blob: 6997e97fc850817a0dd6b6ad34c229b73ee13a41 [file] [log] [blame]
Jerry Chuang8fc85982009-11-03 07:17:11 -02001/******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3 * Linux device driver for RTL8192U
4 *
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.
10 *
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
14 * more details.
15 *
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
19 *
20 * The full GNU General Public License is included in this distribution in the
21 * file called LICENSE.
22 *
23 * Contact Information:
24 * Jerry chuang <wlanfae@realtek.com>
25 */
26
27#ifndef CONFIG_FORCE_HARD_FLOAT
28double __floatsidf (int i) { return i; }
29unsigned int __fixunsdfsi (double d) { return d; }
30double __adddf3(double a, double b) { return a+b; }
31double __addsf3(float a, float b) { return a+b; }
32double __subdf3(double a, double b) { return a-b; }
33double __extendsfdf2(float a) {return a;}
34#endif
35
36#undef LOOP_TEST
37#undef DUMP_RX
38#undef DUMP_TX
39#undef DEBUG_TX_DESC2
40#undef RX_DONT_PASS_UL
41#undef DEBUG_EPROM
42#undef DEBUG_RX_VERBOSE
43#undef DUMMY_RX
44#undef DEBUG_ZERO_RX
45#undef DEBUG_RX_SKB
46#undef DEBUG_TX_FRAG
47#undef DEBUG_RX_FRAG
48#undef DEBUG_TX_FILLDESC
49#undef DEBUG_TX
50#undef DEBUG_IRQ
51#undef DEBUG_RX
52#undef DEBUG_RXALLOC
53#undef DEBUG_REGISTERS
54#undef DEBUG_RING
55#undef DEBUG_IRQ_TASKLET
56#undef DEBUG_TX_ALLOC
57#undef DEBUG_TX_DESC
58
59#define CONFIG_RTL8192_IO_MAP
60
61#include <asm/uaccess.h>
62#include "r8192U_hw.h"
63#include "r8192U.h"
64#include "r8190_rtl8256.h" /* RTL8225 Radio frontend */
65#include "r8180_93cx6.h" /* Card EEPROM */
66#include "r8192U_wx.h"
67#include "r819xU_phy.h" //added by WB 4.30.2008
68#include "r819xU_phyreg.h"
69#include "r819xU_cmdpkt.h"
70#include "r8192U_dm.h"
71//#include "r8192xU_phyreg.h"
72#include <linux/usb.h>
73// FIXME: check if 2.6.7 is ok
74#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,7))
75#define usb_kill_urb usb_unlink_urb
76#endif
77
78#ifdef CONFIG_RTL8192_PM
79#include "r8192_pm.h"
80#endif
81
82#ifdef ENABLE_DOT11D
83#include "dot11d.h"
84#endif
85//set here to open your trace code. //WB
86u32 rt_global_debug_component = \
87 // COMP_INIT |
88// COMP_DBG |
89 // COMP_EPROM |
90// COMP_PHY |
91 // COMP_RF |
92// COMP_FIRMWARE |
93// COMP_CH |
94 // COMP_POWER_TRACKING |
95// COMP_RATE |
96 // COMP_TXAGC |
97 // COMP_TRACE |
98 COMP_DOWN |
99 // COMP_RECV |
100 // COMP_SWBW |
101 COMP_SEC |
102 // COMP_RESET |
103 // COMP_SEND |
104 // COMP_EVENTS |
105 COMP_ERR ; //always open err flags on
106
107#define TOTAL_CAM_ENTRY 32
108#define CAM_CONTENT_COUNT 8
109
110static struct usb_device_id rtl8192_usb_id_tbl[] = {
111 /* Realtek */
112 {USB_DEVICE(0x0bda, 0x8192)},
113 {USB_DEVICE(0x0bda, 0x8709)},
114 /* Corega */
115 {USB_DEVICE(0x07aa, 0x0043)},
116 /* Belkin */
117 {USB_DEVICE(0x050d, 0x805E)},
118 /* Sitecom */
119 {USB_DEVICE(0x0df6, 0x0031)},
120 /* EnGenius */
121 {USB_DEVICE(0x1740, 0x9201)},
122 /* Dlink */
123 {USB_DEVICE(0x2001, 0x3301)},
124 /* Zinwell */
125 {USB_DEVICE(0x5a57, 0x0290)},
126 {}
127};
128
129MODULE_LICENSE("GPL");
130#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
131MODULE_VERSION("V 1.1");
132#endif
133MODULE_DEVICE_TABLE(usb, rtl8192_usb_id_tbl);
134MODULE_DESCRIPTION("Linux driver for Realtek RTL8192 USB WiFi cards");
135
136static char* ifname = "wlan%d";
137#if 0
138static int hwseqnum = 0;
139static int hwwep = 0;
140#endif
141static int hwwep = 1; //default use hw. set 0 to use software security
142static int channels = 0x3fff;
143
144
145
146#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 9)
147module_param(ifname, charp, S_IRUGO|S_IWUSR );
148//module_param(hwseqnum,int, S_IRUGO|S_IWUSR);
149module_param(hwwep,int, S_IRUGO|S_IWUSR);
150module_param(channels,int, S_IRUGO|S_IWUSR);
151#else
152MODULE_PARM(ifname, "s");
153//MODULE_PARM(hwseqnum,"i");
154MODULE_PARM(hwwep,"i");
155MODULE_PARM(channels,"i");
156#endif
157
158MODULE_PARM_DESC(ifname," Net interface name, wlan%d=default");
159//MODULE_PARM_DESC(hwseqnum," Try to use hardware 802.11 header sequence numbers. Zero=default");
160MODULE_PARM_DESC(hwwep," Try to use hardware security support. ");
161MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");
162
163#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
164static int __devinit rtl8192_usb_probe(struct usb_interface *intf,
165 const struct usb_device_id *id);
166static void __devexit rtl8192_usb_disconnect(struct usb_interface *intf);
167#else
168static void *__devinit rtl8192_usb_probe(struct usb_device *udev,unsigned int ifnum,
169 const struct usb_device_id *id);
170static void __devexit rtl8192_usb_disconnect(struct usb_device *udev, void *ptr);
171#endif
172
173
174static struct usb_driver rtl8192_usb_driver = {
175#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 15)
176 .owner = THIS_MODULE,
177#endif
178 .name = RTL819xU_MODULE_NAME, /* Driver name */
179 .id_table = rtl8192_usb_id_tbl, /* PCI_ID table */
180 .probe = rtl8192_usb_probe, /* probe fn */
181 .disconnect = rtl8192_usb_disconnect, /* remove fn */
182#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 5, 0)
183#ifdef CONFIG_RTL8192_PM
184 .suspend = rtl8192_suspend, /* PM suspend fn */
185 .resume = rtl8192_resume, /* PM resume fn */
186#else
187 .suspend = NULL, /* PM suspend fn */
188 .resume = NULL, /* PM resume fn */
189#endif
190#endif
191};
192
193#ifdef ENABLE_DOT11D
194
195typedef struct _CHANNEL_LIST
196{
197 u8 Channel[32];
198 u8 Len;
199}CHANNEL_LIST, *PCHANNEL_LIST;
200
201static CHANNEL_LIST ChannelPlan[] = {
202 {{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
203 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
204 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
205 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI.
206 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI.
207 {{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
208 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1
209 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel.
210 {{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
211 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64}, 22}, //MIC
212 {{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};
214
215static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv)
216{
217 int i, max_chan=-1, min_chan=-1;
218 struct ieee80211_device* ieee = priv->ieee80211;
219 switch (channel_plan)
220 {
221 case COUNTRY_CODE_FCC:
222 case COUNTRY_CODE_IC:
223 case COUNTRY_CODE_ETSI:
224 case COUNTRY_CODE_SPAIN:
225 case COUNTRY_CODE_FRANCE:
226 case COUNTRY_CODE_MKK:
227 case COUNTRY_CODE_MKK1:
228 case COUNTRY_CODE_ISRAEL:
229 case COUNTRY_CODE_TELEC:
230 case COUNTRY_CODE_MIC:
231 {
232 Dot11d_Init(ieee);
233 ieee->bGlobalDomain = false;
234 //acturally 8225 & 8256 rf chip only support B,G,24N mode
235 if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256))
236 {
237 min_chan = 1;
238 max_chan = 14;
239 }
240 else
241 {
242 RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __FUNCTION__);
243 }
244 if (ChannelPlan[channel_plan].Len != 0){
245 // Clear old channel map
246 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
247 // Set new channel map
248 for (i=0;i<ChannelPlan[channel_plan].Len;i++)
249 {
250 if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan)
251 break;
252 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
253 }
254 }
255 break;
256 }
257 case COUNTRY_CODE_GLOBAL_DOMAIN:
258 {
259 GET_DOT11D_INFO(ieee)->bEnabled = 0;//this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain settings.
260 Dot11d_Reset(ieee);
261 ieee->bGlobalDomain = true;
262 break;
263 }
264 default:
265 break;
266 }
267 return;
268}
269#endif
270
271#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 )
272
273#define rx_hal_is_cck_rate(_pdrvinfo)\
274 (_pdrvinfo->RxRate == DESC90_RATE1M ||\
275 _pdrvinfo->RxRate == DESC90_RATE2M ||\
276 _pdrvinfo->RxRate == DESC90_RATE5_5M ||\
277 _pdrvinfo->RxRate == DESC90_RATE11M) &&\
278 !_pdrvinfo->RxHT\
279
280
281void CamResetAllEntry(struct net_device *dev)
282{
283#if 1
284 u32 ulcommand = 0;
285 //2004/02/11 In static WEP, OID_ADD_KEY or OID_ADD_WEP are set before STA associate to AP.
286 // However, ResetKey is called on OID_802_11_INFRASTRUCTURE_MODE and MlmeAssociateRequest
287 // In this condition, Cam can not be reset because upper layer will not set this static key again.
288 //if(Adapter->EncAlgorithm == WEP_Encryption)
289 // return;
290//debug
291 //DbgPrint("========================================\n");
292 //DbgPrint(" Call ResetAllEntry \n");
293 //DbgPrint("========================================\n\n");
294 ulcommand |= BIT31|BIT30;
295 write_nic_dword(dev, RWCAM, ulcommand);
296#else
297 for(ucIndex=0;ucIndex<TOTAL_CAM_ENTRY;ucIndex++)
298 CAM_mark_invalid(dev, ucIndex);
299 for(ucIndex=0;ucIndex<TOTAL_CAM_ENTRY;ucIndex++)
300 CAM_empty_entry(dev, ucIndex);
301#endif
302
303}
304
305
306void write_cam(struct net_device *dev, u8 addr, u32 data)
307{
308 write_nic_dword(dev, WCAMI, data);
309 write_nic_dword(dev, RWCAM, BIT31|BIT16|(addr&0xff) );
310}
311
312u32 read_cam(struct net_device *dev, u8 addr)
313{
314 write_nic_dword(dev, RWCAM, 0x80000000|(addr&0xff) );
315 return read_nic_dword(dev, 0xa8);
316}
317
318void write_nic_byte_E(struct net_device *dev, int indx, u8 data)
319{
320 int status;
321 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
322 struct usb_device *udev = priv->udev;
323
324 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
325 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
326 indx|0xfe00, 0, &data, 1, HZ / 2);
327
328 if (status < 0)
329 {
330 printk("write_nic_byte_E TimeOut! status:%d\n", status);
331 }
332}
333
334u8 read_nic_byte_E(struct net_device *dev, int indx)
335{
336 int status;
337 u8 data;
338 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
339 struct usb_device *udev = priv->udev;
340
341 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
342 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
343 indx|0xfe00, 0, &data, 1, HZ / 2);
344
345 if (status < 0)
346 {
347 printk("read_nic_byte_E TimeOut! status:%d\n", status);
348 }
349
350 return data;
351}
352//as 92U has extend page from 4 to 16, so modify functions below.
353void write_nic_byte(struct net_device *dev, int indx, u8 data)
354{
355 int status;
356
357 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
358 struct usb_device *udev = priv->udev;
359
360 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
361 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
362 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 1, HZ / 2);
363
364 if (status < 0)
365 {
366 printk("write_nic_byte TimeOut! status:%d\n", status);
367 }
368
369
370}
371
372
373void write_nic_word(struct net_device *dev, int indx, u16 data)
374{
375
376 int status;
377
378 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
379 struct usb_device *udev = priv->udev;
380
381 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
382 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
383 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 2, HZ / 2);
384
385 if (status < 0)
386 {
387 printk("write_nic_word TimeOut! status:%d\n", status);
388 }
389
390}
391
392
393void write_nic_dword(struct net_device *dev, int indx, u32 data)
394{
395
396 int status;
397
398 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
399 struct usb_device *udev = priv->udev;
400
401 status = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
402 RTL8187_REQ_SET_REGS, RTL8187_REQT_WRITE,
403 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 4, HZ / 2);
404
405
406 if (status < 0)
407 {
408 printk("write_nic_dword TimeOut! status:%d\n", status);
409 }
410
411}
412
413
414
415u8 read_nic_byte(struct net_device *dev, int indx)
416{
417 u8 data;
418 int status;
419 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
420 struct usb_device *udev = priv->udev;
421
422 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
423 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
424 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 1, HZ / 2);
425
426 if (status < 0)
427 {
428 printk("read_nic_byte TimeOut! status:%d\n", status);
429 }
430
431 return data;
432}
433
434
435
436u16 read_nic_word(struct net_device *dev, int indx)
437{
438 u16 data;
439 int status;
440 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
441 struct usb_device *udev = priv->udev;
442
443 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
444 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
445 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 2, HZ / 2);
446
447 if (status < 0)
448 {
449 printk("read_nic_word TimeOut! status:%d\n", status);
450 }
451
452
453 return data;
454}
455
456u16 read_nic_word_E(struct net_device *dev, int indx)
457{
458 u16 data;
459 int status;
460 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
461 struct usb_device *udev = priv->udev;
462
463 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
464 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
465 indx|0xfe00, 0, &data, 2, HZ / 2);
466
467 if (status < 0)
468 {
469 printk("read_nic_word TimeOut! status:%d\n", status);
470 }
471
472
473 return data;
474}
475
476u32 read_nic_dword(struct net_device *dev, int indx)
477{
478 u32 data;
479 int status;
480// int result;
481
482 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
483 struct usb_device *udev = priv->udev;
484
485 status = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
486 RTL8187_REQ_GET_REGS, RTL8187_REQT_READ,
487 (indx&0xff)|0xff00, (indx>>8)&0x0f, &data, 4, HZ / 2);
488// if(0 != result) {
489// printk(KERN_WARNING "read size of data = %d\, date = %d\n", result, data);
490// }
491
492 if (status < 0)
493 {
494 printk("read_nic_dword TimeOut! status:%d\n", status);
495 }
496
497
498
499 return data;
500}
501
502
503//u8 read_phy_cck(struct net_device *dev, u8 adr);
504//u8 read_phy_ofdm(struct net_device *dev, u8 adr);
505/* this might still called in what was the PHY rtl8185/rtl8192 common code
506 * plans are to possibilty turn it again in one common code...
507 */
508inline void force_pci_posting(struct net_device *dev)
509{
510}
511
512
513static struct net_device_stats *rtl8192_stats(struct net_device *dev);
514void rtl8192_commit(struct net_device *dev);
515//void rtl8192_restart(struct net_device *dev);
516#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
517void rtl8192_restart(struct work_struct *work);
518//void rtl8192_rq_tx_ack(struct work_struct *work);
519#else
520 void rtl8192_restart(struct net_device *dev);
521// //void rtl8192_rq_tx_ack(struct net_device *dev);
522 #endif
523
524void watch_dog_timer_callback(unsigned long data);
525
526/****************************************************************************
527 -----------------------------PROCFS STUFF-------------------------
528*****************************************************************************/
529
530static struct proc_dir_entry *rtl8192_proc = NULL;
531
532
533
534static int proc_get_stats_ap(char *page, char **start,
535 off_t offset, int count,
536 int *eof, void *data)
537{
538 struct net_device *dev = data;
539 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
540 struct ieee80211_device *ieee = priv->ieee80211;
541 struct ieee80211_network *target;
542
543 int len = 0;
544
545 list_for_each_entry(target, &ieee->network_list, list) {
546
547 len += snprintf(page + len, count - len,
548 "%s ", target->ssid);
549
550 if(target->wpa_ie_len>0 || target->rsn_ie_len>0){
551 len += snprintf(page + len, count - len,
552 "WPA\n");
553 }
554 else{
555 len += snprintf(page + len, count - len,
556 "non_WPA\n");
557 }
558
559 }
560
561 *eof = 1;
562 return len;
563}
564
565static int proc_get_registers(char *page, char **start,
566 off_t offset, int count,
567 int *eof, void *data)
568{
569 struct net_device *dev = data;
570// struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
571
572 int len = 0;
573 int i,n;
574
575 int max=0xff;
576
577 /* This dump the current register page */
578len += snprintf(page + len, count - len,
579 "\n####################page 0##################\n ");
580
581 for(n=0;n<=max;)
582 {
583 //printk( "\nD: %2x> ", n);
584 len += snprintf(page + len, count - len,
585 "\nD: %2x > ",n);
586
587 for(i=0;i<16 && n<=max;i++,n++)
588 len += snprintf(page + len, count - len,
589 "%2x ",read_nic_byte(dev,0x000|n));
590
591 // printk("%2x ",read_nic_byte(dev,n));
592 }
593#if 1
594len += snprintf(page + len, count - len,
595 "\n####################page 1##################\n ");
596 for(n=0;n<=max;)
597 {
598 //printk( "\nD: %2x> ", n);
599 len += snprintf(page + len, count - len,
600 "\nD: %2x > ",n);
601
602 for(i=0;i<16 && n<=max;i++,n++)
603 len += snprintf(page + len, count - len,
604 "%2x ",read_nic_byte(dev,0x100|n));
605
606 // printk("%2x ",read_nic_byte(dev,n));
607 }
608len += snprintf(page + len, count - len,
609 "\n####################page 3##################\n ");
610 for(n=0;n<=max;)
611 {
612 //printk( "\nD: %2x> ", n);
613 len += snprintf(page + len, count - len,
614 "\nD: %2x > ",n);
615
616 for(i=0;i<16 && n<=max;i++,n++)
617 len += snprintf(page + len, count - len,
618 "%2x ",read_nic_byte(dev,0x300|n));
619
620 // printk("%2x ",read_nic_byte(dev,n));
621 }
622
623#endif
624
625 len += snprintf(page + len, count - len,"\n");
626 *eof = 1;
627 return len;
628
629}
630
631
632#if 0
633static int proc_get_cck_reg(char *page, char **start,
634 off_t offset, int count,
635 int *eof, void *data)
636{
637 struct net_device *dev = data;
638// struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
639
640 int len = 0;
641 int i,n;
642
643 int max = 0x5F;
644
645 /* This dump the current register page */
646 for(n=0;n<=max;)
647 {
648 //printk( "\nD: %2x> ", n);
649 len += snprintf(page + len, count - len,
650 "\nD: %2x > ",n);
651
652 for(i=0;i<16 && n<=max;i++,n++)
653 len += snprintf(page + len, count - len,
654 "%2x ",read_phy_cck(dev,n));
655
656 // printk("%2x ",read_nic_byte(dev,n));
657 }
658 len += snprintf(page + len, count - len,"\n");
659
660
661 *eof = 1;
662 return len;
663}
664
665#endif
666
667#if 0
668static int proc_get_ofdm_reg(char *page, char **start,
669 off_t offset, int count,
670 int *eof, void *data)
671{
672 struct net_device *dev = data;
673// struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
674
675 int len = 0;
676 int i,n;
677
678 //int max=0xff;
679 int max = 0x40;
680
681 /* This dump the current register page */
682 for(n=0;n<=max;)
683 {
684 //printk( "\nD: %2x> ", n);
685 len += snprintf(page + len, count - len,
686 "\nD: %2x > ",n);
687
688 for(i=0;i<16 && n<=max;i++,n++)
689 len += snprintf(page + len, count - len,
690 "%2x ",read_phy_ofdm(dev,n));
691
692 // printk("%2x ",read_nic_byte(dev,n));
693 }
694 len += snprintf(page + len, count - len,"\n");
695
696
697
698 *eof = 1;
699 return len;
700}
701
702#endif
703
704#if 0
705static int proc_get_stats_hw(char *page, char **start,
706 off_t offset, int count,
707 int *eof, void *data)
708{
709 struct net_device *dev = data;
710 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
711
712 int len = 0;
713
714 len += snprintf(page + len, count - len,
715 "NIC int: %lu\n"
716 "Total int: %lu\n",
717 priv->stats.ints,
718 priv->stats.shints);
719
720 *eof = 1;
721 return len;
722}
723#endif
724
725static int proc_get_stats_tx(char *page, char **start,
726 off_t offset, int count,
727 int *eof, void *data)
728{
729 struct net_device *dev = data;
730 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
731
732 int len = 0;
733
734 len += snprintf(page + len, count - len,
735 "TX VI priority ok int: %lu\n"
736 "TX VI priority error int: %lu\n"
737 "TX VO priority ok int: %lu\n"
738 "TX VO priority error int: %lu\n"
739 "TX BE priority ok int: %lu\n"
740 "TX BE priority error int: %lu\n"
741 "TX BK priority ok int: %lu\n"
742 "TX BK priority error int: %lu\n"
743 "TX MANAGE priority ok int: %lu\n"
744 "TX MANAGE priority error int: %lu\n"
745 "TX BEACON priority ok int: %lu\n"
746 "TX BEACON priority error int: %lu\n"
747// "TX high priority ok int: %lu\n"
748// "TX high priority failed error int: %lu\n"
749 "TX queue resume: %lu\n"
750 "TX queue stopped?: %d\n"
751 "TX fifo overflow: %lu\n"
752// "TX beacon: %lu\n"
753 "TX VI queue: %d\n"
754 "TX VO queue: %d\n"
755 "TX BE queue: %d\n"
756 "TX BK queue: %d\n"
757// "TX HW queue: %d\n"
758 "TX VI dropped: %lu\n"
759 "TX VO dropped: %lu\n"
760 "TX BE dropped: %lu\n"
761 "TX BK dropped: %lu\n"
762 "TX total data packets %lu\n",
763// "TX beacon aborted: %lu\n",
764 priv->stats.txviokint,
765 priv->stats.txvierr,
766 priv->stats.txvookint,
767 priv->stats.txvoerr,
768 priv->stats.txbeokint,
769 priv->stats.txbeerr,
770 priv->stats.txbkokint,
771 priv->stats.txbkerr,
772 priv->stats.txmanageokint,
773 priv->stats.txmanageerr,
774 priv->stats.txbeaconokint,
775 priv->stats.txbeaconerr,
776// priv->stats.txhpokint,
777// priv->stats.txhperr,
778 priv->stats.txresumed,
779 netif_queue_stopped(dev),
780 priv->stats.txoverflow,
781// priv->stats.txbeacon,
782 atomic_read(&(priv->tx_pending[VI_PRIORITY])),
783 atomic_read(&(priv->tx_pending[VO_PRIORITY])),
784 atomic_read(&(priv->tx_pending[BE_PRIORITY])),
785 atomic_read(&(priv->tx_pending[BK_PRIORITY])),
786// read_nic_byte(dev, TXFIFOCOUNT),
787 priv->stats.txvidrop,
788 priv->stats.txvodrop,
789 priv->stats.txbedrop,
790 priv->stats.txbkdrop,
791 priv->stats.txdatapkt
792// priv->stats.txbeaconerr
793 );
794
795 *eof = 1;
796 return len;
797}
798
799
800
801static int proc_get_stats_rx(char *page, char **start,
802 off_t offset, int count,
803 int *eof, void *data)
804{
805 struct net_device *dev = data;
806 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
807
808 int len = 0;
809
810 len += snprintf(page + len, count - len,
811 "RX packets: %lu\n"
812 "RX urb status error: %lu\n"
813 "RX invalid urb error: %lu\n",
814 priv->stats.rxoktotal,
815 priv->stats.rxstaterr,
816 priv->stats.rxurberr);
817
818 *eof = 1;
819 return len;
820}
821#if 0
822#if WIRELESS_EXT >= 12 && WIRELESS_EXT < 17
823
824static struct iw_statistics *r8192_get_wireless_stats(struct net_device *dev)
825{
826 struct r8192_priv *priv = ieee80211_priv(dev);
827
828 return &priv->wstats;
829}
830#endif
831#endif
832void rtl8192_proc_module_init(void)
833{
834 RT_TRACE(COMP_INIT, "Initializing proc filesystem");
835#if(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
836 rtl8192_proc=create_proc_entry(RTL819xU_MODULE_NAME, S_IFDIR, proc_net);
837#else
838 rtl8192_proc=create_proc_entry(RTL819xU_MODULE_NAME, S_IFDIR, init_net.proc_net);
839#endif
840}
841
842
843void rtl8192_proc_module_remove(void)
844{
845#if(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24))
846 remove_proc_entry(RTL819xU_MODULE_NAME, proc_net);
847#else
848 remove_proc_entry(RTL819xU_MODULE_NAME, init_net.proc_net);
849#endif
850}
851
852
853void rtl8192_proc_remove_one(struct net_device *dev)
854{
855 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
856
857
858 if (priv->dir_dev) {
859 // remove_proc_entry("stats-hw", priv->dir_dev);
860 remove_proc_entry("stats-tx", priv->dir_dev);
861 remove_proc_entry("stats-rx", priv->dir_dev);
862 // remove_proc_entry("stats-ieee", priv->dir_dev);
863 remove_proc_entry("stats-ap", priv->dir_dev);
864 remove_proc_entry("registers", priv->dir_dev);
865 // remove_proc_entry("cck-registers",priv->dir_dev);
866 // remove_proc_entry("ofdm-registers",priv->dir_dev);
867 //remove_proc_entry(dev->name, rtl8192_proc);
868 remove_proc_entry("wlan0", rtl8192_proc);
869 priv->dir_dev = NULL;
870 }
871}
872
873
874void rtl8192_proc_init_one(struct net_device *dev)
875{
876 struct proc_dir_entry *e;
877 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
878 priv->dir_dev = create_proc_entry(dev->name,
879 S_IFDIR | S_IRUGO | S_IXUGO,
880 rtl8192_proc);
881 if (!priv->dir_dev) {
882 RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n",
883 dev->name);
884 return;
885 }
886 #if 0
887 e = create_proc_read_entry("stats-hw", S_IFREG | S_IRUGO,
888 priv->dir_dev, proc_get_stats_hw, dev);
889
890 if (!e) {
891 DMESGE("Unable to initialize "
892 "/proc/net/rtl8192/%s/stats-hw\n",
893 dev->name);
894 }
895 #endif
896 e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
897 priv->dir_dev, proc_get_stats_rx, dev);
898
899 if (!e) {
900 RT_TRACE(COMP_ERR,"Unable to initialize "
901 "/proc/net/rtl8192/%s/stats-rx\n",
902 dev->name);
903 }
904
905
906 e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
907 priv->dir_dev, proc_get_stats_tx, dev);
908
909 if (!e) {
910 RT_TRACE(COMP_ERR, "Unable to initialize "
911 "/proc/net/rtl8192/%s/stats-tx\n",
912 dev->name);
913 }
914 #if 0
915 e = create_proc_read_entry("stats-ieee", S_IFREG | S_IRUGO,
916 priv->dir_dev, proc_get_stats_ieee, dev);
917
918 if (!e) {
919 DMESGE("Unable to initialize "
920 "/proc/net/rtl8192/%s/stats-ieee\n",
921 dev->name);
922 }
923
924 #endif
925
926 e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO,
927 priv->dir_dev, proc_get_stats_ap, dev);
928
929 if (!e) {
930 RT_TRACE(COMP_ERR, "Unable to initialize "
931 "/proc/net/rtl8192/%s/stats-ap\n",
932 dev->name);
933 }
934
935 e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
936 priv->dir_dev, proc_get_registers, dev);
937 if (!e) {
938 RT_TRACE(COMP_ERR, "Unable to initialize "
939 "/proc/net/rtl8192/%s/registers\n",
940 dev->name);
941 }
942#if 0
943 e = create_proc_read_entry("cck-registers", S_IFREG | S_IRUGO,
944 priv->dir_dev, proc_get_cck_reg, dev);
945 if (!e) {
946 RT_TRACE(COMP_ERR, "Unable to initialize "
947 "/proc/net/rtl8192/%s/cck-registers\n",
948 dev->name);
949 }
950
951 e = create_proc_read_entry("ofdm-registers", S_IFREG | S_IRUGO,
952 priv->dir_dev, proc_get_ofdm_reg, dev);
953 if (!e) {
954 RT_TRACE(COMP_ERR, "Unable to initialize "
955 "/proc/net/rtl8192/%s/ofdm-registers\n",
956 dev->name);
957 }
958#endif
959}
960/****************************************************************************
961 -----------------------------MISC STUFF-------------------------
962*****************************************************************************/
963
964/* this is only for debugging */
965void print_buffer(u32 *buffer, int len)
966{
967 int i;
968 u8 *buf =(u8*)buffer;
969
970 printk("ASCII BUFFER DUMP (len: %x):\n",len);
971
972 for(i=0;i<len;i++)
973 printk("%c",buf[i]);
974
975 printk("\nBINARY BUFFER DUMP (len: %x):\n",len);
976
977 for(i=0;i<len;i++)
978 printk("%x",buf[i]);
979
980 printk("\n");
981}
982
983//short check_nic_enough_desc(struct net_device *dev, priority_t priority)
984short check_nic_enough_desc(struct net_device *dev,int queue_index)
985{
986 struct r8192_priv *priv = ieee80211_priv(dev);
987 int used = atomic_read(&priv->tx_pending[queue_index]);
988
989 return (used < MAX_TX_URB);
990}
991
992void tx_timeout(struct net_device *dev)
993{
994 struct r8192_priv *priv = ieee80211_priv(dev);
995 //rtl8192_commit(dev);
996
997#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
998 schedule_work(&priv->reset_wq);
999#else
1000 schedule_task(&priv->reset_wq);
1001#endif
1002 //DMESG("TXTIMEOUT");
1003}
1004
1005
1006/* this is only for debug */
1007void dump_eprom(struct net_device *dev)
1008{
1009 int i;
1010 for(i=0; i<63; i++)
1011 RT_TRACE(COMP_EPROM, "EEPROM addr %x : %x", i, eprom_read(dev,i));
1012}
1013
1014/* this is only for debug */
1015void rtl8192_dump_reg(struct net_device *dev)
1016{
1017 int i;
1018 int n;
1019 int max=0x1ff;
1020
1021 RT_TRACE(COMP_PHY, "Dumping NIC register map");
1022
1023 for(n=0;n<=max;)
1024 {
1025 printk( "\nD: %2x> ", n);
1026 for(i=0;i<16 && n<=max;i++,n++)
1027 printk("%2x ",read_nic_byte(dev,n));
1028 }
1029 printk("\n");
1030}
1031
1032/****************************************************************************
1033 ------------------------------HW STUFF---------------------------
1034*****************************************************************************/
1035
1036#if 0
1037void rtl8192_irq_enable(struct net_device *dev)
1038{
1039 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1040 //priv->irq_enabled = 1;
1041/*
1042 write_nic_word(dev,INTA_MASK,INTA_RXOK | INTA_RXDESCERR | INTA_RXOVERFLOW |\
1043 INTA_TXOVERFLOW | INTA_HIPRIORITYDESCERR | INTA_HIPRIORITYDESCOK |\
1044 INTA_NORMPRIORITYDESCERR | INTA_NORMPRIORITYDESCOK |\
1045 INTA_LOWPRIORITYDESCERR | INTA_LOWPRIORITYDESCOK | INTA_TIMEOUT);
1046*/
1047 write_nic_word(dev,INTA_MASK, priv->irq_mask);
1048}
1049
1050
1051void rtl8192_irq_disable(struct net_device *dev)
1052{
1053// struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1054
1055 write_nic_word(dev,INTA_MASK,0);
1056 force_pci_posting(dev);
1057// priv->irq_enabled = 0;
1058}
1059#endif
1060
1061void rtl8192_set_mode(struct net_device *dev,int mode)
1062{
1063 u8 ecmd;
1064 ecmd=read_nic_byte(dev, EPROM_CMD);
1065 ecmd=ecmd &~ EPROM_CMD_OPERATING_MODE_MASK;
1066 ecmd=ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
1067 ecmd=ecmd &~ (1<<EPROM_CS_SHIFT);
1068 ecmd=ecmd &~ (1<<EPROM_CK_SHIFT);
1069 write_nic_byte(dev, EPROM_CMD, ecmd);
1070}
1071
1072
1073void rtl8192_update_msr(struct net_device *dev)
1074{
1075 struct r8192_priv *priv = ieee80211_priv(dev);
1076 u8 msr;
1077
1078 msr = read_nic_byte(dev, MSR);
1079 msr &= ~ MSR_LINK_MASK;
1080
1081 /* do not change in link_state != WLAN_LINK_ASSOCIATED.
1082 * msr must be updated if the state is ASSOCIATING.
1083 * this is intentional and make sense for ad-hoc and
1084 * master (see the create BSS/IBSS func)
1085 */
1086 if (priv->ieee80211->state == IEEE80211_LINKED){
1087
1088 if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
1089 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
1090 else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1091 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
1092 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
1093 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
1094
1095 }else
1096 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
1097
1098 write_nic_byte(dev, MSR, msr);
1099}
1100
1101void rtl8192_set_chan(struct net_device *dev,short ch)
1102{
1103 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1104// u32 tx;
1105 RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __FUNCTION__, ch);
1106 priv->chan=ch;
1107 #if 0
1108 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC ||
1109 priv->ieee80211->iw_mode == IW_MODE_MASTER){
1110
1111 priv->ieee80211->link_state = WLAN_LINK_ASSOCIATED;
1112 priv->ieee80211->master_chan = ch;
1113 rtl8192_update_beacon_ch(dev);
1114 }
1115 #endif
1116
1117 /* this hack should avoid frame TX during channel setting*/
1118
1119
1120// tx = read_nic_dword(dev,TX_CONF);
1121// tx &= ~TX_LOOPBACK_MASK;
1122
1123#ifndef LOOP_TEST
1124// write_nic_dword(dev,TX_CONF, tx |( TX_LOOPBACK_MAC<<TX_LOOPBACK_SHIFT));
1125
1126 //need to implement rf set channel here WB
1127
1128 if (priv->rf_set_chan)
1129 priv->rf_set_chan(dev,priv->chan);
1130 mdelay(10);
1131// write_nic_dword(dev,TX_CONF,tx | (TX_LOOPBACK_NONE<<TX_LOOPBACK_SHIFT));
1132#endif
1133}
1134
1135#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
1136static void rtl8192_rx_isr(struct urb *urb, struct pt_regs *regs);
1137#else
1138static void rtl8192_rx_isr(struct urb *urb);
1139#endif
1140//static void rtl8192_rx_isr(struct urb *rx_urb);
1141
1142u32 get_rxpacket_shiftbytes_819xusb(struct ieee80211_rx_stats *pstats)
1143{
1144
1145#ifdef USB_RX_AGGREGATION_SUPPORT
1146 if (pstats->bisrxaggrsubframe)
1147 return (sizeof(rx_desc_819x_usb) + pstats->RxDrvInfoSize
1148 + pstats->RxBufShift + 8);
1149 else
1150#endif
1151 return (sizeof(rx_desc_819x_usb) + pstats->RxDrvInfoSize
1152 + pstats->RxBufShift);
1153
1154}
1155static int rtl8192_rx_initiate(struct net_device*dev)
1156{
1157 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1158 struct urb *entry;
1159 struct sk_buff *skb;
1160 struct rtl8192_rx_info *info;
1161
1162 /* nomal packet rx procedure */
1163 while (skb_queue_len(&priv->rx_queue) < MAX_RX_URB) {
1164 skb = __dev_alloc_skb(RX_URB_SIZE, GFP_KERNEL);
1165 if (!skb)
1166 break;
1167#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
1168 entry = usb_alloc_urb(0, GFP_KERNEL);
1169#else
1170 entry = usb_alloc_urb(0);
1171#endif
1172 if (!entry) {
1173 kfree_skb(skb);
1174 break;
1175 }
1176// printk("nomal packet IN request!\n");
1177 usb_fill_bulk_urb(entry, priv->udev,
1178 usb_rcvbulkpipe(priv->udev, 3), skb->tail,
1179 RX_URB_SIZE, rtl8192_rx_isr, skb);
1180 info = (struct rtl8192_rx_info *) skb->cb;
1181 info->urb = entry;
1182 info->dev = dev;
1183 info->out_pipe = 3; //denote rx normal packet queue
1184 skb_queue_tail(&priv->rx_queue, skb);
1185#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
1186 usb_submit_urb(entry, GFP_KERNEL);
1187#else
1188 usb_submit_urb(entry);
1189#endif
1190 }
1191
1192 /* command packet rx procedure */
1193 while (skb_queue_len(&priv->rx_queue) < MAX_RX_URB + 3) {
1194// printk("command packet IN request!\n");
1195 skb = __dev_alloc_skb(RX_URB_SIZE ,GFP_KERNEL);
1196 if (!skb)
1197 break;
1198#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
1199 entry = usb_alloc_urb(0, GFP_KERNEL);
1200#else
1201 entry = usb_alloc_urb(0);
1202#endif
1203 if (!entry) {
1204 kfree_skb(skb);
1205 break;
1206 }
1207 usb_fill_bulk_urb(entry, priv->udev,
1208 usb_rcvbulkpipe(priv->udev, 9), skb->tail,
1209 RX_URB_SIZE, rtl8192_rx_isr, skb);
1210 info = (struct rtl8192_rx_info *) skb->cb;
1211 info->urb = entry;
1212 info->dev = dev;
1213 info->out_pipe = 9; //denote rx cmd packet queue
1214 skb_queue_tail(&priv->rx_queue, skb);
1215#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
1216 usb_submit_urb(entry, GFP_KERNEL);
1217#else
1218 usb_submit_urb(entry);
1219#endif
1220 }
1221
1222 return 0;
1223}
1224
1225void rtl8192_set_rxconf(struct net_device *dev)
1226{
1227 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1228 u32 rxconf;
1229
1230 rxconf=read_nic_dword(dev,RCR);
1231 rxconf = rxconf &~ MAC_FILTER_MASK;
1232 rxconf = rxconf | RCR_AMF;
1233 rxconf = rxconf | RCR_ADF;
1234 rxconf = rxconf | RCR_AB;
1235 rxconf = rxconf | RCR_AM;
1236 //rxconf = rxconf | RCR_ACF;
1237
1238 if (dev->flags & IFF_PROMISC) {DMESG ("NIC in promisc mode");}
1239
1240 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
1241 dev->flags & IFF_PROMISC){
1242 rxconf = rxconf | RCR_AAP;
1243 } /*else if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
1244 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
1245 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
1246 }*/else{
1247 rxconf = rxconf | RCR_APM;
1248 rxconf = rxconf | RCR_CBSSID;
1249 }
1250
1251
1252 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
1253 rxconf = rxconf | RCR_AICV;
1254 rxconf = rxconf | RCR_APWRMGT;
1255 }
1256
1257 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
1258 rxconf = rxconf | RCR_ACRC32;
1259
1260
1261 rxconf = rxconf &~ RX_FIFO_THRESHOLD_MASK;
1262 rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
1263 rxconf = rxconf &~ MAX_RX_DMA_MASK;
1264 rxconf = rxconf | ((u32)7<<RCR_MXDMA_OFFSET);
1265
1266// rxconf = rxconf | (1<<RX_AUTORESETPHY_SHIFT);
1267 rxconf = rxconf | RCR_ONLYERLPKT;
1268
1269// rxconf = rxconf &~ RCR_CS_MASK;
1270// rxconf = rxconf | (1<<RCR_CS_SHIFT);
1271
1272 write_nic_dword(dev, RCR, rxconf);
1273
1274 #ifdef DEBUG_RX
1275 DMESG("rxconf: %x %x",rxconf ,read_nic_dword(dev,RCR));
1276 #endif
1277}
1278//wait to be removed
1279void rtl8192_rx_enable(struct net_device *dev)
1280{
1281 //u8 cmd;
1282
1283 //struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1284
1285 rtl8192_rx_initiate(dev);
1286
1287// rtl8192_set_rxconf(dev);
1288#if 0
1289 if(NIC_8187 == priv->card_8187) {
1290 cmd=read_nic_byte(dev,CMD);
1291 write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
1292 }
1293 else {
1294 //write_nic_dword(dev, RX_CONF, priv->ReceiveConfig);
1295 }
1296#endif
1297}
1298
1299
1300void rtl8192_tx_enable(struct net_device *dev)
1301{
1302#if 0
1303 u8 cmd;
1304 u8 byte;
1305 u32 txconf;
1306 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1307 //test loopback
1308 // priv->TransmitConfig |= (TX_LOOPBACK_BASEBAND<<TX_LOOPBACK_SHIFT);
1309 if(NIC_8187B == priv->card_8187){
1310 write_nic_dword(dev, TX_CONF, priv->TransmitConfig);
1311 byte = read_nic_byte(dev, MSR);
1312 byte |= MSR_LINK_ENEDCA;
1313 write_nic_byte(dev, MSR, byte);
1314 } else {
1315 byte = read_nic_byte(dev,CW_CONF);
1316 byte &= ~(1<<CW_CONF_PERPACKET_CW_SHIFT);
1317 byte &= ~(1<<CW_CONF_PERPACKET_RETRY_SHIFT);
1318 write_nic_byte(dev, CW_CONF, byte);
1319
1320 byte = read_nic_byte(dev, TX_AGC_CTL);
1321 byte &= ~(1<<TX_AGC_CTL_PERPACKET_GAIN_SHIFT);
1322 byte &= ~(1<<TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT);
1323 byte &= ~(1<<TX_AGC_CTL_FEEDBACK_ANT);
1324 write_nic_byte(dev, TX_AGC_CTL, byte);
1325
1326 txconf= read_nic_dword(dev,TX_CONF);
1327
1328
1329 txconf = txconf &~ TX_LOOPBACK_MASK;
1330
1331#ifndef LOOP_TEST
1332 txconf = txconf | (TX_LOOPBACK_NONE<<TX_LOOPBACK_SHIFT);
1333#else
1334 txconf = txconf | (TX_LOOPBACK_BASEBAND<<TX_LOOPBACK_SHIFT);
1335#endif
1336 txconf = txconf &~ TCR_SRL_MASK;
1337 txconf = txconf &~ TCR_LRL_MASK;
1338
1339 txconf = txconf | (priv->retry_data<<TX_LRLRETRY_SHIFT); // long
1340 txconf = txconf | (priv->retry_rts<<TX_SRLRETRY_SHIFT); // short
1341
1342 txconf = txconf &~ (1<<TX_NOCRC_SHIFT);
1343
1344 txconf = txconf &~ TCR_MXDMA_MASK;
1345 txconf = txconf | (TCR_MXDMA_2048<<TCR_MXDMA_SHIFT);
1346
1347 txconf = txconf | TCR_DISReqQsize;
1348 txconf = txconf | TCR_DISCW;
1349 txconf = txconf &~ TCR_SWPLCPLEN;
1350
1351 txconf=txconf | (1<<TX_NOICV_SHIFT);
1352
1353 write_nic_dword(dev,TX_CONF,txconf);
1354
1355#ifdef DEBUG_TX
1356 DMESG("txconf: %x %x",txconf,read_nic_dword(dev,TX_CONF));
1357#endif
1358
1359 cmd=read_nic_byte(dev,CMD);
1360 write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));
1361 }
1362#endif
1363}
1364
1365#if 0
1366void rtl8192_beacon_tx_enable(struct net_device *dev)
1367{
1368 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1369 priv->dma_poll_mask &=~(1<<TX_DMA_STOP_BEACON_SHIFT);
1370 rtl8192_set_mode(dev,EPROM_CMD_CONFIG);
1371 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1372 rtl8192_set_mode(dev,EPROM_CMD_NORMAL);
1373}
1374
1375
1376void rtl8192_
1377_disable(struct net_device *dev)
1378{
1379 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1380 priv->dma_poll_mask |= (1<<TX_DMA_STOP_BEACON_SHIFT);
1381 rtl8192_set_mode(dev,EPROM_CMD_CONFIG);
1382 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1383 rtl8192_set_mode(dev,EPROM_CMD_NORMAL);
1384}
1385
1386#endif
1387
1388
1389void rtl8192_rtx_disable(struct net_device *dev)
1390{
1391 u8 cmd;
1392 struct r8192_priv *priv = ieee80211_priv(dev);
1393 struct sk_buff *skb;
1394 struct rtl8192_rx_info *info;
1395
1396 cmd=read_nic_byte(dev,CMDR);
1397 write_nic_byte(dev, CMDR, cmd &~ \
1398 (CR_TE|CR_RE));
1399 force_pci_posting(dev);
1400 mdelay(10);
1401
1402 while ((skb = __skb_dequeue(&priv->rx_queue))) {
1403 info = (struct rtl8192_rx_info *) skb->cb;
1404 if (!info->urb)
1405 continue;
1406
1407 usb_kill_urb(info->urb);
1408 kfree_skb(skb);
1409 }
1410
1411 if (skb_queue_len(&priv->skb_queue)) {
1412 printk(KERN_WARNING "skb_queue not empty\n");
1413 }
1414
1415 skb_queue_purge(&priv->skb_queue);
1416 return;
1417}
1418
1419
1420int alloc_tx_beacon_desc_ring(struct net_device *dev, int count)
1421{
1422 #if 0
1423 int i;
1424 u32 *tmp;
1425 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1426
1427 priv->txbeaconring = (u32*)pci_alloc_consistent(priv->pdev,
1428 sizeof(u32)*8*count,
1429 &priv->txbeaconringdma);
1430 if (!priv->txbeaconring) return -1;
1431 for (tmp=priv->txbeaconring,i=0;i<count;i++){
1432 *tmp = *tmp &~ (1<<31); // descriptor empty, owned by the drv
1433 /*
1434 *(tmp+2) = (u32)dma_tmp;
1435 *(tmp+3) = bufsize;
1436 */
1437 if(i+1<count)
1438 *(tmp+4) = (u32)priv->txbeaconringdma+((i+1)*8*4);
1439 else
1440 *(tmp+4) = (u32)priv->txbeaconringdma;
1441
1442 tmp=tmp+8;
1443 }
1444 #endif
1445 return 0;
1446}
1447
1448#if 0
1449void rtl8192_reset(struct net_device *dev)
1450{
1451
1452 //struct r8192_priv *priv = ieee80211_priv(dev);
1453 //u8 cr;
1454
1455
1456 /* make sure the analog power is on before
1457 * reset, otherwise reset may fail
1458 */
1459#if 0
1460 if(NIC_8187 == priv->card_8187) {
1461 rtl8192_set_anaparam(dev, RTL8225_ANAPARAM_ON);
1462 rtl8185_set_anaparam2(dev, RTL8225_ANAPARAM2_ON);
1463 rtl8192_irq_disable(dev);
1464 mdelay(200);
1465 write_nic_byte_E(dev,0x18,0x10);
1466 write_nic_byte_E(dev,0x18,0x11);
1467 write_nic_byte_E(dev,0x18,0x00);
1468 mdelay(200);
1469 }
1470#endif
1471 printk("=====>reset?\n");
1472#if 0
1473 cr=read_nic_byte(dev,CMD);
1474 cr = cr & 2;
1475 cr = cr | (1<<CMD_RST_SHIFT);
1476 write_nic_byte(dev,CMD,cr);
1477
1478 force_pci_posting(dev);
1479
1480 mdelay(200);
1481
1482 if(read_nic_byte(dev,CMD) & (1<<CMD_RST_SHIFT))
1483 RT_TRACE(COMP_ERR, "Card reset timeout!\n");
1484 else
1485 RT_TRACE(COMP_DOWN, "Card successfully reset\n");
1486#endif
1487#if 0
1488 if(NIC_8187 == priv->card_8187) {
1489
1490 printk("This is RTL8187 Reset procedure\n");
1491 rtl8192_set_mode(dev,EPROM_CMD_LOAD);
1492 force_pci_posting(dev);
1493 mdelay(200);
1494
1495 /* after the eeprom load cycle, make sure we have
1496 * correct anaparams
1497 */
1498 rtl8192_set_anaparam(dev, RTL8225_ANAPARAM_ON);
1499 rtl8185_set_anaparam2(dev, RTL8225_ANAPARAM2_ON);
1500 }
1501 else
1502#endif
1503 printk("This is RTL8187B Reset procedure\n");
1504
1505}
1506#endif
1507inline u16 ieeerate2rtlrate(int rate)
1508{
1509 switch(rate){
1510 case 10:
1511 return 0;
1512 case 20:
1513 return 1;
1514 case 55:
1515 return 2;
1516 case 110:
1517 return 3;
1518 case 60:
1519 return 4;
1520 case 90:
1521 return 5;
1522 case 120:
1523 return 6;
1524 case 180:
1525 return 7;
1526 case 240:
1527 return 8;
1528 case 360:
1529 return 9;
1530 case 480:
1531 return 10;
1532 case 540:
1533 return 11;
1534 default:
1535 return 3;
1536
1537 }
1538}
1539static u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540};
1540inline u16 rtl8192_rate2rate(short rate)
1541{
1542 if (rate >11) return 0;
1543 return rtl_rate[rate];
1544}
1545
1546
1547/* The protype of rx_isr has changed since one verion of Linux Kernel */
1548#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
1549static void rtl8192_rx_isr(struct urb *urb, struct pt_regs *regs)
1550#else
1551static void rtl8192_rx_isr(struct urb *urb)
1552#endif
1553{
1554 struct sk_buff *skb = (struct sk_buff *) urb->context;
1555 struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
1556 struct net_device *dev = info->dev;
1557 struct r8192_priv *priv = ieee80211_priv(dev);
1558 int out_pipe = info->out_pipe;
1559 int err;
1560 if(!priv->up)
1561 return;
1562 if (unlikely(urb->status)) {
1563 info->urb = NULL;
1564 priv->stats.rxstaterr++;
1565 priv->ieee80211->stats.rx_errors++;
1566 usb_free_urb(urb);
1567 // printk("%s():rx status err\n",__FUNCTION__);
1568 return;
1569 }
1570#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
1571 skb_unlink(skb, &priv->rx_queue);
1572#else
1573 __skb_unlink(skb,&priv->rx_queue);
1574#endif
1575 skb_put(skb, urb->actual_length);
1576
1577 skb_queue_tail(&priv->skb_queue, skb);
1578 tasklet_schedule(&priv->irq_rx_tasklet);
1579
1580 skb = dev_alloc_skb(RX_URB_SIZE);
1581 if (unlikely(!skb)) {
1582 usb_free_urb(urb);
1583 printk("%s():can,t alloc skb\n",__FUNCTION__);
1584 /* TODO check rx queue length and refill *somewhere* */
1585 return;
1586 }
1587
1588 usb_fill_bulk_urb(urb, priv->udev,
1589 usb_rcvbulkpipe(priv->udev, out_pipe), skb->tail,
1590 RX_URB_SIZE, rtl8192_rx_isr, skb);
1591
1592 info = (struct rtl8192_rx_info *) skb->cb;
1593 info->urb = urb;
1594 info->dev = dev;
1595 info->out_pipe = out_pipe;
1596
1597 urb->transfer_buffer = skb->tail;
1598 urb->context = skb;
1599 skb_queue_tail(&priv->rx_queue, skb);
1600#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
1601 err = usb_submit_urb(urb, GFP_ATOMIC);
1602#else
1603 err = usb_submit_urb(urb);
1604#endif
1605 if(err && err != EPERM)
1606 printk("can not submit rxurb, err is %x,URB status is %x\n",err,urb->status);
1607}
1608
1609u32
1610rtl819xusb_rx_command_packet(
1611 struct net_device *dev,
1612 struct ieee80211_rx_stats *pstats
1613 )
1614{
1615 u32 status;
1616
1617 //RT_TRACE(COMP_RECV, DBG_TRACE, ("---> RxCommandPacketHandle819xUsb()\n"));
1618
1619 status = cmpk_message_handle_rx(dev, pstats);
1620 if (status)
1621 {
1622 DMESG("rxcommandpackethandle819xusb: It is a command packet\n");
1623 }
1624 else
1625 {
1626 //RT_TRACE(COMP_RECV, DBG_TRACE, ("RxCommandPacketHandle819xUsb: It is not a command packet\n"));
1627 }
1628
1629 //RT_TRACE(COMP_RECV, DBG_TRACE, ("<--- RxCommandPacketHandle819xUsb()\n"));
1630 return status;
1631}
1632
1633#if 0
1634void rtl8192_tx_queues_stop(struct net_device *dev)
1635{
1636 //struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1637 u8 dma_poll_mask = (1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
1638 dma_poll_mask |= (1<<TX_DMA_STOP_HIPRIORITY_SHIFT);
1639 dma_poll_mask |= (1<<TX_DMA_STOP_NORMPRIORITY_SHIFT);
1640 dma_poll_mask |= (1<<TX_DMA_STOP_BEACON_SHIFT);
1641
1642 rtl8192_set_mode(dev,EPROM_CMD_CONFIG);
1643 write_nic_byte(dev,TX_DMA_POLLING,dma_poll_mask);
1644 rtl8192_set_mode(dev,EPROM_CMD_NORMAL);
1645}
1646#endif
1647
1648void rtl8192_data_hard_stop(struct net_device *dev)
1649{
1650 //FIXME !!
1651 #if 0
1652 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1653 priv->dma_poll_mask |= (1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
1654 rtl8192_set_mode(dev,EPROM_CMD_CONFIG);
1655 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1656 rtl8192_set_mode(dev,EPROM_CMD_NORMAL);
1657 #endif
1658}
1659
1660
1661void rtl8192_data_hard_resume(struct net_device *dev)
1662{
1663 // FIXME !!
1664 #if 0
1665 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1666 priv->dma_poll_mask &= ~(1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
1667 rtl8192_set_mode(dev,EPROM_CMD_CONFIG);
1668 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1669 rtl8192_set_mode(dev,EPROM_CMD_NORMAL);
1670 #endif
1671}
1672
1673/* this function TX data frames when the ieee80211 stack requires this.
1674 * It checks also if we need to stop the ieee tx queue, eventually do it
1675 */
1676void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate)
1677{
1678 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1679 int ret;
1680 unsigned long flags;
1681 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1682 u8 queue_index = tcb_desc->queue_index;
1683
1684 /* shall not be referred by command packet */
1685 assert(queue_index != TXCMD_QUEUE);
1686
1687 spin_lock_irqsave(&priv->tx_lock,flags);
1688
1689 memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
1690// tcb_desc->RATRIndex = 7;
1691// tcb_desc->bTxDisableRateFallBack = 1;
1692// tcb_desc->bTxUseDriverAssingedRate = 1;
1693 tcb_desc->bTxEnableFwCalcDur = 1;
1694 skb_push(skb, priv->ieee80211->tx_headroom);
1695 ret = rtl8192_tx(dev, skb);
1696
1697 //priv->ieee80211->stats.tx_bytes+=(skb->len - priv->ieee80211->tx_headroom);
1698 //priv->ieee80211->stats.tx_packets++;
1699
1700 spin_unlock_irqrestore(&priv->tx_lock,flags);
1701
1702// return ret;
1703 return;
1704}
1705
1706/* This is a rough attempt to TX a frame
1707 * This is called by the ieee 80211 stack to TX management frames.
1708 * If the ring is full packet are dropped (for data frame the queue
1709 * is stopped before this can happen).
1710 */
1711int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
1712{
1713 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
1714 int ret;
1715 unsigned long flags;
1716 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1717 u8 queue_index = tcb_desc->queue_index;
1718
1719
1720 spin_lock_irqsave(&priv->tx_lock,flags);
1721
1722 memcpy((unsigned char *)(skb->cb),&dev,sizeof(dev));
1723 if(queue_index == TXCMD_QUEUE) {
1724 skb_push(skb, USB_HWDESC_HEADER_LEN);
1725 rtl819xU_tx_cmd(dev, skb);
1726 ret = 1;
1727 spin_unlock_irqrestore(&priv->tx_lock,flags);
1728 return ret;
1729 } else {
1730 skb_push(skb, priv->ieee80211->tx_headroom);
1731 ret = rtl8192_tx(dev, skb);
1732 }
1733
1734 spin_unlock_irqrestore(&priv->tx_lock,flags);
1735
1736 return ret;
1737}
1738
1739
1740void rtl8192_try_wake_queue(struct net_device *dev, int pri);
1741
1742#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
1743u16 DrvAggr_PaddingAdd(struct net_device *dev, struct sk_buff *skb)
1744{
1745 u16 PaddingNum = 256 - ((skb->len + TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES) % 256);
1746 return (PaddingNum&0xff);
1747}
1748
1749u8 MRateToHwRate8190Pci(u8 rate);
1750u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc);
1751u8 MapHwQueueToFirmwareQueue(u8 QueueID);
1752struct sk_buff *DrvAggr_Aggregation(struct net_device *dev, struct ieee80211_drv_agg_txb *pSendList)
1753{
1754#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1755 struct ieee80211_device *ieee = netdev_priv(dev);
1756#else
1757 struct ieee80211_device *ieee = (struct ieee80211_device *)dev->priv;
1758#endif
1759 struct r8192_priv *priv = ieee80211_priv(dev);
1760 cb_desc *tcb_desc = NULL;
1761 u8 i;
1762 u32 TotalLength;
1763 struct sk_buff *skb;
1764 struct sk_buff *agg_skb;
1765 tx_desc_819x_usb_aggr_subframe *tx_agg_desc = NULL;
1766 tx_fwinfo_819x_usb *tx_fwinfo = NULL;
1767
1768 //
1769 // Local variable initialization.
1770 //
1771 /* first skb initialization */
1772 skb = pSendList->tx_agg_frames[0];
1773 TotalLength = skb->len;
1774
1775 /* Get the total aggregation length including the padding space and
1776 * sub frame header.
1777 */
1778 for(i = 1; i < pSendList->nr_drv_agg_frames; i++) {
1779 TotalLength += DrvAggr_PaddingAdd(dev, skb);
1780 skb = pSendList->tx_agg_frames[i];
1781 TotalLength += (skb->len + TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES);
1782 }
1783
1784 /* allocate skb to contain the aggregated packets */
1785 agg_skb = dev_alloc_skb(TotalLength + ieee->tx_headroom);
1786 memset(agg_skb->data, 0, agg_skb->len);
1787 skb_reserve(agg_skb, ieee->tx_headroom);
1788
1789// RT_DEBUG_DATA(COMP_SEND, skb->cb, sizeof(skb->cb));
1790 /* reserve info for first subframe Tx descriptor to be set in the tx function */
1791 skb = pSendList->tx_agg_frames[0];
1792 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1793 tcb_desc->drv_agg_enable = 1;
1794 tcb_desc->pkt_size = skb->len;
1795 tcb_desc->DrvAggrNum = pSendList->nr_drv_agg_frames;
1796 printk("DrvAggNum = %d\n", tcb_desc->DrvAggrNum);
1797// RT_DEBUG_DATA(COMP_SEND, skb->cb, sizeof(skb->cb));
1798// printk("========>skb->data ======> \n");
1799// RT_DEBUG_DATA(COMP_SEND, skb->data, skb->len);
1800 memcpy(agg_skb->cb, skb->cb, sizeof(skb->cb));
1801 memcpy(skb_put(agg_skb,skb->len),skb->data,skb->len);
1802
1803 for(i = 1; i < pSendList->nr_drv_agg_frames; i++) {
1804 /* push the next sub frame to be 256 byte aline */
1805 skb_put(agg_skb,DrvAggr_PaddingAdd(dev,skb));
1806
1807 /* Subframe drv Tx descriptor and firmware info setting */
1808 skb = pSendList->tx_agg_frames[i];
1809 tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1810 tx_agg_desc = (tx_desc_819x_usb_aggr_subframe *)agg_skb->tail;
1811 tx_fwinfo = (tx_fwinfo_819x_usb *)(agg_skb->tail + sizeof(tx_desc_819x_usb_aggr_subframe));
1812
1813 memset(tx_fwinfo,0,sizeof(tx_fwinfo_819x_usb));
1814 /* DWORD 0 */
1815 tx_fwinfo->TxHT = (tcb_desc->data_rate&0x80)?1:0;
1816 tx_fwinfo->TxRate = MRateToHwRate8190Pci(tcb_desc->data_rate);
1817 tx_fwinfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
1818 tx_fwinfo->Short = QueryIsShort(tx_fwinfo->TxHT, tx_fwinfo->TxRate, tcb_desc);
1819 if(tcb_desc->bAMPDUEnable) {//AMPDU enabled
1820 tx_fwinfo->AllowAggregation = 1;
1821 /* DWORD 1 */
1822 tx_fwinfo->RxMF = tcb_desc->ampdu_factor;
1823 tx_fwinfo->RxAMD = tcb_desc->ampdu_density&0x07;//ampdudensity
1824 } else {
1825 tx_fwinfo->AllowAggregation = 0;
1826 /* DWORD 1 */
1827 tx_fwinfo->RxMF = 0;
1828 tx_fwinfo->RxAMD = 0;
1829 }
1830
1831 /* Protection mode related */
1832 tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable)?1:0;
1833 tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable)?1:0;
1834 tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC)?1:0;
1835 tx_fwinfo->RtsHT = (tcb_desc->rts_rate&0x80)?1:0;
1836 tx_fwinfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
1837 tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT==0)?(tcb_desc->RTSSC):0;
1838 tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT==1)?((tcb_desc->bRTSBW)?1:0):0;
1839 tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT==0)?(tcb_desc->bRTSUseShortPreamble?1:0):\
1840 (tcb_desc->bRTSUseShortGI?1:0);
1841
1842 /* Set Bandwidth and sub-channel settings. */
1843 if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
1844 {
1845 if(tcb_desc->bPacketBW) {
1846 tx_fwinfo->TxBandwidth = 1;
1847 tx_fwinfo->TxSubCarrier = 0; //By SD3's Jerry suggestion, use duplicated mode
1848 } else {
1849 tx_fwinfo->TxBandwidth = 0;
1850 tx_fwinfo->TxSubCarrier = priv->nCur40MhzPrimeSC;
1851 }
1852 } else {
1853 tx_fwinfo->TxBandwidth = 0;
1854 tx_fwinfo->TxSubCarrier = 0;
1855 }
1856
1857 /* Fill Tx descriptor */
1858 memset(tx_agg_desc, 0, sizeof(tx_desc_819x_usb_aggr_subframe));
1859 /* DWORD 0 */
1860 //tx_agg_desc->LINIP = 0;
1861 //tx_agg_desc->CmdInit = 1;
1862 tx_agg_desc->Offset = sizeof(tx_fwinfo_819x_usb) + 8;
1863 /* already raw data, need not to substract header length */
1864 tx_agg_desc->PktSize = skb->len & 0xffff;
1865
1866 /*DWORD 1*/
1867 tx_agg_desc->SecCAMID= 0;
1868 tx_agg_desc->RATid = tcb_desc->RATRIndex;
1869#if 0
1870 /* Fill security related */
1871 if( pTcb->bEncrypt && !Adapter->MgntInfo.SecurityInfo.SWTxEncryptFlag)
1872 {
1873 EncAlg = SecGetEncryptionOverhead(
1874 Adapter,
1875 &EncryptionMPDUHeadOverhead,
1876 &EncryptionMPDUTailOverhead,
1877 NULL,
1878 NULL,
1879 FALSE,
1880 FALSE);
1881 //2004/07/22, kcwu, EncryptionMPDUHeadOverhead has been added in previous code
1882 //MPDUOverhead = EncryptionMPDUHeadOverhead + EncryptionMPDUTailOverhead;
1883 MPDUOverhead = EncryptionMPDUTailOverhead;
1884 tx_agg_desc->NoEnc = 0;
1885 RT_TRACE(COMP_SEC, DBG_LOUD, ("******We in the loop SecCAMID is %d SecDescAssign is %d The Sec is %d********\n",tx_agg_desc->SecCAMID,tx_agg_desc->SecDescAssign,EncAlg));
1886 //CamDumpAll(Adapter);
1887 }
1888 else
1889#endif
1890 {
1891 //MPDUOverhead = 0;
1892 tx_agg_desc->NoEnc = 1;
1893 }
1894#if 0
1895 switch(EncAlg){
1896 case NO_Encryption:
1897 tx_agg_desc->SecType = 0x0;
1898 break;
1899 case WEP40_Encryption:
1900 case WEP104_Encryption:
1901 tx_agg_desc->SecType = 0x1;
1902 break;
1903 case TKIP_Encryption:
1904 tx_agg_desc->SecType = 0x2;
1905 break;
1906 case AESCCMP_Encryption:
1907 tx_agg_desc->SecType = 0x3;
1908 break;
1909 default:
1910 tx_agg_desc->SecType = 0x0;
1911 break;
1912 }
1913#else
1914 tx_agg_desc->SecType = 0x0;
1915#endif
1916
1917 if (tcb_desc->bHwSec) {
1918 switch (priv->ieee80211->pairwise_key_type)
1919 {
1920 case KEY_TYPE_WEP40:
1921 case KEY_TYPE_WEP104:
1922 tx_agg_desc->SecType = 0x1;
1923 tx_agg_desc->NoEnc = 0;
1924 break;
1925 case KEY_TYPE_TKIP:
1926 tx_agg_desc->SecType = 0x2;
1927 tx_agg_desc->NoEnc = 0;
1928 break;
1929 case KEY_TYPE_CCMP:
1930 tx_agg_desc->SecType = 0x3;
1931 tx_agg_desc->NoEnc = 0;
1932 break;
1933 case KEY_TYPE_NA:
1934 tx_agg_desc->SecType = 0x0;
1935 tx_agg_desc->NoEnc = 1;
1936 break;
1937 }
1938 }
1939
1940 tx_agg_desc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
1941 tx_agg_desc->TxFWInfoSize = sizeof(tx_fwinfo_819x_usb);
1942
1943 tx_agg_desc->DISFB = tcb_desc->bTxDisableRateFallBack;
1944 tx_agg_desc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
1945
1946 tx_agg_desc->OWN = 1;
1947
1948 //DWORD 2
1949 /* According windows driver, it seems that there no need to fill this field */
1950 //tx_agg_desc->TxBufferSize= (u32)(skb->len - USB_HWDESC_HEADER_LEN);
1951
1952 /* to fill next packet */
1953 skb_put(agg_skb,TX_PACKET_DRVAGGR_SUBFRAME_SHIFT_BYTES);
1954 memcpy(skb_put(agg_skb,skb->len),skb->data,skb->len);
1955 }
1956
1957 for(i = 0; i < pSendList->nr_drv_agg_frames; i++) {
1958 dev_kfree_skb_any(pSendList->tx_agg_frames[i]);
1959 }
1960
1961 return agg_skb;
1962}
1963
1964/* NOTE:
1965 This function return a list of PTCB which is proper to be aggregate with the input TCB.
1966 If no proper TCB is found to do aggregation, SendList will only contain the input TCB.
1967*/
1968u8 DrvAggr_GetAggregatibleList(struct net_device *dev, struct sk_buff *skb,
1969 struct ieee80211_drv_agg_txb *pSendList)
1970{
1971#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0)
1972 struct ieee80211_device *ieee = netdev_priv(dev);
1973#else
1974 struct ieee80211_device *ieee = (struct ieee80211_device *)dev->priv;
1975#endif
1976 PRT_HIGH_THROUGHPUT pHTInfo = ieee->pHTInfo;
1977 u16 nMaxAggrNum = pHTInfo->UsbTxAggrNum;
1978 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
1979 u8 QueueID = tcb_desc->queue_index;
1980
1981 do {
1982 pSendList->tx_agg_frames[pSendList->nr_drv_agg_frames++] = skb;
1983 if(pSendList->nr_drv_agg_frames >= nMaxAggrNum) {
1984 break;
1985 }
1986
1987 } while((skb = skb_dequeue(&ieee->skb_drv_aggQ[QueueID])));
1988
1989 RT_TRACE(COMP_AMSDU, "DrvAggr_GetAggregatibleList, nAggrTcbNum = %d \n", pSendList->nr_drv_agg_frames);
1990 return pSendList->nr_drv_agg_frames;
1991}
1992#endif
1993
1994#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
1995static void rtl8192_tx_isr(struct urb *tx_urb, struct pt_regs *reg)
1996#else
1997static void rtl8192_tx_isr(struct urb *tx_urb)
1998#endif
1999{
2000 struct sk_buff *skb = (struct sk_buff*)tx_urb->context;
2001 struct net_device *dev = NULL;
2002 struct r8192_priv *priv = NULL;
2003 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
2004 u8 queue_index = tcb_desc->queue_index;
2005// bool bToSend0Byte;
2006// u16 BufLen = skb->len;
2007
2008 memcpy(&dev,(struct net_device*)(skb->cb),sizeof(struct net_device*));
2009 priv = ieee80211_priv(dev);
2010
2011 if(tcb_desc->queue_index != TXCMD_QUEUE) {
2012 if(tx_urb->status == 0) {
2013 dev->trans_start = jiffies;
2014 // As act as station mode, destion shall be unicast address.
2015 //priv->ieee80211->stats.tx_bytes+=(skb->len - priv->ieee80211->tx_headroom);
2016 //priv->ieee80211->stats.tx_packets++;
2017 priv->stats.txoktotal++;
2018 priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
2019 priv->stats.txbytesunicast += (skb->len - priv->ieee80211->tx_headroom);
2020 } else {
2021 priv->ieee80211->stats.tx_errors++;
2022 //priv->stats.txmanageerr++;
2023 /* TODO */
2024 }
2025 }
2026
2027 /* free skb and tx_urb */
2028 if(skb != NULL) {
2029 dev_kfree_skb_any(skb);
2030 usb_free_urb(tx_urb);
2031 atomic_dec(&priv->tx_pending[queue_index]);
2032 }
2033
2034#if 0 //we need to send zero byte packet just after 512 byte(64 byte)packet is transmitted, or we will halt. It will greatly reduced available page in FW, and ruin our throughput. WB 2008.08.27
2035 if(BufLen > 0 && ((BufLen % 512 == 0)||(BufLen % 64 == 0))) {
2036 bToSend0Byte = true;
2037 }
2038
2039 bToSend0Byte = false;
2040 //
2041 // Note that, we at most handle 1 MPDU to send here, either
2042 // fragment or MPDU in wait queue.
2043 //
2044 if(!bToSend0Byte)
2045#endif
2046 {
2047 //
2048 // Handle HW Beacon:
2049 // We had transfer our beacon frame to host controler at this moment.
2050 //
2051#if 0
2052 if(tcb_desc->tx_queue == BEACON_QUEUE)
2053 {
2054 priv->bSendingBeacon = FALSE;
2055 }
2056#endif
2057 //
2058 // Caution:
2059 // Handling the wait queue of command packets.
2060 // For Tx command packets, we must not do TCB fragment because it is not handled right now.
2061 // We must cut the packets to match the size of TX_CMD_PKT before we send it.
2062 //
2063
2064 /* Handle MPDU in wait queue. */
2065 if(queue_index != BEACON_QUEUE) {
2066 /* Don't send data frame during scanning.*/
2067 if((skb_queue_len(&priv->ieee80211->skb_waitQ[queue_index]) != 0)&&\
2068 (!(priv->ieee80211->queue_stop))) {
2069 if(NULL != (skb = skb_dequeue(&(priv->ieee80211->skb_waitQ[queue_index]))))
2070 priv->ieee80211->softmac_hard_start_xmit(skb, dev);
2071
2072 return; //modified by david to avoid further processing AMSDU
2073 }
2074#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
2075 else if ((skb_queue_len(&priv->ieee80211->skb_drv_aggQ[queue_index])!= 0)&&\
2076 (!(priv->ieee80211->queue_stop))) {
2077 // Tx Driver Aggregation process
2078 /* The driver will aggregation the packets according to the following stets
2079 * 1. check whether there's tx irq available, for it's a completion return
2080 * function, it should contain enough tx irq;
2081 * 2. check pakcet type;
2082 * 3. intialize sendlist, check whether the to-be send packet no greater than 1
2083 * 4. aggregation the packets, and fill firmware info and tx desc to it, etc.
2084 * 5. check whehter the packet could be sent, otherwise just insert to wait head
2085 * */
2086 skb = skb_dequeue(&priv->ieee80211->skb_drv_aggQ[queue_index]);
2087 if(!check_nic_enough_desc(dev, queue_index)) {
2088 skb_queue_head(&(priv->ieee80211->skb_drv_aggQ[queue_index]), skb);
2089 return;
2090 }
2091
2092 {
2093 /*TODO*/
2094 /*
2095 u8* pHeader = skb->data;
2096
2097 if(IsMgntQosData(pHeader) ||
2098 IsMgntQData_Ack(pHeader) ||
2099 IsMgntQData_Poll(pHeader) ||
2100 IsMgntQData_Poll_Ack(pHeader)
2101 )
2102 */
2103 {
2104 struct ieee80211_drv_agg_txb SendList;
2105
2106 memset(&SendList, 0, sizeof(struct ieee80211_drv_agg_txb));
2107 if(DrvAggr_GetAggregatibleList(dev, skb, &SendList) > 1) {
2108 skb = DrvAggr_Aggregation(dev, &SendList);
2109
2110#if 0
2111 printk("=============>to send aggregated packet!\n");
2112 RT_DEBUG_DATA(COMP_SEND, skb->cb, sizeof(skb->cb));
2113 printk("\n=================skb->len = %d\n", skb->len);
2114 RT_DEBUG_DATA(COMP_SEND, skb->data, skb->len);
2115#endif
2116 }
2117 }
2118 priv->ieee80211->softmac_hard_start_xmit(skb, dev);
2119 }
2120 }
2121#endif
2122 }
2123 }
2124
2125#if 0
2126 else
2127 {
2128 RT_TRACE( COMP_SEND,"HalUsbOutComplete(%d): bToSend0Byte.\n", PipeIndex);
2129
2130 //
2131 // In this case, we don't return skb now.
2132 // It will be returned when the 0-byte request completed.
2133 //
2134
2135 //
2136 // Bulk out an 0-byte padding transfer.
2137 //
2138 HalUsbOut0Byte(pAdapter, PipeIndex, skb);
2139 }
2140
2141#endif
2142}
2143
2144void rtl8192_beacon_stop(struct net_device *dev)
2145{
2146 u8 msr, msrm, msr2;
2147 struct r8192_priv *priv = ieee80211_priv(dev);
2148
2149 msr = read_nic_byte(dev, MSR);
2150 msrm = msr & MSR_LINK_MASK;
2151 msr2 = msr & ~MSR_LINK_MASK;
2152
2153 if(NIC_8192U == priv->card_8192) {
2154 usb_kill_urb(priv->rx_urb[MAX_RX_URB]);
2155 }
2156 if ((msrm == (MSR_LINK_ADHOC<<MSR_LINK_SHIFT) ||
2157 (msrm == (MSR_LINK_MASTER<<MSR_LINK_SHIFT)))){
2158 write_nic_byte(dev, MSR, msr2 | MSR_LINK_NONE);
2159 write_nic_byte(dev, MSR, msr);
2160 }
2161}
2162
2163void rtl8192_config_rate(struct net_device* dev, u16* rate_config)
2164{
2165 struct r8192_priv *priv = ieee80211_priv(dev);
2166 struct ieee80211_network *net;
2167 u8 i=0, basic_rate = 0;
2168 net = & priv->ieee80211->current_network;
2169
2170 for (i=0; i<net->rates_len; i++)
2171 {
2172 basic_rate = net->rates[i]&0x7f;
2173 switch(basic_rate)
2174 {
2175 case MGN_1M: *rate_config |= RRSR_1M; break;
2176 case MGN_2M: *rate_config |= RRSR_2M; break;
2177 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
2178 case MGN_11M: *rate_config |= RRSR_11M; break;
2179 case MGN_6M: *rate_config |= RRSR_6M; break;
2180 case MGN_9M: *rate_config |= RRSR_9M; break;
2181 case MGN_12M: *rate_config |= RRSR_12M; break;
2182 case MGN_18M: *rate_config |= RRSR_18M; break;
2183 case MGN_24M: *rate_config |= RRSR_24M; break;
2184 case MGN_36M: *rate_config |= RRSR_36M; break;
2185 case MGN_48M: *rate_config |= RRSR_48M; break;
2186 case MGN_54M: *rate_config |= RRSR_54M; break;
2187 }
2188 }
2189 for (i=0; i<net->rates_ex_len; i++)
2190 {
2191 basic_rate = net->rates_ex[i]&0x7f;
2192 switch(basic_rate)
2193 {
2194 case MGN_1M: *rate_config |= RRSR_1M; break;
2195 case MGN_2M: *rate_config |= RRSR_2M; break;
2196 case MGN_5_5M: *rate_config |= RRSR_5_5M; break;
2197 case MGN_11M: *rate_config |= RRSR_11M; break;
2198 case MGN_6M: *rate_config |= RRSR_6M; break;
2199 case MGN_9M: *rate_config |= RRSR_9M; break;
2200 case MGN_12M: *rate_config |= RRSR_12M; break;
2201 case MGN_18M: *rate_config |= RRSR_18M; break;
2202 case MGN_24M: *rate_config |= RRSR_24M; break;
2203 case MGN_36M: *rate_config |= RRSR_36M; break;
2204 case MGN_48M: *rate_config |= RRSR_48M; break;
2205 case MGN_54M: *rate_config |= RRSR_54M; break;
2206 }
2207 }
2208}
2209
2210
2211#define SHORT_SLOT_TIME 9
2212#define NON_SHORT_SLOT_TIME 20
2213
2214void rtl8192_update_cap(struct net_device* dev, u16 cap)
2215{
2216 u32 tmp = 0;
2217 struct r8192_priv *priv = ieee80211_priv(dev);
2218 struct ieee80211_network *net = &priv->ieee80211->current_network;
2219 priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE;
2220 tmp = priv->basic_rate;
2221 if (priv->short_preamble)
2222 tmp |= BRSR_AckShortPmb;
2223 write_nic_dword(dev, RRSR, tmp);
2224
2225 if (net->mode & (IEEE_G|IEEE_N_24G))
2226 {
2227 u8 slot_time = 0;
2228 if ((cap & WLAN_CAPABILITY_SHORT_SLOT)&&(!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime))
2229 {//short slot time
2230 slot_time = SHORT_SLOT_TIME;
2231 }
2232 else //long slot time
2233 slot_time = NON_SHORT_SLOT_TIME;
2234 priv->slot_time = slot_time;
2235 write_nic_byte(dev, SLOT_TIME, slot_time);
2236 }
2237
2238}
2239void rtl8192_net_update(struct net_device *dev)
2240{
2241
2242 struct r8192_priv *priv = ieee80211_priv(dev);
2243 struct ieee80211_network *net;
2244 u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
2245 u16 rate_config = 0;
2246 net = & priv->ieee80211->current_network;
2247
2248 rtl8192_config_rate(dev, &rate_config);
2249 priv->basic_rate = rate_config &= 0x15f;
2250
2251 write_nic_dword(dev,BSSIDR,((u32*)net->bssid)[0]);
2252 write_nic_word(dev,BSSIDR+4,((u16*)net->bssid)[2]);
2253 //for(i=0;i<ETH_ALEN;i++)
2254 // write_nic_byte(dev,BSSID+i,net->bssid[i]);
2255
2256 rtl8192_update_msr(dev);
2257// rtl8192_update_cap(dev, net->capability);
2258 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
2259 {
2260 write_nic_word(dev, ATIMWND, 2);
2261 write_nic_word(dev, BCN_DMATIME, 1023);
2262 write_nic_word(dev, BCN_INTERVAL, net->beacon_interval);
2263// write_nic_word(dev, BcnIntTime, 100);
2264 write_nic_word(dev, BCN_DRV_EARLY_INT, 1);
2265 write_nic_byte(dev, BCN_ERR_THRESH, 100);
2266 BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT);
2267 // TODO: BcnIFS may required to be changed on ASIC
2268 BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS;
2269
2270 write_nic_word(dev, BCN_TCFG, BcnTimeCfg);
2271 }
2272
2273
2274
2275}
2276
2277//temporary hw beacon is not used any more.
2278//open it when necessary
2279#if 1
2280void rtl819xusb_beacon_tx(struct net_device *dev,u16 tx_rate)
2281{
2282
2283#if 0
2284 struct r8192_priv *priv = ieee80211_priv(dev);
2285 struct sk_buff *skb;
2286 int i = 0;
2287 //u8 cr;
2288
2289 rtl8192_net_update(dev);
2290
2291 skb = ieee80211_get_beacon(priv->ieee80211);
2292 if(!skb){
2293 DMESG("not enought memory for allocating beacon");
2294 return;
2295 }
2296
2297
2298 write_nic_byte(dev, BQREQ, read_nic_byte(dev, BQREQ) | (1<<7));
2299
2300 i=0;
2301 //while(!read_nic_byte(dev,BQREQ & (1<<7)))
2302 while( (read_nic_byte(dev, BQREQ) & (1<<7)) == 0 )
2303 {
2304 msleep_interruptible_rtl(HZ/2);
2305 if(i++ > 10){
2306 DMESGW("get stuck to wait HW beacon to be ready");
2307 return ;
2308 }
2309 }
2310 skb->cb[0] = NORM_PRIORITY;
2311 skb->cb[1] = 0; //morefragment = 0
2312 skb->cb[2] = ieeerate2rtlrate(tx_rate);
2313
2314 rtl8192_tx(dev,skb);
2315
2316#endif
2317}
2318#endif
2319inline u8 rtl8192_IsWirelessBMode(u16 rate)
2320{
2321 if( ((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220) )
2322 return 1;
2323 else return 0;
2324}
2325
2326u16 N_DBPSOfRate(u16 DataRate);
2327
2328u16 ComputeTxTime(
2329 u16 FrameLength,
2330 u16 DataRate,
2331 u8 bManagementFrame,
2332 u8 bShortPreamble
2333)
2334{
2335 u16 FrameTime;
2336 u16 N_DBPS;
2337 u16 Ceiling;
2338
2339 if( rtl8192_IsWirelessBMode(DataRate) )
2340 {
2341 if( bManagementFrame || !bShortPreamble || DataRate == 10 )
2342 { // long preamble
2343 FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
2344 }
2345 else
2346 { // Short preamble
2347 FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
2348 }
2349 if( ( FrameLength*8 % (DataRate/10) ) != 0 ) //Get the Ceilling
2350 FrameTime ++;
2351 } else { //802.11g DSSS-OFDM PLCP length field calculation.
2352 N_DBPS = N_DBPSOfRate(DataRate);
2353 Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
2354 + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
2355 FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
2356 }
2357 return FrameTime;
2358}
2359
2360u16 N_DBPSOfRate(u16 DataRate)
2361{
2362 u16 N_DBPS = 24;
2363
2364 switch(DataRate)
2365 {
2366 case 60:
2367 N_DBPS = 24;
2368 break;
2369
2370 case 90:
2371 N_DBPS = 36;
2372 break;
2373
2374 case 120:
2375 N_DBPS = 48;
2376 break;
2377
2378 case 180:
2379 N_DBPS = 72;
2380 break;
2381
2382 case 240:
2383 N_DBPS = 96;
2384 break;
2385
2386 case 360:
2387 N_DBPS = 144;
2388 break;
2389
2390 case 480:
2391 N_DBPS = 192;
2392 break;
2393
2394 case 540:
2395 N_DBPS = 216;
2396 break;
2397
2398 default:
2399 break;
2400 }
2401
2402 return N_DBPS;
2403}
2404
2405void rtl819xU_cmd_isr(struct urb *tx_cmd_urb, struct pt_regs *regs)
2406{
2407#if 0
2408 struct net_device *dev = (struct net_device*)tx_cmd_urb->context;
2409 struct r8192_priv *priv = ieee80211_priv(dev);
2410 int last_init_packet = 0;
2411 u8 *ptr_cmd_buf;
2412 u16 cmd_buf_len;
2413
2414 if(tx_cmd_urb->status != 0) {
2415 priv->pFirmware.firmware_seg_index = 0; //only begin transter, should it can be set to 1
2416 }
2417
2418 /* Free the urb and the corresponding buf for common Tx cmd packet, or
2419 * last segment of each firmware img.
2420 */
2421 if((priv->pFirmware.firmware_seg_index == 0) ||(priv->pFirmware.firmware_seg_index == priv->pFirmware.firmware_seg_maxnum)) {
2422 priv->pFirmware.firmware_seg_index = 0;//only begin transter, should it can be set to 1
2423 } else {
2424 /* prepare for last transfer */
2425 /* update some infomation for */
2426 /* last segment of the firmware img need indicate to device */
2427 priv->pFirmware.firmware_seg_index++;
2428 if(priv->pFirmware.firmware_seg_index == priv->pFirmware.firmware_seg_maxnum) {
2429 last_init_packet = 1;
2430 }
2431
2432 cmd_buf_len = priv->pFirmware.firmware_seg_container[priv->pFirmware.firmware_seg_index-1].seg_size;
2433 ptr_cmd_buf = priv->pFfirmware.firmware_seg_container[priv->pFfirmware.firmware_seg_index-1].seg_ptr;
2434 rtl819xU_tx_cmd(dev, ptr_cmd_buf, cmd_buf_len, last_init_packet, DESC_PACKET_TYPE_INIT);
2435 }
2436
2437 kfree(tx_cmd_urb->transfer_buffer);
2438#endif
2439 usb_free_urb(tx_cmd_urb);
2440}
2441
2442unsigned int txqueue2outpipe(struct r8192_priv* priv,unsigned int tx_queue) {
2443
2444 if(tx_queue >= 9)
2445 {
2446 RT_TRACE(COMP_ERR,"%s():Unknown queue ID!!!\n",__FUNCTION__);
2447 return 0x04;
2448 }
2449 return priv->txqueue_to_outpipemap[tx_queue];
2450}
2451
2452short rtl819xU_tx_cmd(struct net_device *dev, struct sk_buff *skb)
2453{
2454 struct r8192_priv *priv = ieee80211_priv(dev);
2455 //u8 *tx;
2456 int status;
2457 struct urb *tx_urb;
2458 //int urb_buf_len;
2459 unsigned int idx_pipe;
2460 tx_desc_cmd_819x_usb *pdesc = (tx_desc_cmd_819x_usb *)skb->data;
2461 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
2462 u8 queue_index = tcb_desc->queue_index;
2463
2464 //printk("\n %s::queue_index = %d\n",__FUNCTION__, queue_index);
2465 atomic_inc(&priv->tx_pending[queue_index]);
2466#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
2467 tx_urb = usb_alloc_urb(0,GFP_ATOMIC);
2468#else
2469 tx_urb = usb_alloc_urb(0);
2470#endif
2471 if(!tx_urb){
2472 dev_kfree_skb(skb);
2473 return -ENOMEM;
2474 }
2475
2476 memset(pdesc, 0, USB_HWDESC_HEADER_LEN);
2477 /* Tx descriptor ought to be set according to the skb->cb */
2478 pdesc->FirstSeg = 1;//bFirstSeg;
2479 pdesc->LastSeg = 1;//bLastSeg;
2480 pdesc->CmdInit = tcb_desc->bCmdOrInit;
2481 pdesc->TxBufferSize = tcb_desc->txbuf_size;
2482 pdesc->OWN = 1;
2483 pdesc->LINIP = tcb_desc->bLastIniPkt;
2484
2485 //----------------------------------------------------------------------------
2486 // Fill up USB_OUT_CONTEXT.
2487 //----------------------------------------------------------------------------
2488 // Get index to out pipe from specified QueueID.
2489#ifndef USE_ONE_PIPE
2490 idx_pipe = txqueue2outpipe(priv,queue_index);
2491#else
2492 idx_pipe = 0x04;
2493#endif
2494#ifdef JOHN_DUMP_TXDESC
2495 int i;
2496 printk("<Tx descriptor>--rate %x---",rate);
2497 for (i = 0; i < 8; i++)
2498 printk("%8x ", tx[i]);
2499 printk("\n");
2500#endif
2501 usb_fill_bulk_urb(tx_urb,priv->udev, usb_sndbulkpipe(priv->udev,idx_pipe), \
2502 skb->data, skb->len, rtl8192_tx_isr, skb);
2503
2504#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
2505 status = usb_submit_urb(tx_urb, GFP_ATOMIC);
2506#else
2507 status = usb_submit_urb(tx_urb);
2508#endif
2509
2510 if (!status){
2511 return 0;
2512 }else{
2513 DMESGE("Error TX CMD URB, error %d",
2514 status);
2515 return -1;
2516 }
2517}
2518
2519/*
2520 * Mapping Software/Hardware descriptor queue id to "Queue Select Field"
2521 * in TxFwInfo data structure
2522 * 2006.10.30 by Emily
2523 *
2524 * \param QUEUEID Software Queue
2525*/
2526u8 MapHwQueueToFirmwareQueue(u8 QueueID)
2527{
2528 u8 QueueSelect = 0x0; //defualt set to
2529
2530 switch(QueueID) {
2531 case BE_QUEUE:
2532 QueueSelect = QSLT_BE; //or QSelect = pTcb->priority;
2533 break;
2534
2535 case BK_QUEUE:
2536 QueueSelect = QSLT_BK; //or QSelect = pTcb->priority;
2537 break;
2538
2539 case VO_QUEUE:
2540 QueueSelect = QSLT_VO; //or QSelect = pTcb->priority;
2541 break;
2542
2543 case VI_QUEUE:
2544 QueueSelect = QSLT_VI; //or QSelect = pTcb->priority;
2545 break;
2546 case MGNT_QUEUE:
2547 QueueSelect = QSLT_MGNT;
2548 break;
2549
2550 case BEACON_QUEUE:
2551 QueueSelect = QSLT_BEACON;
2552 break;
2553
2554 // TODO: 2006.10.30 mark other queue selection until we verify it is OK
2555 // TODO: Remove Assertions
2556//#if (RTL819X_FPGA_VER & RTL819X_FPGA_GUANGAN_070502)
2557 case TXCMD_QUEUE:
2558 QueueSelect = QSLT_CMD;
2559 break;
2560//#endif
2561 case HIGH_QUEUE:
2562 QueueSelect = QSLT_HIGH;
2563 break;
2564
2565 default:
2566 RT_TRACE(COMP_ERR, "TransmitTCB(): Impossible Queue Selection: %d \n", QueueID);
2567 break;
2568 }
2569 return QueueSelect;
2570}
2571
2572u8 MRateToHwRate8190Pci(u8 rate)
2573{
2574 u8 ret = DESC90_RATE1M;
2575
2576 switch(rate) {
2577 case MGN_1M: ret = DESC90_RATE1M; break;
2578 case MGN_2M: ret = DESC90_RATE2M; break;
2579 case MGN_5_5M: ret = DESC90_RATE5_5M; break;
2580 case MGN_11M: ret = DESC90_RATE11M; break;
2581 case MGN_6M: ret = DESC90_RATE6M; break;
2582 case MGN_9M: ret = DESC90_RATE9M; break;
2583 case MGN_12M: ret = DESC90_RATE12M; break;
2584 case MGN_18M: ret = DESC90_RATE18M; break;
2585 case MGN_24M: ret = DESC90_RATE24M; break;
2586 case MGN_36M: ret = DESC90_RATE36M; break;
2587 case MGN_48M: ret = DESC90_RATE48M; break;
2588 case MGN_54M: ret = DESC90_RATE54M; break;
2589
2590 // HT rate since here
2591 case MGN_MCS0: ret = DESC90_RATEMCS0; break;
2592 case MGN_MCS1: ret = DESC90_RATEMCS1; break;
2593 case MGN_MCS2: ret = DESC90_RATEMCS2; break;
2594 case MGN_MCS3: ret = DESC90_RATEMCS3; break;
2595 case MGN_MCS4: ret = DESC90_RATEMCS4; break;
2596 case MGN_MCS5: ret = DESC90_RATEMCS5; break;
2597 case MGN_MCS6: ret = DESC90_RATEMCS6; break;
2598 case MGN_MCS7: ret = DESC90_RATEMCS7; break;
2599 case MGN_MCS8: ret = DESC90_RATEMCS8; break;
2600 case MGN_MCS9: ret = DESC90_RATEMCS9; break;
2601 case MGN_MCS10: ret = DESC90_RATEMCS10; break;
2602 case MGN_MCS11: ret = DESC90_RATEMCS11; break;
2603 case MGN_MCS12: ret = DESC90_RATEMCS12; break;
2604 case MGN_MCS13: ret = DESC90_RATEMCS13; break;
2605 case MGN_MCS14: ret = DESC90_RATEMCS14; break;
2606 case MGN_MCS15: ret = DESC90_RATEMCS15; break;
2607 case (0x80|0x20): ret = DESC90_RATEMCS32; break;
2608
2609 default: break;
2610 }
2611 return ret;
2612}
2613
2614
2615u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc)
2616{
2617 u8 tmp_Short;
2618
2619 tmp_Short = (TxHT==1)?((tcb_desc->bUseShortGI)?1:0):((tcb_desc->bUseShortPreamble)?1:0);
2620
2621 if(TxHT==1 && TxRate != DESC90_RATEMCS15)
2622 tmp_Short = 0;
2623
2624 return tmp_Short;
2625}
2626
2627#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
2628static void tx_zero_isr(struct urb *tx_urb, struct pt_regs *reg)
2629#else
2630static void tx_zero_isr(struct urb *tx_urb)
2631#endif
2632{
2633 return;
2634}
2635
2636/*
2637 * The tx procedure is just as following,
2638 * skb->cb will contain all the following information,
2639 * priority, morefrag, rate, &dev.
2640 * */
2641short rtl8192_tx(struct net_device *dev, struct sk_buff* skb)
2642{
2643 struct r8192_priv *priv = ieee80211_priv(dev);
2644 cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
2645 tx_desc_819x_usb *tx_desc = (tx_desc_819x_usb *)skb->data;
2646 tx_fwinfo_819x_usb *tx_fwinfo = (tx_fwinfo_819x_usb *)(skb->data + USB_HWDESC_HEADER_LEN);
2647 struct usb_device *udev = priv->udev;
2648 int pend;
2649 int status;
2650 struct urb *tx_urb = NULL, *tx_urb_zero = NULL;
2651 //int urb_len;
2652 unsigned int idx_pipe;
2653// RT_DEBUG_DATA(COMP_SEND, tcb_desc, sizeof(cb_desc));
2654#if 0
2655 /* Added by Annie for filling Len_Adjust field. 2005-12-14. */
2656 RT_ENC_ALG EncAlg = NO_Encryption;
2657#endif
2658// printk("=============> %s\n", __FUNCTION__);
2659 pend = atomic_read(&priv->tx_pending[tcb_desc->queue_index]);
2660 /* we are locked here so the two atomic_read and inc are executed
2661 * without interleaves
2662 * !!! For debug purpose
2663 */
2664 if( pend > MAX_TX_URB){
2665#if 0
2666 switch (tcb_desc->queue_index) {
2667 case VO_PRIORITY:
2668 priv->stats.txvodrop++;
2669 break;
2670 case VI_PRIORITY:
2671 priv->stats.txvidrop++;
2672 break;
2673 case BE_PRIORITY:
2674 priv->stats.txbedrop++;
2675 break;
2676 default://BK_PRIORITY
2677 priv->stats.txbkdrop++;
2678 break;
2679 }
2680#endif
2681 printk("To discard skb packet!\n");
2682 dev_kfree_skb_any(skb);
2683 return -1;
2684 }
2685
2686#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
2687 tx_urb = usb_alloc_urb(0,GFP_ATOMIC);
2688#else
2689 tx_urb = usb_alloc_urb(0);
2690#endif
2691 if(!tx_urb){
2692 dev_kfree_skb_any(skb);
2693 return -ENOMEM;
2694 }
2695
2696 /* Fill Tx firmware info */
2697 memset(tx_fwinfo,0,sizeof(tx_fwinfo_819x_usb));
2698 /* DWORD 0 */
2699 tx_fwinfo->TxHT = (tcb_desc->data_rate&0x80)?1:0;
2700 tx_fwinfo->TxRate = MRateToHwRate8190Pci(tcb_desc->data_rate);
2701 tx_fwinfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur;
2702 tx_fwinfo->Short = QueryIsShort(tx_fwinfo->TxHT, tx_fwinfo->TxRate, tcb_desc);
2703 if(tcb_desc->bAMPDUEnable) {//AMPDU enabled
2704 tx_fwinfo->AllowAggregation = 1;
2705 /* DWORD 1 */
2706 tx_fwinfo->RxMF = tcb_desc->ampdu_factor;
2707 tx_fwinfo->RxAMD = tcb_desc->ampdu_density&0x07;//ampdudensity
2708 } else {
2709 tx_fwinfo->AllowAggregation = 0;
2710 /* DWORD 1 */
2711 tx_fwinfo->RxMF = 0;
2712 tx_fwinfo->RxAMD = 0;
2713 }
2714
2715 /* Protection mode related */
2716 tx_fwinfo->RtsEnable = (tcb_desc->bRTSEnable)?1:0;
2717 tx_fwinfo->CtsEnable = (tcb_desc->bCTSEnable)?1:0;
2718 tx_fwinfo->RtsSTBC = (tcb_desc->bRTSSTBC)?1:0;
2719 tx_fwinfo->RtsHT = (tcb_desc->rts_rate&0x80)?1:0;
2720 tx_fwinfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate);
2721 tx_fwinfo->RtsSubcarrier = (tx_fwinfo->RtsHT==0)?(tcb_desc->RTSSC):0;
2722 tx_fwinfo->RtsBandwidth = (tx_fwinfo->RtsHT==1)?((tcb_desc->bRTSBW)?1:0):0;
2723 tx_fwinfo->RtsShort = (tx_fwinfo->RtsHT==0)?(tcb_desc->bRTSUseShortPreamble?1:0):\
2724 (tcb_desc->bRTSUseShortGI?1:0);
2725
2726 /* Set Bandwidth and sub-channel settings. */
2727 if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40)
2728 {
2729 if(tcb_desc->bPacketBW) {
2730 tx_fwinfo->TxBandwidth = 1;
2731 tx_fwinfo->TxSubCarrier = 0; //By SD3's Jerry suggestion, use duplicated mode
2732 } else {
2733 tx_fwinfo->TxBandwidth = 0;
2734 tx_fwinfo->TxSubCarrier = priv->nCur40MhzPrimeSC;
2735 }
2736 } else {
2737 tx_fwinfo->TxBandwidth = 0;
2738 tx_fwinfo->TxSubCarrier = 0;
2739 }
2740
2741#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
2742 if (tcb_desc->drv_agg_enable)
2743 {
2744 tx_fwinfo->Tx_INFO_RSVD = (tcb_desc->DrvAggrNum & 0x1f) << 1;
2745 }
2746#endif
2747 /* Fill Tx descriptor */
2748 memset(tx_desc, 0, sizeof(tx_desc_819x_usb));
2749 /* DWORD 0 */
2750 tx_desc->LINIP = 0;
2751 tx_desc->CmdInit = 1;
2752 tx_desc->Offset = sizeof(tx_fwinfo_819x_usb) + 8;
2753
2754#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
2755 if (tcb_desc->drv_agg_enable) {
2756 tx_desc->PktSize = tcb_desc->pkt_size;
2757 } else
2758#endif
2759 {
2760 tx_desc->PktSize = (skb->len - TX_PACKET_SHIFT_BYTES) & 0xffff;
2761 }
2762
2763 /*DWORD 1*/
2764 tx_desc->SecCAMID= 0;
2765 tx_desc->RATid = tcb_desc->RATRIndex;
2766#if 0
2767 /* Fill security related */
2768 if( pTcb->bEncrypt && !Adapter->MgntInfo.SecurityInfo.SWTxEncryptFlag)
2769 {
2770 EncAlg = SecGetEncryptionOverhead(
2771 Adapter,
2772 &EncryptionMPDUHeadOverhead,
2773 &EncryptionMPDUTailOverhead,
2774 NULL,
2775 NULL,
2776 FALSE,
2777 FALSE);
2778 //2004/07/22, kcwu, EncryptionMPDUHeadOverhead has been added in previous code
2779 //MPDUOverhead = EncryptionMPDUHeadOverhead + EncryptionMPDUTailOverhead;
2780 MPDUOverhead = EncryptionMPDUTailOverhead;
2781 tx_desc->NoEnc = 0;
2782 RT_TRACE(COMP_SEC, DBG_LOUD, ("******We in the loop SecCAMID is %d SecDescAssign is %d The Sec is %d********\n",tx_desc->SecCAMID,tx_desc->SecDescAssign,EncAlg));
2783 //CamDumpAll(Adapter);
2784 }
2785 else
2786#endif
2787 {
2788 //MPDUOverhead = 0;
2789 tx_desc->NoEnc = 1;
2790 }
2791#if 0
2792 switch(EncAlg){
2793 case NO_Encryption:
2794 tx_desc->SecType = 0x0;
2795 break;
2796 case WEP40_Encryption:
2797 case WEP104_Encryption:
2798 tx_desc->SecType = 0x1;
2799 break;
2800 case TKIP_Encryption:
2801 tx_desc->SecType = 0x2;
2802 break;
2803 case AESCCMP_Encryption:
2804 tx_desc->SecType = 0x3;
2805 break;
2806 default:
2807 tx_desc->SecType = 0x0;
2808 break;
2809 }
2810#else
2811 tx_desc->SecType = 0x0;
2812#endif
2813 if (tcb_desc->bHwSec)
2814 {
2815 switch (priv->ieee80211->pairwise_key_type)
2816 {
2817 case KEY_TYPE_WEP40:
2818 case KEY_TYPE_WEP104:
2819 tx_desc->SecType = 0x1;
2820 tx_desc->NoEnc = 0;
2821 break;
2822 case KEY_TYPE_TKIP:
2823 tx_desc->SecType = 0x2;
2824 tx_desc->NoEnc = 0;
2825 break;
2826 case KEY_TYPE_CCMP:
2827 tx_desc->SecType = 0x3;
2828 tx_desc->NoEnc = 0;
2829 break;
2830 case KEY_TYPE_NA:
2831 tx_desc->SecType = 0x0;
2832 tx_desc->NoEnc = 1;
2833 break;
2834 }
2835 }
2836
2837 tx_desc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index);
2838 tx_desc->TxFWInfoSize = sizeof(tx_fwinfo_819x_usb);
2839
2840 tx_desc->DISFB = tcb_desc->bTxDisableRateFallBack;
2841 tx_desc->USERATE = tcb_desc->bTxUseDriverAssingedRate;
2842
2843 /* Fill fields that are required to be initialized in all of the descriptors */
2844 //DWORD 0
2845#if 0
2846 tx_desc->FirstSeg = (tcb_desc->bFirstSeg)? 1:0;
2847 tx_desc->LastSeg = (tcb_desc->bLastSeg)?1:0;
2848#else
2849 tx_desc->FirstSeg = 1;
2850 tx_desc->LastSeg = 1;
2851#endif
2852 tx_desc->OWN = 1;
2853
2854#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
2855 if (tcb_desc->drv_agg_enable) {
2856 tx_desc->TxBufferSize = tcb_desc->pkt_size + sizeof(tx_fwinfo_819x_usb);
2857 } else
2858#endif
2859 {
2860 //DWORD 2
2861 tx_desc->TxBufferSize = (u32)(skb->len - USB_HWDESC_HEADER_LEN);
2862 }
2863 /* Get index to out pipe from specified QueueID */
2864#ifndef USE_ONE_PIPE
2865 idx_pipe = txqueue2outpipe(priv,tcb_desc->queue_index);
2866#else
2867 idx_pipe = 0x5;
2868#endif
2869
2870 //RT_DEBUG_DATA(COMP_SEND,tx_fwinfo,sizeof(tx_fwinfo_819x_usb));
2871 //RT_DEBUG_DATA(COMP_SEND,tx_desc,sizeof(tx_desc_819x_usb));
2872
2873 /* To submit bulk urb */
2874 usb_fill_bulk_urb(tx_urb,udev,
2875 usb_sndbulkpipe(udev,idx_pipe), skb->data,
2876 skb->len, rtl8192_tx_isr, skb);
2877
2878#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
2879 status = usb_submit_urb(tx_urb, GFP_ATOMIC);
2880#else
2881 status = usb_submit_urb(tx_urb);
2882#endif
2883 if (!status){
2884//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
2885 bool bSend0Byte = false;
2886 u8 zero = 0;
2887 if(udev->speed == USB_SPEED_HIGH)
2888 {
2889 if (skb->len > 0 && skb->len % 512 == 0)
2890 bSend0Byte = true;
2891 }
2892 else
2893 {
2894 if (skb->len > 0 && skb->len % 64 == 0)
2895 bSend0Byte = true;
2896 }
2897 if (bSend0Byte)
2898 {
2899#if 1
2900#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
2901 tx_urb_zero = usb_alloc_urb(0,GFP_ATOMIC);
2902#else
2903 tx_urb_zero = usb_alloc_urb(0);
2904#endif
2905 if(!tx_urb_zero){
2906 RT_TRACE(COMP_ERR, "can't alloc urb for zero byte\n");
2907 return -ENOMEM;
2908 }
2909 usb_fill_bulk_urb(tx_urb_zero,udev,
2910 usb_sndbulkpipe(udev,idx_pipe), &zero,
2911 0, tx_zero_isr, dev);
2912#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
2913 status = usb_submit_urb(tx_urb_zero, GFP_ATOMIC);
2914#else
2915 status = usb_submit_urb(tx_urb_zero);
2916#endif
2917 if (status){
2918 RT_TRACE(COMP_ERR, "Error TX URB for zero byte %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]), status);
2919 return -1;
2920 }
2921#endif
2922 }
2923 dev->trans_start = jiffies;
2924 atomic_inc(&priv->tx_pending[tcb_desc->queue_index]);
2925 return 0;
2926 }else{
2927 RT_TRACE(COMP_ERR, "Error TX URB %d, error %d", atomic_read(&priv->tx_pending[tcb_desc->queue_index]),
2928 status);
2929 return -1;
2930 }
2931}
2932
2933short rtl8192_usb_initendpoints(struct net_device *dev)
2934{
2935 struct r8192_priv *priv = ieee80211_priv(dev);
2936
2937 priv->rx_urb = (struct urb**) kmalloc (sizeof(struct urb*) * (MAX_RX_URB+1), GFP_KERNEL);
2938
2939#ifndef JACKSON_NEW_RX
2940 for(i=0;i<(MAX_RX_URB+1);i++){
2941
2942#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
2943 priv->rx_urb[i] = usb_alloc_urb(0,GFP_KERNEL);
2944#else
2945 priv->rx_urb[i] = usb_alloc_urb(0);
2946#endif
2947
2948 priv->rx_urb[i]->transfer_buffer = kmalloc(RX_URB_SIZE, GFP_KERNEL);
2949
2950 priv->rx_urb[i]->transfer_buffer_length = RX_URB_SIZE;
2951 }
2952#endif
2953
2954#ifdef THOMAS_BEACON
2955{
2956 int align = 0;
2957 u32 oldaddr,newaddr;
2958#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
2959 priv->rx_urb[16] = usb_alloc_urb(0, GFP_KERNEL);
2960#else
2961 priv->rx_urb[16] = usb_alloc_urb(0);
2962#endif
2963 priv->oldaddr = kmalloc(16, GFP_KERNEL);
2964 oldaddr = (u32)priv->oldaddr;
2965 align = oldaddr&3;
2966 if(align != 0 ){
2967 newaddr = oldaddr + 4 - align;
2968 priv->rx_urb[16]->transfer_buffer_length = 16-4+align;
2969 }
2970 else{
2971 newaddr = oldaddr;
2972 priv->rx_urb[16]->transfer_buffer_length = 16;
2973 }
2974 priv->rx_urb[16]->transfer_buffer = (u32*)newaddr;
2975}
2976#endif
2977
2978 memset(priv->rx_urb, 0, sizeof(struct urb*) * MAX_RX_URB);
2979 priv->pp_rxskb = (struct sk_buff **)kmalloc(sizeof(struct sk_buff *) * MAX_RX_URB, GFP_KERNEL);
2980 if (priv->pp_rxskb == NULL)
2981 goto destroy;
2982
2983 memset(priv->pp_rxskb, 0, sizeof(struct sk_buff*) * MAX_RX_URB);
2984
2985 goto _middle;
2986
2987
2988destroy:
2989 if (priv->pp_rxskb) {
2990 kfree(priv->pp_rxskb);
2991 }
2992 if (priv->rx_urb) {
2993 kfree(priv->rx_urb);
2994 }
2995
2996 priv->pp_rxskb = NULL;
2997 priv->rx_urb = NULL;
2998
2999 DMESGE("Endpoint Alloc Failure");
3000 return -ENOMEM;
3001
3002
3003_middle:
3004
3005 printk("End of initendpoints\n");
3006 return 0;
3007
3008}
3009#ifdef THOMAS_BEACON
3010void rtl8192_usb_deleteendpoints(struct net_device *dev)
3011{
3012 int i;
3013 struct r8192_priv *priv = ieee80211_priv(dev);
3014
3015 if(priv->rx_urb){
3016 for(i=0;i<(MAX_RX_URB+1);i++){
3017 usb_kill_urb(priv->rx_urb[i]);
3018 usb_free_urb(priv->rx_urb[i]);
3019 }
3020 kfree(priv->rx_urb);
3021 priv->rx_urb = NULL;
3022 }
3023 if(priv->oldaddr){
3024 kfree(priv->oldaddr);
3025 priv->oldaddr = NULL;
3026 }
3027 if (priv->pp_rxskb) {
3028 kfree(priv->pp_rxskb);
3029 priv->pp_rxskb = 0;
3030 }
3031}
3032#else
3033void rtl8192_usb_deleteendpoints(struct net_device *dev)
3034{
3035 int i;
3036 struct r8192_priv *priv = ieee80211_priv(dev);
3037
3038#ifndef JACKSON_NEW_RX
3039
3040 if(priv->rx_urb){
3041 for(i=0;i<(MAX_RX_URB+1);i++){
3042 usb_kill_urb(priv->rx_urb[i]);
3043 kfree(priv->rx_urb[i]->transfer_buffer);
3044 usb_free_urb(priv->rx_urb[i]);
3045 }
3046 kfree(priv->rx_urb);
3047 priv->rx_urb = NULL;
3048
3049 }
3050#else
3051 if(priv->rx_urb){
3052 kfree(priv->rx_urb);
3053 priv->rx_urb = NULL;
3054 }
3055 if(priv->oldaddr){
3056 kfree(priv->oldaddr);
3057 priv->oldaddr = NULL;
3058 }
3059 if (priv->pp_rxskb) {
3060 kfree(priv->pp_rxskb);
3061 priv->pp_rxskb = 0;
3062
3063 }
3064
3065#endif
3066}
3067#endif
3068
3069#if 0
3070void rtl8192_set_rate(struct net_device *dev)
3071{
3072 int i;
3073 u16 word;
3074 int basic_rate,min_rr_rate,max_rr_rate;
3075
3076// struct r8192_priv *priv = ieee80211_priv(dev);
3077
3078 //if (ieee80211_is_54g(priv->ieee80211->current_network) &&
3079// priv->ieee80211->state == IEEE80211_LINKED){
3080 basic_rate = ieeerate2rtlrate(240);
3081 min_rr_rate = ieeerate2rtlrate(60);
3082 max_rr_rate = ieeerate2rtlrate(240);
3083
3084//
3085// }else{
3086// basic_rate = ieeerate2rtlrate(20);
3087// min_rr_rate = ieeerate2rtlrate(10);
3088// max_rr_rate = ieeerate2rtlrate(110);
3089// }
3090
3091 write_nic_byte(dev, RESP_RATE,
3092 max_rr_rate<<MAX_RESP_RATE_SHIFT| min_rr_rate<<MIN_RESP_RATE_SHIFT);
3093
3094 //word = read_nic_word(dev, BRSR);
3095 word = read_nic_word(dev, BRSR_8187);
3096 word &= ~BRSR_MBR_8185;
3097
3098
3099 for(i=0;i<=basic_rate;i++)
3100 word |= (1<<i);
3101
3102 //write_nic_word(dev, BRSR, word);
3103 write_nic_word(dev, BRSR_8187, word);
3104 //DMESG("RR:%x BRSR: %x", read_nic_byte(dev,RESP_RATE), read_nic_word(dev,BRSR));
3105}
3106#endif
3107extern void rtl8192_update_ratr_table(struct net_device* dev);
3108void rtl8192_link_change(struct net_device *dev)
3109{
3110// int i;
3111
3112 struct r8192_priv *priv = ieee80211_priv(dev);
3113 struct ieee80211_device* ieee = priv->ieee80211;
3114 //write_nic_word(dev, BCN_INTR_ITV, net->beacon_interval);
3115 if (ieee->state == IEEE80211_LINKED)
3116 {
3117 rtl8192_net_update(dev);
3118 rtl8192_update_ratr_table(dev);
3119#if 1
3120 //add this as in pure N mode, wep encryption will use software way, but there is no chance to set this as wep will not set group key in wext. WB.2008.07.08
3121 if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type))
3122 EnableHWSecurityConfig8192(dev);
3123#endif
3124 }
3125 /*update timing params*/
3126// RT_TRACE(COMP_CH, "========>%s(), chan:%d\n", __FUNCTION__, priv->chan);
3127// rtl8192_set_chan(dev, priv->chan);
3128 if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC)
3129 {
3130 u32 reg = 0;
3131 reg = read_nic_dword(dev, RCR);
3132 if (priv->ieee80211->state == IEEE80211_LINKED)
3133 priv->ReceiveConfig = reg |= RCR_CBSSID;
3134 else
3135 priv->ReceiveConfig = reg &= ~RCR_CBSSID;
3136 write_nic_dword(dev, RCR, reg);
3137 }
3138
3139// rtl8192_set_rxconf(dev);
3140}
3141
3142static struct ieee80211_qos_parameters def_qos_parameters = {
3143 {3,3,3,3},/* cw_min */
3144 {7,7,7,7},/* cw_max */
3145 {2,2,2,2},/* aifs */
3146 {0,0,0,0},/* flags */
3147 {0,0,0,0} /* tx_op_limit */
3148};
3149
3150
3151#if LINUX_VERSION_CODE >=KERNEL_VERSION(2,6,20)
3152void rtl8192_update_beacon(struct work_struct * work)
3153{
3154 struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work);
3155 struct net_device *dev = priv->ieee80211->dev;
3156#else
3157void rtl8192_update_beacon(struct net_device *dev)
3158{
3159 struct r8192_priv *priv = ieee80211_priv(dev);
3160#endif
3161 struct ieee80211_device* ieee = priv->ieee80211;
3162 struct ieee80211_network* net = &ieee->current_network;
3163
3164 if (ieee->pHTInfo->bCurrentHTSupport)
3165 HTUpdateSelfAndPeerSetting(ieee, net);
3166 ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime;
3167 rtl8192_update_cap(dev, net->capability);
3168}
3169/*
3170* background support to run QoS activate functionality
3171*/
3172int WDCAPARA_ADD[] = {EDCAPARA_BE,EDCAPARA_BK,EDCAPARA_VI,EDCAPARA_VO};
3173#if LINUX_VERSION_CODE >=KERNEL_VERSION(2,6,20)
3174void rtl8192_qos_activate(struct work_struct * work)
3175{
3176 struct r8192_priv *priv = container_of(work, struct r8192_priv, qos_activate);
3177 struct net_device *dev = priv->ieee80211->dev;
3178#else
3179void rtl8192_qos_activate(struct net_device *dev)
3180{
3181 struct r8192_priv *priv = ieee80211_priv(dev);
3182#endif
3183 struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters;
3184 u8 mode = priv->ieee80211->current_network.mode;
3185 //u32 size = sizeof(struct ieee80211_qos_parameters);
3186 u8 u1bAIFS;
3187 u32 u4bAcParam;
3188 int i;
3189
3190 if (priv == NULL)
3191 return;
3192
3193#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16))
3194 down(&priv->mutex);
3195#else
3196 mutex_lock(&priv->mutex);
3197#endif
3198 if(priv->ieee80211->state != IEEE80211_LINKED)
3199 goto success;
3200 RT_TRACE(COMP_QOS,"qos active process with associate response received\n");
3201 /* It better set slot time at first */
3202 /* For we just support b/g mode at present, let the slot time at 9/20 selection */
3203 /* update the ac parameter to related registers */
3204 for(i = 0; i < QOS_QUEUE_NUM; i++) {
3205 //Mode G/A: slotTimeTimer = 9; Mode B: 20
3206 u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ?9:20) + aSifsTime;
3207 u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)|
3208 (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)|
3209 (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)|
3210 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
3211
3212 write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam);
3213 //write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4332);
3214 }
3215
3216success:
3217#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16))
3218 up(&priv->mutex);
3219#else
3220 mutex_unlock(&priv->mutex);
3221#endif
3222}
3223
3224static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
3225 int active_network,
3226 struct ieee80211_network *network)
3227{
3228 int ret = 0;
3229 u32 size = sizeof(struct ieee80211_qos_parameters);
3230
3231 if(priv->ieee80211->state !=IEEE80211_LINKED)
3232 return ret;
3233
3234 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
3235 return ret;
3236
3237 if (network->flags & NETWORK_HAS_QOS_MASK) {
3238 if (active_network &&
3239 (network->flags & NETWORK_HAS_QOS_PARAMETERS))
3240 network->qos_data.active = network->qos_data.supported;
3241
3242 if ((network->qos_data.active == 1) && (active_network == 1) &&
3243 (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
3244 (network->qos_data.old_param_count !=
3245 network->qos_data.param_count)) {
3246 network->qos_data.old_param_count =
3247 network->qos_data.param_count;
3248#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
3249 queue_work(priv->priv_wq, &priv->qos_activate);
3250#else
3251 schedule_task(&priv->qos_activate);
3252#endif
3253 RT_TRACE (COMP_QOS, "QoS parameters change call "
3254 "qos_activate\n");
3255 }
3256 } else {
3257 memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
3258 &def_qos_parameters, size);
3259
3260 if ((network->qos_data.active == 1) && (active_network == 1)) {
3261#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
3262 queue_work(priv->priv_wq, &priv->qos_activate);
3263#else
3264 schedule_task(&priv->qos_activate);
3265#endif
3266 RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate \n");
3267 }
3268 network->qos_data.active = 0;
3269 network->qos_data.supported = 0;
3270 }
3271
3272 return 0;
3273}
3274
3275/* handle manage frame frame beacon and probe response */
3276static int rtl8192_handle_beacon(struct net_device * dev,
3277 struct ieee80211_beacon * beacon,
3278 struct ieee80211_network * network)
3279{
3280 struct r8192_priv *priv = ieee80211_priv(dev);
3281
3282 rtl8192_qos_handle_probe_response(priv,1,network);
3283#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
3284 queue_delayed_work(priv->priv_wq, &priv->update_beacon_wq, 0);
3285#else
3286#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
3287 schedule_task(&priv->update_beacon_wq);
3288#else
3289 queue_work(priv->priv_wq, &priv->update_beacon_wq);
3290#endif
3291
3292#endif
3293 return 0;
3294
3295}
3296
3297/*
3298* handling the beaconing responses. if we get different QoS setting
3299* off the network from the associated setting, adjust the QoS
3300* setting
3301*/
3302static int rtl8192_qos_association_resp(struct r8192_priv *priv,
3303 struct ieee80211_network *network)
3304{
3305 int ret = 0;
3306 unsigned long flags;
3307 u32 size = sizeof(struct ieee80211_qos_parameters);
3308 int set_qos_param = 0;
3309
3310 if ((priv == NULL) || (network == NULL))
3311 return ret;
3312
3313 if(priv->ieee80211->state !=IEEE80211_LINKED)
3314 return ret;
3315
3316 if ((priv->ieee80211->iw_mode != IW_MODE_INFRA))
3317 return ret;
3318
3319 spin_lock_irqsave(&priv->ieee80211->lock, flags);
3320 if(network->flags & NETWORK_HAS_QOS_PARAMETERS) {
3321 memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
3322 &network->qos_data.parameters,\
3323 sizeof(struct ieee80211_qos_parameters));
3324 priv->ieee80211->current_network.qos_data.active = 1;
3325#if 0
3326 if((priv->ieee80211->current_network.qos_data.param_count != \
3327 network->qos_data.param_count))
3328#endif
3329 {
3330 set_qos_param = 1;
3331 /* update qos parameter for current network */
3332 priv->ieee80211->current_network.qos_data.old_param_count = \
3333 priv->ieee80211->current_network.qos_data.param_count;
3334 priv->ieee80211->current_network.qos_data.param_count = \
3335 network->qos_data.param_count;
3336 }
3337 } else {
3338 memcpy(&priv->ieee80211->current_network.qos_data.parameters,\
3339 &def_qos_parameters, size);
3340 priv->ieee80211->current_network.qos_data.active = 0;
3341 priv->ieee80211->current_network.qos_data.supported = 0;
3342 set_qos_param = 1;
3343 }
3344
3345 spin_unlock_irqrestore(&priv->ieee80211->lock, flags);
3346
3347 RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n",__FUNCTION__,network->flags ,priv->ieee80211->current_network.qos_data.active);
3348 if (set_qos_param == 1)
3349#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
3350 queue_work(priv->priv_wq, &priv->qos_activate);
3351#else
3352 schedule_task(&priv->qos_activate);
3353#endif
3354
3355
3356 return ret;
3357}
3358
3359
3360static int rtl8192_handle_assoc_response(struct net_device *dev,
3361 struct ieee80211_assoc_response_frame *resp,
3362 struct ieee80211_network *network)
3363{
3364 struct r8192_priv *priv = ieee80211_priv(dev);
3365 rtl8192_qos_association_resp(priv, network);
3366 return 0;
3367}
3368
3369
3370void rtl8192_update_ratr_table(struct net_device* dev)
3371 // POCTET_STRING posLegacyRate,
3372 // u8* pMcsRate)
3373 // PRT_WLAN_STA pEntry)
3374{
3375 struct r8192_priv* priv = ieee80211_priv(dev);
3376 struct ieee80211_device* ieee = priv->ieee80211;
3377 u8* pMcsRate = ieee->dot11HTOperationalRateSet;
3378 //struct ieee80211_network *net = &ieee->current_network;
3379 u32 ratr_value = 0;
3380 u8 rate_index = 0;
3381 rtl8192_config_rate(dev, (u16*)(&ratr_value));
3382 ratr_value |= (*(u16*)(pMcsRate)) << 12;
3383// switch (net->mode)
3384 switch (ieee->mode)
3385 {
3386 case IEEE_A:
3387 ratr_value &= 0x00000FF0;
3388 break;
3389 case IEEE_B:
3390 ratr_value &= 0x0000000F;
3391 break;
3392 case IEEE_G:
3393 ratr_value &= 0x00000FF7;
3394 break;
3395 case IEEE_N_24G:
3396 case IEEE_N_5G:
3397 if (ieee->pHTInfo->PeerMimoPs == 0) //MIMO_PS_STATIC
3398 ratr_value &= 0x0007F007;
3399 else{
3400 if (priv->rf_type == RF_1T2R)
3401 ratr_value &= 0x000FF007;
3402 else
3403 ratr_value &= 0x0F81F007;
3404 }
3405 break;
3406 default:
3407 break;
3408 }
3409 ratr_value &= 0x0FFFFFFF;
3410 if(ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz){
3411 ratr_value |= 0x80000000;
3412 }else if(!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz){
3413 ratr_value |= 0x80000000;
3414 }
3415 write_nic_dword(dev, RATR0+rate_index*4, ratr_value);
3416 write_nic_byte(dev, UFWP, 1);
3417}
3418
3419static u8 ccmp_ie[4] = {0x00,0x50,0xf2,0x04};
3420static u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04};
3421bool GetNmodeSupportBySecCfg8192(struct net_device*dev)
3422{
3423#if 1
3424 struct r8192_priv* priv = ieee80211_priv(dev);
3425 struct ieee80211_device* ieee = priv->ieee80211;
3426 struct ieee80211_network * network = &ieee->current_network;
3427 int wpa_ie_len= ieee->wpa_ie_len;
3428 struct ieee80211_crypt_data* crypt;
3429 int encrypt;
3430
3431 crypt = ieee->crypt[ieee->tx_keyidx];
3432 //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
3433 encrypt = (network->capability & WLAN_CAPABILITY_PRIVACY) || (ieee->host_encrypt && crypt && crypt->ops && (0 == strcmp(crypt->ops->name,"WEP")));
3434
3435 /* simply judge */
3436 if(encrypt && (wpa_ie_len == 0)) {
3437 /* wep encryption, no N mode setting */
3438 return false;
3439// } else if((wpa_ie_len != 0)&&(memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) {
3440 } else if((wpa_ie_len != 0)) {
3441 /* parse pairwise key type */
3442 //if((pairwisekey = WEP40)||(pairwisekey = WEP104)||(pairwisekey = TKIP))
3443 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))))
3444 return true;
3445 else
3446 return false;
3447 } else {
3448 return true;
3449 }
3450
3451#if 0
3452 //In here we discuss with SD4 David. He think we still can send TKIP in broadcast group key in MCS rate.
3453 //We can't force in G mode if Pairwie key is AES and group key is TKIP
3454 if((pSecInfo->GroupEncAlgorithm == WEP104_Encryption) || (pSecInfo->GroupEncAlgorithm == WEP40_Encryption) ||
3455 (pSecInfo->PairwiseEncAlgorithm == WEP104_Encryption) ||
3456 (pSecInfo->PairwiseEncAlgorithm == WEP40_Encryption) || (pSecInfo->PairwiseEncAlgorithm == TKIP_Encryption))
3457 {
3458 return false;
3459 }
3460 else
3461 return true;
3462#endif
3463 return true;
3464#endif
3465}
3466
3467bool GetHalfNmodeSupportByAPs819xUsb(struct net_device* dev)
3468{
3469 bool Reval;
3470 struct r8192_priv* priv = ieee80211_priv(dev);
3471 struct ieee80211_device* ieee = priv->ieee80211;
3472
3473 if(ieee->bHalfWirelessN24GMode == true)
3474 Reval = true;
3475 else
3476 Reval = false;
3477
3478 return Reval;
3479}
3480
3481void rtl8192_refresh_supportrate(struct r8192_priv* priv)
3482{
3483 struct ieee80211_device* ieee = priv->ieee80211;
3484 //we donot consider set support rate for ABG mode, only HT MCS rate is set here.
3485 if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G)
3486 {
3487 memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16);
3488 //RT_DEBUG_DATA(COMP_INIT, ieee->RegHTSuppRateSet, 16);
3489 //RT_DEBUG_DATA(COMP_INIT, ieee->Regdot11HTOperationalRateSet, 16);
3490 }
3491 else
3492 memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
3493 return;
3494}
3495
3496u8 rtl8192_getSupportedWireleeMode(struct net_device*dev)
3497{
3498 struct r8192_priv *priv = ieee80211_priv(dev);
3499 u8 ret = 0;
3500 switch(priv->rf_chip)
3501 {
3502 case RF_8225:
3503 case RF_8256:
3504 case RF_PSEUDO_11N:
3505 ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B);
3506 break;
3507 case RF_8258:
3508 ret = (WIRELESS_MODE_A|WIRELESS_MODE_N_5G);
3509 break;
3510 default:
3511 ret = WIRELESS_MODE_B;
3512 break;
3513 }
3514 return ret;
3515}
3516void rtl8192_SetWirelessMode(struct net_device* dev, u8 wireless_mode)
3517{
3518 struct r8192_priv *priv = ieee80211_priv(dev);
3519 u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
3520
3521#if 1
3522 if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode)==0))
3523 {
3524 if(bSupportMode & WIRELESS_MODE_N_24G)
3525 {
3526 wireless_mode = WIRELESS_MODE_N_24G;
3527 }
3528 else if(bSupportMode & WIRELESS_MODE_N_5G)
3529 {
3530 wireless_mode = WIRELESS_MODE_N_5G;
3531 }
3532 else if((bSupportMode & WIRELESS_MODE_A))
3533 {
3534 wireless_mode = WIRELESS_MODE_A;
3535 }
3536 else if((bSupportMode & WIRELESS_MODE_G))
3537 {
3538 wireless_mode = WIRELESS_MODE_G;
3539 }
3540 else if((bSupportMode & WIRELESS_MODE_B))
3541 {
3542 wireless_mode = WIRELESS_MODE_B;
3543 }
3544 else{
3545 RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __FUNCTION__,bSupportMode);
3546 wireless_mode = WIRELESS_MODE_B;
3547 }
3548 }
3549#ifdef TO_DO_LIST //// TODO: this function doesn't work well at this time, we shoud wait for FPGA
3550 ActUpdateChannelAccessSetting( pAdapter, pHalData->CurrentWirelessMode, &pAdapter->MgntInfo.Info8185.ChannelAccessSetting );
3551#endif
3552 priv->ieee80211->mode = wireless_mode;
3553
3554 if ((wireless_mode == WIRELESS_MODE_N_24G) || (wireless_mode == WIRELESS_MODE_N_5G))
3555 priv->ieee80211->pHTInfo->bEnableHT = 1;
3556 else
3557 priv->ieee80211->pHTInfo->bEnableHT = 0;
3558 RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode);
3559 rtl8192_refresh_supportrate(priv);
3560#endif
3561
3562}
3563//init priv variables here. only non_zero value should be initialized here.
3564static void rtl8192_init_priv_variable(struct net_device* dev)
3565{
3566 struct r8192_priv *priv = ieee80211_priv(dev);
3567 u8 i;
3568 priv->card_8192 = NIC_8192U;
3569 priv->chan = 1; //set to channel 1
3570 priv->ieee80211->mode = WIRELESS_MODE_AUTO; //SET AUTO
3571 priv->ieee80211->iw_mode = IW_MODE_INFRA;
3572 priv->ieee80211->ieee_up=0;
3573 priv->retry_rts = DEFAULT_RETRY_RTS;
3574 priv->retry_data = DEFAULT_RETRY_DATA;
3575 priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD;
3576 priv->ieee80211->rate = 110; //11 mbps
3577 priv->ieee80211->short_slot = 1;
3578 priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
3579 priv->CckPwEnl = 6;
3580 //for silent reset
3581 priv->IrpPendingCount = 1;
3582 priv->ResetProgress = RESET_TYPE_NORESET;
3583 priv->bForcedSilentReset = 0;
3584 priv->bDisableNormalResetCheck = false;
3585 priv->force_reset = false;
3586
3587 priv->ieee80211->FwRWRF = 0; //we don't use FW read/write RF until stable firmware is available.
3588 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
3589 priv->ieee80211->iw_mode = IW_MODE_INFRA;
3590 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
3591 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
3592 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE |
3593 IEEE_SOFTMAC_BEACONS;//added by amy 080604 //| //IEEE_SOFTMAC_SINGLE_QUEUE;
3594
3595 priv->ieee80211->active_scan = 1;
3596 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
3597 priv->ieee80211->host_encrypt = 1;
3598 priv->ieee80211->host_decrypt = 1;
3599 priv->ieee80211->start_send_beacons = NULL;//rtl819xusb_beacon_tx;//-by amy 080604
3600 priv->ieee80211->stop_send_beacons = NULL;//rtl8192_beacon_stop;//-by amy 080604
3601 priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
3602 priv->ieee80211->set_chan = rtl8192_set_chan;
3603 priv->ieee80211->link_change = rtl8192_link_change;
3604 priv->ieee80211->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit;
3605 priv->ieee80211->data_hard_stop = rtl8192_data_hard_stop;
3606 priv->ieee80211->data_hard_resume = rtl8192_data_hard_resume;
3607 priv->ieee80211->init_wmmparam_flag = 0;
3608 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
3609 priv->ieee80211->check_nic_enough_desc = check_nic_enough_desc;
3610 priv->ieee80211->tx_headroom = TX_PACKET_SHIFT_BYTES;
3611 priv->ieee80211->qos_support = 1;
3612
3613 //added by WB
3614// priv->ieee80211->SwChnlByTimerHandler = rtl8192_phy_SwChnl;
3615 priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode;
3616 priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response;
3617 priv->ieee80211->handle_beacon = rtl8192_handle_beacon;
3618 //added by david
3619 priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8192;
3620 priv->ieee80211->GetHalfNmodeSupportByAPsHandler = GetHalfNmodeSupportByAPs819xUsb;
3621 priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode;
3622 //added by amy
3623 priv->ieee80211->InitialGainHandler = InitialGain819xUsb;
3624 priv->card_type = USB;
3625#ifdef TO_DO_LIST
3626 if(Adapter->bInHctTest)
3627 {
3628 pHalData->ShortRetryLimit = 7;
3629 pHalData->LongRetryLimit = 7;
3630 }
3631#endif
3632 {
3633 priv->ShortRetryLimit = 0x30;
3634 priv->LongRetryLimit = 0x30;
3635 }
3636 priv->EarlyRxThreshold = 7;
3637 priv->enable_gpio0 = 0;
3638 priv->TransmitConfig =
3639 // TCR_DurProcMode | //for RTL8185B, duration setting by HW
3640 //? TCR_DISReqQsize |
3641 (TCR_MXDMA_2048<<TCR_MXDMA_OFFSET)| // Max DMA Burst Size per Tx DMA Burst, 7: reservied.
3642 (priv->ShortRetryLimit<<TCR_SRL_OFFSET)| // Short retry limit
3643 (priv->LongRetryLimit<<TCR_LRL_OFFSET) | // Long retry limit
3644 (false ? TCR_SAT: 0); // FALSE: HW provies PLCP length and LENGEXT, TURE: SW proiveds them
3645#ifdef TO_DO_LIST
3646 if(Adapter->bInHctTest)
3647 pHalData->ReceiveConfig = pHalData->CSMethod |
3648 RCR_AMF | RCR_ADF | //RCR_AAP | //accept management/data
3649 //guangan200710
3650 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
3651 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
3652 RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet
3653 ((u32)7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
3654 (pHalData->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold.
3655 (pHalData->EarlyRxThreshold == 7 ? RCR_OnlyErlPkt:0);
3656 else
3657
3658#endif
3659 priv->ReceiveConfig =
3660 RCR_AMF | RCR_ADF | //accept management/data
3661 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
3662 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
3663 //RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet
3664 ((u32)7<<RCR_MXDMA_OFFSET)| // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
3665 (priv->EarlyRxThreshold<<RX_FIFO_THRESHOLD_SHIFT) | // Rx FIFO Threshold, 7: No Rx threshold.
3666 (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT:0);
3667
3668 priv->AcmControl = 0;
3669 priv->pFirmware = (rt_firmware*)kmalloc(sizeof(rt_firmware), GFP_KERNEL);
3670 if (priv->pFirmware)
3671 memset(priv->pFirmware, 0, sizeof(rt_firmware));
3672
3673 /* rx related queue */
3674 skb_queue_head_init(&priv->rx_queue);
3675 skb_queue_head_init(&priv->skb_queue);
3676
3677 /* Tx related queue */
3678 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
3679 skb_queue_head_init(&priv->ieee80211->skb_waitQ [i]);
3680 }
3681 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
3682 skb_queue_head_init(&priv->ieee80211->skb_aggQ [i]);
3683 }
3684 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
3685 skb_queue_head_init(&priv->ieee80211->skb_drv_aggQ [i]);
3686 }
3687 priv->rf_set_chan = rtl8192_phy_SwChnl;
3688}
3689
3690//init lock here
3691static void rtl8192_init_priv_lock(struct r8192_priv* priv)
3692{
3693 spin_lock_init(&priv->tx_lock);
3694 spin_lock_init(&priv->irq_lock);//added by thomas
3695 //spin_lock_init(&priv->rf_lock);
3696 sema_init(&priv->wx_sem,1);
3697 sema_init(&priv->rf_sem,1);
3698#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,16))
3699 sema_init(&priv->mutex, 1);
3700#else
3701 mutex_init(&priv->mutex);
3702#endif
3703}
3704
3705#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3706extern void rtl819x_watchdog_wqcallback(struct work_struct *work);
3707#else
3708extern void rtl819x_watchdog_wqcallback(struct net_device *dev);
3709#endif
3710
3711void rtl8192_irq_rx_tasklet(struct r8192_priv *priv);
3712//init tasklet and wait_queue here. only 2.6 above kernel is considered
3713#define DRV_NAME "wlan0"
3714static void rtl8192_init_priv_task(struct net_device* dev)
3715{
3716 struct r8192_priv *priv = ieee80211_priv(dev);
3717
3718#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
3719#ifdef PF_SYNCTHREAD
3720 priv->priv_wq = create_workqueue(DRV_NAME,0);
3721#else
3722 priv->priv_wq = create_workqueue(DRV_NAME);
3723#endif
3724#endif
3725
3726#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3727 INIT_WORK(&priv->reset_wq, rtl8192_restart);
3728
3729 //INIT_DELAYED_WORK(&priv->watch_dog_wq, hal_dm_watchdog);
3730 INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback);
3731 INIT_DELAYED_WORK(&priv->txpower_tracking_wq, dm_txpower_trackingcallback);
3732// INIT_DELAYED_WORK(&priv->gpio_change_rf_wq, dm_gpio_change_rf_callback);
3733 INIT_DELAYED_WORK(&priv->rfpath_check_wq, dm_rf_pathcheck_workitemcallback);
3734 INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon);
3735 INIT_DELAYED_WORK(&priv->initialgain_operate_wq, InitialGainOperateWorkItemCallBack);
3736 //INIT_WORK(&priv->SwChnlWorkItem, rtl8192_SwChnl_WorkItem);
3737 //INIT_WORK(&priv->SetBWModeWorkItem, rtl8192_SetBWModeWorkItem);
3738 INIT_WORK(&priv->qos_activate, rtl8192_qos_activate);
3739#else
3740#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
3741 tq_init(&priv->reset_wq, (void*)rtl8192_restart, dev);
3742 tq_init(&priv->watch_dog_wq, (void*)rtl819x_watchdog_wqcallback, dev);
3743 tq_init(&priv->txpower_tracking_wq, (void*)dm_txpower_trackingcallback, dev);
3744 tq_init(&priv->rfpath_check_wq, (void*)dm_rf_pathcheck_workitemcallback, dev);
3745 tq_init(&priv->update_beacon_wq, (void*)rtl8192_update_beacon, dev);
3746 //tq_init(&priv->SwChnlWorkItem, (void*) rtl8192_SwChnl_WorkItem, dev);
3747 //tq_init(&priv->SetBWModeWorkItem, (void*)rtl8192_SetBWModeWorkItem, dev);
3748 tq_init(&priv->qos_activate, (void *)rtl8192_qos_activate, dev);
3749#else
3750 INIT_WORK(&priv->reset_wq,(void(*)(void*)) rtl8192_restart,dev);
3751 //INIT_WORK(&priv->watch_dog_wq, (void(*)(void*)) hal_dm_watchdog,dev);
3752 INIT_WORK(&priv->watch_dog_wq, (void(*)(void*)) rtl819x_watchdog_wqcallback,dev);
3753 INIT_WORK(&priv->txpower_tracking_wq, (void(*)(void*)) dm_txpower_trackingcallback,dev);
3754// INIT_WORK(&priv->gpio_change_rf_wq, (void(*)(void*)) dm_gpio_change_rf_callback,dev);
3755 INIT_WORK(&priv->rfpath_check_wq, (void(*)(void*)) dm_rf_pathcheck_workitemcallback,dev);
3756 INIT_WORK(&priv->update_beacon_wq, (void(*)(void*))rtl8192_update_beacon,dev);
3757 INIT_WORK(&priv->initialgain_operate_wq, (void(*)(void*))InitialGainOperateWorkItemCallBack,dev);
3758 //INIT_WORK(&priv->SwChnlWorkItem, (void(*)(void*)) rtl8192_SwChnl_WorkItem, dev);
3759 //INIT_WORK(&priv->SetBWModeWorkItem, (void(*)(void*)) rtl8192_SetBWModeWorkItem, dev);
3760 INIT_WORK(&priv->qos_activate, (void(*)(void *))rtl8192_qos_activate, dev);
3761#endif
3762#endif
3763
3764 tasklet_init(&priv->irq_rx_tasklet,
3765 (void(*)(unsigned long))rtl8192_irq_rx_tasklet,
3766 (unsigned long)priv);
3767}
3768
3769static void rtl8192_get_eeprom_size(struct net_device* dev)
3770{
3771 u16 curCR = 0;
3772 struct r8192_priv *priv = ieee80211_priv(dev);
3773 RT_TRACE(COMP_EPROM, "===========>%s()\n", __FUNCTION__);
3774 curCR = read_nic_word_E(dev,EPROM_CMD);
3775 RT_TRACE(COMP_EPROM, "read from Reg EPROM_CMD(%x):%x\n", EPROM_CMD, curCR);
3776 //whether need I consider BIT5?
3777 priv->epromtype = (curCR & Cmd9346CR_9356SEL) ? EPROM_93c56 : EPROM_93c46;
3778 RT_TRACE(COMP_EPROM, "<===========%s(), epromtype:%d\n", __FUNCTION__, priv->epromtype);
3779}
3780
3781//used to swap endian. as ntohl & htonl are not neccessary to swap endian, so use this instead.
3782static inline u16 endian_swap(u16* data)
3783{
3784 u16 tmp = *data;
3785 *data = (tmp >> 8) | (tmp << 8);
3786 return *data;
3787}
3788static void rtl8192_read_eeprom_info(struct net_device* dev)
3789{
3790 u16 wEPROM_ID = 0;
3791 u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x02};
3792 u8 bLoad_From_EEPOM = false;
3793 struct r8192_priv *priv = ieee80211_priv(dev);
3794 u16 tmpValue = 0;
3795 RT_TRACE(COMP_EPROM, "===========>%s()\n", __FUNCTION__);
3796 wEPROM_ID = eprom_read(dev, 0); //first read EEPROM ID out;
3797 RT_TRACE(COMP_EPROM, "EEPROM ID is 0x%x\n", wEPROM_ID);
3798
3799 if (wEPROM_ID != RTL8190_EEPROM_ID)
3800 {
3801 RT_TRACE(COMP_ERR, "EEPROM ID is invalid(is 0x%x(should be 0x%x)\n", wEPROM_ID, RTL8190_EEPROM_ID);
3802 }
3803 else
3804 bLoad_From_EEPOM = true;
3805
3806 if (bLoad_From_EEPOM)
3807 {
3808 tmpValue = eprom_read(dev, (EEPROM_VID>>1));
3809 priv->eeprom_vid = endian_swap(&tmpValue);
3810 priv->eeprom_pid = eprom_read(dev, (EEPROM_PID>>1));
3811 tmpValue = eprom_read(dev, (EEPROM_ChannelPlan>>1));
3812 priv->eeprom_ChannelPlan =((tmpValue&0xff00)>>8);
3813 priv->btxpowerdata_readfromEEPORM = true;
3814 priv->eeprom_CustomerID = eprom_read(dev, (EEPROM_Customer_ID>>1)) >>8;
3815 }
3816 else
3817 {
3818 priv->eeprom_vid = 0;
3819 priv->eeprom_pid = 0;
3820 priv->card_8192_version = VERSION_819xU_B;
3821 priv->eeprom_ChannelPlan = 0;
3822 priv->eeprom_CustomerID = 0;
3823 }
3824 RT_TRACE(COMP_EPROM, "vid:0x%4x, pid:0x%4x, CustomID:0x%2x, ChanPlan:0x%x\n", priv->eeprom_vid, priv->eeprom_pid, priv->eeprom_CustomerID, priv->eeprom_ChannelPlan);
3825 //set channelplan from eeprom
3826 priv->ChannelPlan = priv->eeprom_ChannelPlan;
3827 if (bLoad_From_EEPOM)
3828 {
3829 int i;
3830 for (i=0; i<6; i+=2)
3831 {
3832 u16 tmp = 0;
3833 tmp = eprom_read(dev, (u16)((EEPROM_NODE_ADDRESS_BYTE_0 + i)>>1));
3834 *(u16*)(&dev->dev_addr[i]) = tmp;
3835 }
3836 }
3837 else
3838 {
3839 memcpy(dev->dev_addr, bMac_Tmp_Addr, 6);
3840 //should I set IDR0 here?
3841 }
3842 RT_TRACE(COMP_EPROM, "MAC addr:"MAC_FMT"\n", MAC_ARG(dev->dev_addr));
3843 priv->rf_type = RTL819X_DEFAULT_RF_TYPE; //default 1T2R
3844 priv->rf_chip = RF_8256;
3845
3846 if (priv->card_8192_version == (u8)VERSION_819xU_A)
3847 {
3848 //read Tx power gain offset of legacy OFDM to HT rate
3849 if (bLoad_From_EEPOM)
3850 priv->EEPROMTxPowerDiff = (eprom_read(dev, (EEPROM_TxPowerDiff>>1))&0xff00) >> 8;
3851 else
3852 priv->EEPROMTxPowerDiff = EEPROM_Default_TxPower;
3853 RT_TRACE(COMP_EPROM, "TxPowerDiff:%d\n", priv->EEPROMTxPowerDiff);
3854 //read ThermalMeter from EEPROM
3855 if (bLoad_From_EEPOM)
3856 priv->EEPROMThermalMeter = (u8)(eprom_read(dev, (EEPROM_ThermalMeter>>1))&0x00ff);
3857 else
3858 priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter;
3859 RT_TRACE(COMP_EPROM, "ThermalMeter:%d\n", priv->EEPROMThermalMeter);
3860 //vivi, for tx power track
3861 priv->TSSI_13dBm = priv->EEPROMThermalMeter *100;
3862 //read antenna tx power offset of B/C/D to A from EEPROM
3863 if (bLoad_From_EEPOM)
3864 priv->EEPROMPwDiff = (eprom_read(dev, (EEPROM_PwDiff>>1))&0x0f00)>>8;
3865 else
3866 priv->EEPROMPwDiff = EEPROM_Default_PwDiff;
3867 RT_TRACE(COMP_EPROM, "TxPwDiff:%d\n", priv->EEPROMPwDiff);
3868 // Read CrystalCap from EEPROM
3869 if (bLoad_From_EEPOM)
3870 priv->EEPROMCrystalCap = (eprom_read(dev, (EEPROM_CrystalCap>>1))&0x0f);
3871 else
3872 priv->EEPROMCrystalCap = EEPROM_Default_CrystalCap;
3873 RT_TRACE(COMP_EPROM, "CrystalCap = %d\n", priv->EEPROMCrystalCap);
3874 //get per-channel Tx power level
3875 if (bLoad_From_EEPOM)
3876 priv->EEPROM_Def_Ver = (eprom_read(dev, (EEPROM_TxPwIndex_Ver>>1))&0xff00)>>8;
3877 else
3878 priv->EEPROM_Def_Ver = 1;
3879 RT_TRACE(COMP_EPROM, "EEPROM_DEF_VER:%d\n", priv->EEPROM_Def_Ver);
3880 if (priv->EEPROM_Def_Ver == 0) //old eeprom definition
3881 {
3882 int i;
3883 if (bLoad_From_EEPOM)
3884 priv->EEPROMTxPowerLevelCCK = (eprom_read(dev, (EEPROM_TxPwIndex_CCK>>1))&0xff) >> 8;
3885 else
3886 priv->EEPROMTxPowerLevelCCK = 0x10;
3887 RT_TRACE(COMP_EPROM, "CCK Tx Power Levl: 0x%02x\n", priv->EEPROMTxPowerLevelCCK);
3888 for (i=0; i<3; i++)
3889 {
3890 if (bLoad_From_EEPOM)
3891 {
3892 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G+i)>>1);
3893 if (((EEPROM_TxPwIndex_OFDM_24G+i) % 2) == 0)
3894 tmpValue = tmpValue & 0x00ff;
3895 else
3896 tmpValue = (tmpValue & 0xff00) >> 8;
3897 }
3898 else
3899 tmpValue = 0x10;
3900 priv->EEPROMTxPowerLevelOFDM24G[i] = (u8) tmpValue;
3901 RT_TRACE(COMP_EPROM, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK);
3902 }
3903 }//end if EEPROM_DEF_VER == 0
3904 else if (priv->EEPROM_Def_Ver == 1)
3905 {
3906 if (bLoad_From_EEPOM)
3907 {
3908 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1>>1));
3909 tmpValue = (tmpValue & 0xff00) >> 8;
3910 }
3911 else
3912 tmpValue = 0x10;
3913 priv->EEPROMTxPowerLevelCCK_V1[0] = (u8)tmpValue;
3914
3915 if (bLoad_From_EEPOM)
3916 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_CCK_V1 + 2)>>1);
3917 else
3918 tmpValue = 0x1010;
3919 *((u16*)(&priv->EEPROMTxPowerLevelCCK_V1[1])) = tmpValue;
3920 if (bLoad_From_EEPOM)
3921 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1>>1));
3922 else
3923 tmpValue = 0x1010;
3924 *((u16*)(&priv->EEPROMTxPowerLevelOFDM24G[0])) = tmpValue;
3925 if (bLoad_From_EEPOM)
3926 tmpValue = eprom_read(dev, (EEPROM_TxPwIndex_OFDM_24G_V1+2)>>1);
3927 else
3928 tmpValue = 0x10;
3929 priv->EEPROMTxPowerLevelOFDM24G[2] = (u8)tmpValue;
3930 }//endif EEPROM_Def_Ver == 1
3931
3932 //update HAL variables
3933 //
3934 {
3935 int i;
3936 for (i=0; i<14; i++)
3937 {
3938 if (i<=3)
3939 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[0];
3940 else if (i>=4 && i<=9)
3941 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[1];
3942 else
3943 priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[2];
3944 }
3945
3946 for (i=0; i<14; i++)
3947 {
3948 if (priv->EEPROM_Def_Ver == 0)
3949 {
3950 if (i<=3)
3951 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[0] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
3952 else if (i>=4 && i<=9)
3953 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK;
3954 else
3955 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelOFDM24G[2] + (priv->EEPROMTxPowerLevelCCK - priv->EEPROMTxPowerLevelOFDM24G[1]);
3956 }
3957 else if (priv->EEPROM_Def_Ver == 1)
3958 {
3959 if (i<=3)
3960 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[0];
3961 else if (i>=4 && i<=9)
3962 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[1];
3963 else
3964 priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK_V1[2];
3965 }
3966 }
3967 }//end update HAL variables
3968 priv->TxPowerDiff = priv->EEPROMPwDiff;
3969// Antenna B gain offset to antenna A, bit0~3
3970 priv->AntennaTxPwDiff[0] = (priv->EEPROMTxPowerDiff & 0xf);
3971 // Antenna C gain offset to antenna A, bit4~7
3972 priv->AntennaTxPwDiff[1] = ((priv->EEPROMTxPowerDiff & 0xf0)>>4);
3973 // CrystalCap, bit12~15
3974 priv->CrystalCap = priv->EEPROMCrystalCap;
3975 // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2
3976 // 92U does not enable TX power tracking.
3977 priv->ThermalMeter[0] = priv->EEPROMThermalMeter;
3978 }//end if VersionID == VERSION_819xU_A
3979
3980//added by vivi, for dlink led, 20080416
3981 switch(priv->eeprom_CustomerID)
3982 {
3983 case EEPROM_CID_RUNTOP:
3984 priv->CustomerID = RT_CID_819x_RUNTOP;
3985 break;
3986
3987 case EEPROM_CID_DLINK:
3988 priv->CustomerID = RT_CID_DLINK;
3989 break;
3990
3991 default:
3992 priv->CustomerID = RT_CID_DEFAULT;
3993 break;
3994
3995 }
3996
3997 switch(priv->CustomerID)
3998 {
3999 case RT_CID_819x_RUNTOP:
4000 priv->LedStrategy = SW_LED_MODE2;
4001 break;
4002
4003 case RT_CID_DLINK:
4004 priv->LedStrategy = SW_LED_MODE4;
4005 break;
4006
4007 default:
4008 priv->LedStrategy = SW_LED_MODE0;
4009 break;
4010
4011 }
4012
4013
4014 if(priv->rf_type == RF_1T2R)
4015 {
4016 RT_TRACE(COMP_EPROM, "\n1T2R config\n");
4017 }
4018 else
4019 {
4020 RT_TRACE(COMP_EPROM, "\n2T4R config\n");
4021 }
4022
4023 // 2008/01/16 MH We can only know RF type in the function. So we have to init
4024 // DIG RATR table again.
4025 init_rate_adaptive(dev);
4026 //we need init DIG RATR table here again.
4027
4028 RT_TRACE(COMP_EPROM, "<===========%s()\n", __FUNCTION__);
4029 return;
4030}
4031
4032short rtl8192_get_channel_map(struct net_device * dev)
4033{
4034 struct r8192_priv *priv = ieee80211_priv(dev);
4035#ifdef ENABLE_DOT11D
4036 if(priv->ChannelPlan > COUNTRY_CODE_GLOBAL_DOMAIN){
4037 printk("rtl8180_init:Error channel plan! Set to default.\n");
4038 priv->ChannelPlan= 0;
4039 }
4040 RT_TRACE(COMP_INIT, "Channel plan is %d\n",priv->ChannelPlan);
4041
4042 rtl819x_set_channel_map(priv->ChannelPlan, priv);
4043#else
4044 int ch,i;
4045 //Set Default Channel Plan
4046 if(!channels){
4047 DMESG("No channels, aborting");
4048 return -1;
4049 }
4050 ch=channels;
4051 priv->ChannelPlan= 0;//hikaru
4052 // set channels 1..14 allowed in given locale
4053 for (i=1; i<=14; i++) {
4054 (priv->ieee80211->channel_map)[i] = (u8)(ch & 0x01);
4055 ch >>= 1;
4056 }
4057#endif
4058 return 0;
4059}
4060
4061short rtl8192_init(struct net_device *dev)
4062{
4063
4064 struct r8192_priv *priv = ieee80211_priv(dev);
4065
4066 memset(&(priv->stats),0,sizeof(struct Stats));
4067 memset(priv->txqueue_to_outpipemap,0,9);
4068#ifdef PIPE12
4069 {
4070 int i=0;
4071 u8 queuetopipe[]={3,2,1,0,4,8,7,6,5};
4072 memcpy(priv->txqueue_to_outpipemap,queuetopipe,9);
4073/* for(i=0;i<9;i++)
4074 printk("%d ",priv->txqueue_to_outpipemap[i]);
4075 printk("\n");*/
4076 }
4077#else
4078 {
4079 u8 queuetopipe[]={3,2,1,0,4,4,0,4,4};
4080 memcpy(priv->txqueue_to_outpipemap,queuetopipe,9);
4081/* for(i=0;i<9;i++)
4082 printk("%d ",priv->txqueue_to_outpipemap[i]);
4083 printk("\n");*/
4084 }
4085#endif
4086 rtl8192_init_priv_variable(dev);
4087 rtl8192_init_priv_lock(priv);
4088 rtl8192_init_priv_task(dev);
4089 rtl8192_get_eeprom_size(dev);
4090 rtl8192_read_eeprom_info(dev);
4091 rtl8192_get_channel_map(dev);
4092 init_hal_dm(dev);
4093 init_timer(&priv->watch_dog_timer);
4094 priv->watch_dog_timer.data = (unsigned long)dev;
4095 priv->watch_dog_timer.function = watch_dog_timer_callback;
4096 if(rtl8192_usb_initendpoints(dev)!=0){
4097 DMESG("Endopoints initialization failed");
4098 return -ENOMEM;
4099 }
4100
4101 //rtl8192_adapter_start(dev);
4102#ifdef DEBUG_EPROM
4103 dump_eprom(dev);
4104#endif
4105 return 0;
4106}
4107
4108/******************************************************************************
4109 *function: This function actually only set RRSR, RATR and BW_OPMODE registers
4110 * not to do all the hw config as its name says
4111 * input: net_device dev
4112 * output: none
4113 * return: none
4114 * notice: This part need to modified according to the rate set we filtered
4115 * ****************************************************************************/
4116void rtl8192_hwconfig(struct net_device* dev)
4117{
4118 u32 regRATR = 0, regRRSR = 0;
4119 u8 regBwOpMode = 0, regTmp = 0;
4120 struct r8192_priv *priv = ieee80211_priv(dev);
4121
4122// Set RRSR, RATR, and BW_OPMODE registers
4123 //
4124 switch(priv->ieee80211->mode)
4125 {
4126 case WIRELESS_MODE_B:
4127 regBwOpMode = BW_OPMODE_20MHZ;
4128 regRATR = RATE_ALL_CCK;
4129 regRRSR = RATE_ALL_CCK;
4130 break;
4131 case WIRELESS_MODE_A:
4132 regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ;
4133 regRATR = RATE_ALL_OFDM_AG;
4134 regRRSR = RATE_ALL_OFDM_AG;
4135 break;
4136 case WIRELESS_MODE_G:
4137 regBwOpMode = BW_OPMODE_20MHZ;
4138 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4139 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4140 break;
4141 case WIRELESS_MODE_AUTO:
4142#ifdef TO_DO_LIST
4143 if (Adapter->bInHctTest)
4144 {
4145 regBwOpMode = BW_OPMODE_20MHZ;
4146 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4147 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4148 }
4149 else
4150#endif
4151 {
4152 regBwOpMode = BW_OPMODE_20MHZ;
4153 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
4154 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4155 }
4156 break;
4157 case WIRELESS_MODE_N_24G:
4158 // It support CCK rate by default.
4159 // CCK rate will be filtered out only when associated AP does not support it.
4160 regBwOpMode = BW_OPMODE_20MHZ;
4161 regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
4162 regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG;
4163 break;
4164 case WIRELESS_MODE_N_5G:
4165 regBwOpMode = BW_OPMODE_5G;
4166 regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS;
4167 regRRSR = RATE_ALL_OFDM_AG;
4168 break;
4169 }
4170
4171 write_nic_byte(dev, BW_OPMODE, regBwOpMode);
4172 {
4173 u32 ratr_value = 0;
4174 ratr_value = regRATR;
4175 if (priv->rf_type == RF_1T2R)
4176 {
4177 ratr_value &= ~(RATE_ALL_OFDM_2SS);
4178 }
4179 write_nic_dword(dev, RATR0, ratr_value);
4180 write_nic_byte(dev, UFWP, 1);
4181 }
4182 regTmp = read_nic_byte(dev, 0x313);
4183 regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff);
4184 write_nic_dword(dev, RRSR, regRRSR);
4185
4186 //
4187 // Set Retry Limit here
4188 //
4189 write_nic_word(dev, RETRY_LIMIT,
4190 priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT | \
4191 priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT);
4192 // Set Contention Window here
4193
4194 // Set Tx AGC
4195
4196 // Set Tx Antenna including Feedback control
4197
4198 // Set Auto Rate fallback control
4199
4200
4201}
4202
4203
4204//InitializeAdapter and PhyCfg
4205bool rtl8192_adapter_start(struct net_device *dev)
4206{
4207 struct r8192_priv *priv = ieee80211_priv(dev);
4208 u32 dwRegRead = 0;
4209 bool init_status = true;
4210 RT_TRACE(COMP_INIT, "====>%s()\n", __FUNCTION__);
4211 priv->Rf_Mode = RF_OP_By_SW_3wire;
4212 //for ASIC power on sequence
4213 write_nic_byte_E(dev, 0x5f, 0x80);
4214 mdelay(50);
4215 write_nic_byte_E(dev, 0x5f, 0xf0);
4216 write_nic_byte_E(dev, 0x5d, 0x00);
4217 write_nic_byte_E(dev, 0x5e, 0x80);
4218 write_nic_byte(dev, 0x17, 0x37);
4219 mdelay(10);
4220//#ifdef TO_DO_LIST
4221 priv->pFirmware->firmware_status = FW_STATUS_0_INIT;
4222 //config CPUReset Register
4223 //Firmware Reset or not?
4224 dwRegRead = read_nic_dword(dev, CPU_GEN);
4225 if (priv->pFirmware->firmware_status == FW_STATUS_0_INIT)
4226 dwRegRead |= CPU_GEN_SYSTEM_RESET; //do nothing here?
4227 else if (priv->pFirmware->firmware_status == FW_STATUS_5_READY)
4228 dwRegRead |= CPU_GEN_FIRMWARE_RESET;
4229 else
4230 RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __FUNCTION__, priv->pFirmware->firmware_status);
4231
4232 write_nic_dword(dev, CPU_GEN, dwRegRead);
4233 //mdelay(30);
4234 //config BB.
4235 rtl8192_BBConfig(dev);
4236
4237#if 1
4238 //Loopback mode or not
4239 priv->LoopbackMode = RTL819xU_NO_LOOPBACK;
4240// priv->LoopbackMode = RTL819xU_MAC_LOOPBACK;
4241
4242 dwRegRead = read_nic_dword(dev, CPU_GEN);
4243 if (priv->LoopbackMode == RTL819xU_NO_LOOPBACK)
4244 dwRegRead = ((dwRegRead & CPU_GEN_NO_LOOPBACK_MSK) | CPU_GEN_NO_LOOPBACK_SET);
4245 else if (priv->LoopbackMode == RTL819xU_MAC_LOOPBACK)
4246 dwRegRead |= CPU_CCK_LOOPBACK;
4247 else
4248 RT_TRACE(COMP_ERR, "Serious error in %s(): wrong loopback mode setting(%d)\n", __FUNCTION__, priv->LoopbackMode);
4249
4250 write_nic_dword(dev, CPU_GEN, dwRegRead);
4251
4252 //after reset cpu, we need wait for a seconds to write in register.
4253 udelay(500);
4254
4255 //xiong add for new bitfile:usb suspend reset pin set to 1. //do we need?
4256 write_nic_byte_E(dev, 0x5f, (read_nic_byte_E(dev, 0x5f)|0x20));
4257
4258 //Set Hardware
4259 rtl8192_hwconfig(dev);
4260
4261 //turn on Tx/Rx
4262 write_nic_byte(dev, CMDR, CR_RE|CR_TE);
4263
4264 //set IDR0 here
4265 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
4266 write_nic_word(dev, MAC4, ((u16*)(dev->dev_addr + 4))[0]);
4267
4268 //set RCR
4269 write_nic_dword(dev, RCR, priv->ReceiveConfig);
4270
4271 //Initialize Number of Reserved Pages in Firmware Queue
4272 write_nic_dword(dev, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |\
4273 NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT | \
4274 NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT | \
4275 NUM_OF_PAGE_IN_FW_QUEUE_VO <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
4276 write_nic_dword(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT |\
4277 NUM_OF_PAGE_IN_FW_QUEUE_CMD << RSVD_FW_QUEUE_PAGE_CMD_SHIFT);
4278 write_nic_dword(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW| \
4279 NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT
4280// | NUM_OF_PAGE_IN_FW_QUEUE_PUB<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT
4281 );
4282 write_nic_dword(dev, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK));
4283
4284 //Set AckTimeout
4285 // TODO: (it value is only for FPGA version). need to be changed!!2006.12.18, by Emily
4286 write_nic_byte(dev, ACK_TIMEOUT, 0x30);
4287
4288// RT_TRACE(COMP_INIT, "%s():priv->ResetProgress is %d\n", __FUNCTION__,priv->ResetProgress);
4289 if(priv->ResetProgress == RESET_TYPE_NORESET)
4290 rtl8192_SetWirelessMode(dev, priv->ieee80211->mode);
4291 if(priv->ResetProgress == RESET_TYPE_NORESET){
4292 CamResetAllEntry(dev);
4293 {
4294 u8 SECR_value = 0x0;
4295 SECR_value |= SCR_TxEncEnable;
4296 SECR_value |= SCR_RxDecEnable;
4297 SECR_value |= SCR_NoSKMC;
4298 write_nic_byte(dev, SECR, SECR_value);
4299 }
4300 }
4301
4302 //Beacon related
4303 write_nic_word(dev, ATIMWND, 2);
4304 write_nic_word(dev, BCN_INTERVAL, 100);
4305
4306 {
4307#define DEFAULT_EDCA 0x005e4332
4308 int i;
4309 for (i=0; i<QOS_QUEUE_NUM; i++)
4310 write_nic_dword(dev, WDCAPARA_ADD[i], DEFAULT_EDCA);
4311 }
4312#ifdef USB_RX_AGGREGATION_SUPPORT
4313 //3 For usb rx firmware aggregation control
4314 if(priv->ResetProgress == RESET_TYPE_NORESET)
4315 {
4316 u32 ulValue;
4317 PRT_HIGH_THROUGHPUT pHTInfo = priv->ieee80211->pHTInfo;
4318 ulValue = (pHTInfo->UsbRxFwAggrEn<<24) | (pHTInfo->UsbRxFwAggrPageNum<<16) |
4319 (pHTInfo->UsbRxFwAggrPacketNum<<8) | (pHTInfo->UsbRxFwAggrTimeout);
4320 /*
4321 * If usb rx firmware aggregation is enabled,
4322 * when anyone of three threshold conditions above is reached,
4323 * firmware will send aggregated packet to driver.
4324 */
4325 write_nic_dword(dev, 0x1a8, ulValue);
4326 priv->bCurrentRxAggrEnable = true;
4327 }
4328#endif
4329
4330 rtl8192_phy_configmac(dev);
4331
4332 if (priv->card_8192_version == (u8) VERSION_819xU_A)
4333 {
4334 rtl8192_phy_getTxPower(dev);
4335 rtl8192_phy_setTxPower(dev, priv->chan);
4336 }
4337
4338 //Firmware download
4339 init_status = init_firmware(dev);
4340 if(!init_status)
4341 {
4342 RT_TRACE(COMP_ERR,"ERR!!! %s(): Firmware download is failed\n", __FUNCTION__);
4343 return init_status;
4344 }
4345 RT_TRACE(COMP_INIT, "%s():after firmware download\n", __FUNCTION__);
4346 //
4347#ifdef TO_DO_LIST
4348if(Adapter->ResetProgress == RESET_TYPE_NORESET)
4349 {
4350 if(pMgntInfo->RegRfOff == TRUE)
4351 { // User disable RF via registry.
4352 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RegRfOff ----------\n"));
4353 MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_SW);
4354 // Those action will be discard in MgntActSet_RF_State because off the same state
4355 for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
4356 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
4357 }
4358 else if(pMgntInfo->RfOffReason > RF_CHANGE_BY_PS)
4359 { // H/W or S/W RF OFF before sleep.
4360 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): Turn off RF for RfOffReason(%d) ----------\n", pMgntInfo->RfOffReason));
4361 MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
4362 }
4363 else
4364 {
4365 pHalData->eRFPowerState = eRfOn;
4366 pMgntInfo->RfOffReason = 0;
4367 RT_TRACE((COMP_INIT|COMP_RF), DBG_LOUD, ("InitializeAdapter819xUsb(): RF is on ----------\n"));
4368 }
4369 }
4370 else
4371 {
4372 if(pHalData->eRFPowerState == eRfOff)
4373 {
4374 MgntActSet_RF_State(Adapter, eRfOff, pMgntInfo->RfOffReason);
4375 // Those action will be discard in MgntActSet_RF_State because off the same state
4376 for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++)
4377 PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0);
4378 }
4379 }
4380#endif
4381 //config RF.
4382 if(priv->ResetProgress == RESET_TYPE_NORESET){
4383 rtl8192_phy_RFConfig(dev);
4384 RT_TRACE(COMP_INIT, "%s():after phy RF config\n", __FUNCTION__);
4385 }
4386
4387
4388 if(priv->ieee80211->FwRWRF)
4389 // We can force firmware to do RF-R/W
4390 priv->Rf_Mode = RF_OP_By_FW;
4391 else
4392 priv->Rf_Mode = RF_OP_By_SW_3wire;
4393
4394
4395 rtl8192_phy_updateInitGain(dev);
4396 /*--set CCK and OFDM Block "ON"--*/
4397 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
4398 rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
4399
4400 if(priv->ResetProgress == RESET_TYPE_NORESET)
4401 {
4402 //if D or C cut
4403 u8 tmpvalue = read_nic_byte(dev, 0x301);
4404 if(tmpvalue ==0x03)
4405 {
4406 priv->bDcut = TRUE;
4407 RT_TRACE(COMP_POWER_TRACKING, "D-cut\n");
4408 }
4409 else
4410 {
4411 priv->bDcut = FALSE;
4412 RT_TRACE(COMP_POWER_TRACKING, "C-cut\n");
4413 }
4414 dm_initialize_txpower_tracking(dev);
4415
4416 if(priv->bDcut == TRUE)
4417 {
4418 u32 i, TempCCk;
4419 u32 tmpRegA= rtl8192_QueryBBReg(dev,rOFDM0_XATxIQImbalance,bMaskDWord);
4420 // u32 tmpRegC= rtl8192_QueryBBReg(dev,rOFDM0_XCTxIQImbalance,bMaskDWord);
4421 for(i = 0; i<TxBBGainTableLength; i++)
4422 {
4423 if(tmpRegA == priv->txbbgain_table[i].txbbgain_value)
4424 {
4425 priv->rfa_txpowertrackingindex= (u8)i;
4426 priv->rfa_txpowertrackingindex_real= (u8)i;
4427 priv->rfa_txpowertracking_default= priv->rfa_txpowertrackingindex;
4428 break;
4429 }
4430 }
4431
4432 TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
4433
4434 for(i=0 ; i<CCKTxBBGainTableLength ; i++)
4435 {
4436
4437 if(TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0])
4438 {
4439 priv->cck_present_attentuation_20Mdefault=(u8) i;
4440 break;
4441 }
4442 }
4443 priv->cck_present_attentuation_40Mdefault= 0;
4444 priv->cck_present_attentuation_difference= 0;
4445 priv->cck_present_attentuation = priv->cck_present_attentuation_20Mdefault;
4446
4447 // pMgntInfo->bTXPowerTracking = FALSE;//TEMPLY DISABLE
4448 }
4449 }
4450 write_nic_byte(dev, 0x87, 0x0);
4451
4452
4453#endif
4454 return init_status;
4455}
4456
4457/* this configures registers for beacon tx and enables it via
4458 * rtl8192_beacon_tx_enable(). rtl8192_beacon_tx_disable() might
4459 * be used to stop beacon transmission
4460 */
4461#if 0
4462void rtl8192_start_tx_beacon(struct net_device *dev)
4463{
4464 int i;
4465 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
4466 u16 word;
4467 DMESG("Enabling beacon TX");
4468 //write_nic_byte(dev, TX_CONF,0xe6);// TX_CONF
4469 //rtl8192_init_beacon(dev);
4470 //set_nic_txring(dev);
4471// rtl8192_prepare_beacon(dev);
4472 rtl8192_irq_disable(dev);
4473// rtl8192_beacon_tx_enable(dev);
4474 rtl8192_set_mode(dev,EPROM_CMD_CONFIG);
4475 //write_nic_byte(dev,0x9d,0x20); //DMA Poll
4476 //write_nic_word(dev,0x7a,0);
4477 //write_nic_word(dev,0x7a,0x8000);
4478
4479
4480 word = read_nic_word(dev, BcnItv);
4481 word &= ~BcnItv_BcnItv; // clear Bcn_Itv
4482 write_nic_word(dev, BcnItv, word);
4483
4484 write_nic_word(dev, AtimWnd,
4485 read_nic_word(dev, AtimWnd) &~ AtimWnd_AtimWnd);
4486
4487 word = read_nic_word(dev, BCN_INTR_ITV);
4488 word &= ~BCN_INTR_ITV_MASK;
4489
4490 //word |= priv->ieee80211->beacon_interval *
4491 // ((priv->txbeaconcount > 1)?(priv->txbeaconcount-1):1);
4492 // FIXME:FIXME check if correct ^^ worked with 0x3e8;
4493
4494 write_nic_word(dev, BCN_INTR_ITV, word);
4495
4496 //write_nic_word(dev,0x2e,0xe002);
4497 //write_nic_dword(dev,0x30,0xb8c7832e);
4498 for(i=0; i<ETH_ALEN; i++)
4499 write_nic_byte(dev, BSSID+i, priv->ieee80211->beacon_cell_ssid[i]);
4500
4501// rtl8192_update_msr(dev);
4502
4503
4504 //write_nic_byte(dev,CONFIG4,3); /* !!!!!!!!!! */
4505
4506 rtl8192_set_mode(dev, EPROM_CMD_NORMAL);
4507
4508 rtl8192_irq_enable(dev);
4509
4510 /* VV !!!!!!!!!! VV*/
4511 /*
4512 rtl8192_set_mode(dev,EPROM_CMD_CONFIG);
4513 write_nic_byte(dev,0x9d,0x00);
4514 rtl8192_set_mode(dev,EPROM_CMD_NORMAL);
4515*/
4516}
4517#endif
4518/***************************************************************************
4519 -------------------------------NET STUFF---------------------------
4520***************************************************************************/
4521
4522static struct net_device_stats *rtl8192_stats(struct net_device *dev)
4523{
4524 struct r8192_priv *priv = ieee80211_priv(dev);
4525
4526 return &priv->ieee80211->stats;
4527}
4528
4529bool
4530HalTxCheckStuck819xUsb(
4531 struct net_device *dev
4532 )
4533{
4534 struct r8192_priv *priv = ieee80211_priv(dev);
4535 u16 RegTxCounter = read_nic_word(dev, 0x128);
4536 bool bStuck = FALSE;
4537 RT_TRACE(COMP_RESET,"%s():RegTxCounter is %d,TxCounter is %d\n",__FUNCTION__,RegTxCounter,priv->TxCounter);
4538 if(priv->TxCounter==RegTxCounter)
4539 bStuck = TRUE;
4540
4541 priv->TxCounter = RegTxCounter;
4542
4543 return bStuck;
4544}
4545
4546/*
4547* <Assumption: RT_TX_SPINLOCK is acquired.>
4548* First added: 2006.11.19 by emily
4549*/
4550RESET_TYPE
4551TxCheckStuck(struct net_device *dev)
4552{
4553 struct r8192_priv *priv = ieee80211_priv(dev);
4554 u8 QueueID;
4555// PRT_TCB pTcb;
4556// u8 ResetThreshold;
4557 bool bCheckFwTxCnt = false;
4558 //unsigned long flags;
4559
4560 //
4561 // Decide Stuch threshold according to current power save mode
4562 //
4563
4564// RT_TRACE(COMP_RESET, " ==> TxCheckStuck()\n");
4565// PlatformAcquireSpinLock(Adapter, RT_TX_SPINLOCK);
4566// spin_lock_irqsave(&priv->ieee80211->lock,flags);
4567 for (QueueID = 0; QueueID<=BEACON_QUEUE;QueueID ++)
4568 {
4569 if(QueueID == TXCMD_QUEUE)
4570 continue;
4571#if 1
4572#ifdef USB_TX_DRIVER_AGGREGATION_ENABLE
4573 if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_drv_aggQ[QueueID]) == 0))
4574#else
4575 if((skb_queue_len(&priv->ieee80211->skb_waitQ[QueueID]) == 0) && (skb_queue_len(&priv->ieee80211->skb_aggQ[QueueID]) == 0))
4576#endif
4577 continue;
4578#endif
4579
4580 bCheckFwTxCnt = true;
4581 }
4582// PlatformReleaseSpinLock(Adapter, RT_TX_SPINLOCK);
4583// spin_unlock_irqrestore(&priv->ieee80211->lock,flags);
4584// RT_TRACE(COMP_RESET,"bCheckFwTxCnt is %d\n",bCheckFwTxCnt);
4585#if 1
4586 if(bCheckFwTxCnt)
4587 {
4588 if(HalTxCheckStuck819xUsb(dev))
4589 {
4590 RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n");
4591 return RESET_TYPE_SILENT;
4592 }
4593 }
4594#endif
4595 return RESET_TYPE_NORESET;
4596}
4597
4598bool
4599HalRxCheckStuck819xUsb(struct net_device *dev)
4600{
4601 u16 RegRxCounter = read_nic_word(dev, 0x130);
4602 struct r8192_priv *priv = ieee80211_priv(dev);
4603 bool bStuck = FALSE;
4604 static u8 rx_chk_cnt = 0;
4605 RT_TRACE(COMP_RESET,"%s(): RegRxCounter is %d,RxCounter is %d\n",__FUNCTION__,RegRxCounter,priv->RxCounter);
4606 // If rssi is small, we should check rx for long time because of bad rx.
4607 // or maybe it will continuous silent reset every 2 seconds.
4608 rx_chk_cnt++;
4609 if(priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5))
4610 {
4611 rx_chk_cnt = 0; //high rssi, check rx stuck right now.
4612 }
4613 else if(priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) &&
4614 ((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_40M) ||
4615 (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_20M)) )
4616 {
4617 if(rx_chk_cnt < 2)
4618 {
4619 return bStuck;
4620 }
4621 else
4622 {
4623 rx_chk_cnt = 0;
4624 }
4625 }
4626 else if(((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_40M) ||
4627 (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_20M)) &&
4628 priv->undecorated_smoothed_pwdb >= VeryLowRSSI)
4629 {
4630 if(rx_chk_cnt < 4)
4631 {
4632 //DbgPrint("RSSI < %d && RSSI >= %d, no check this time \n", RateAdaptiveTH_Low, VeryLowRSSI);
4633 return bStuck;
4634 }
4635 else
4636 {
4637 rx_chk_cnt = 0;
4638 //DbgPrint("RSSI < %d && RSSI >= %d, check this time \n", RateAdaptiveTH_Low, VeryLowRSSI);
4639 }
4640 }
4641 else
4642 {
4643 if(rx_chk_cnt < 8)
4644 {
4645 //DbgPrint("RSSI <= %d, no check this time \n", VeryLowRSSI);
4646 return bStuck;
4647 }
4648 else
4649 {
4650 rx_chk_cnt = 0;
4651 //DbgPrint("RSSI <= %d, check this time \n", VeryLowRSSI);
4652 }
4653 }
4654
4655 if(priv->RxCounter==RegRxCounter)
4656 bStuck = TRUE;
4657
4658 priv->RxCounter = RegRxCounter;
4659
4660 return bStuck;
4661}
4662
4663RESET_TYPE
4664RxCheckStuck(struct net_device *dev)
4665{
4666 struct r8192_priv *priv = ieee80211_priv(dev);
4667 //int i;
4668 bool bRxCheck = FALSE;
4669
4670// RT_TRACE(COMP_RESET," ==> RxCheckStuck()\n");
4671 //PlatformAcquireSpinLock(Adapter, RT_RX_SPINLOCK);
4672
4673 if(priv->IrpPendingCount > 1)
4674 bRxCheck = TRUE;
4675 //PlatformReleaseSpinLock(Adapter, RT_RX_SPINLOCK);
4676
4677// RT_TRACE(COMP_RESET,"bRxCheck is %d \n",bRxCheck);
4678 if(bRxCheck)
4679 {
4680 if(HalRxCheckStuck819xUsb(dev))
4681 {
4682 RT_TRACE(COMP_RESET, "RxStuck Condition\n");
4683 return RESET_TYPE_SILENT;
4684 }
4685 }
4686 return RESET_TYPE_NORESET;
4687}
4688
4689
4690/**
4691* This function is called by Checkforhang to check whether we should ask OS to reset driver
4692*
4693* \param pAdapter The adapter context for this miniport
4694*
4695* Note:NIC with USB interface sholud not call this function because we cannot scan descriptor
4696* to judge whether there is tx stuck.
4697* Note: This function may be required to be rewrite for Vista OS.
4698* <<<Assumption: Tx spinlock has been acquired >>>
4699*
4700* 8185 and 8185b does not implement this function. This is added by Emily at 2006.11.24
4701*/
4702RESET_TYPE
4703rtl819x_ifcheck_resetornot(struct net_device *dev)
4704{
4705 struct r8192_priv *priv = ieee80211_priv(dev);
4706 RESET_TYPE TxResetType = RESET_TYPE_NORESET;
4707 RESET_TYPE RxResetType = RESET_TYPE_NORESET;
4708 RT_RF_POWER_STATE rfState;
4709
4710 rfState = priv->ieee80211->eRFPowerState;
4711
4712 TxResetType = TxCheckStuck(dev);
4713#if 1
4714 if( rfState != eRfOff ||
4715 /*ADAPTER_TEST_STATUS_FLAG(Adapter, ADAPTER_STATUS_FW_DOWNLOAD_FAILURE)) &&*/
4716 (priv->ieee80211->iw_mode != IW_MODE_ADHOC))
4717 {
4718 // If driver is in the status of firmware download failure , driver skips RF initialization and RF is
4719 // in turned off state. Driver should check whether Rx stuck and do silent reset. And
4720 // if driver is in firmware download failure status, driver should initialize RF in the following
4721 // silent reset procedure Emily, 2008.01.21
4722
4723 // Driver should not check RX stuck in IBSS mode because it is required to
4724 // set Check BSSID in order to send beacon, however, if check BSSID is
4725 // set, STA cannot hear any packet a all. Emily, 2008.04.12
4726 RxResetType = RxCheckStuck(dev);
4727 }
4728#endif
4729 if(TxResetType==RESET_TYPE_NORMAL || RxResetType==RESET_TYPE_NORMAL)
4730 return RESET_TYPE_NORMAL;
4731 else if(TxResetType==RESET_TYPE_SILENT || RxResetType==RESET_TYPE_SILENT){
4732 RT_TRACE(COMP_RESET,"%s():silent reset\n",__FUNCTION__);
4733 return RESET_TYPE_SILENT;
4734 }
4735 else
4736 return RESET_TYPE_NORESET;
4737
4738}
4739
4740void rtl8192_cancel_deferred_work(struct r8192_priv* priv);
4741int _rtl8192_up(struct net_device *dev);
4742int rtl8192_close(struct net_device *dev);
4743
4744
4745
4746void
4747CamRestoreAllEntry( struct net_device *dev)
4748{
4749 u8 EntryId = 0;
4750 struct r8192_priv *priv = ieee80211_priv(dev);
4751 u8* MacAddr = priv->ieee80211->current_network.bssid;
4752
4753 static u8 CAM_CONST_ADDR[4][6] = {
4754 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
4755 {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
4756 {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
4757 {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}};
4758 static u8 CAM_CONST_BROAD[] =
4759 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
4760
4761 RT_TRACE(COMP_SEC, "CamRestoreAllEntry: \n");
4762
4763
4764 if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40)||
4765 (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104))
4766 {
4767
4768 for(EntryId=0; EntryId<4; EntryId++)
4769 {
4770 {
4771 MacAddr = CAM_CONST_ADDR[EntryId];
4772 setKey(dev,
4773 EntryId ,
4774 EntryId,
4775 priv->ieee80211->pairwise_key_type,
4776 MacAddr,
4777 0,
4778 NULL);
4779 }
4780 }
4781
4782 }
4783 else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP)
4784 {
4785
4786 {
4787 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4788 setKey(dev,
4789 4,
4790 0,
4791 priv->ieee80211->pairwise_key_type,
4792 (u8*)dev->dev_addr,
4793 0,
4794 NULL);
4795 else
4796 setKey(dev,
4797 4,
4798 0,
4799 priv->ieee80211->pairwise_key_type,
4800 MacAddr,
4801 0,
4802 NULL);
4803 }
4804 }
4805 else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP)
4806 {
4807
4808 {
4809 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4810 setKey(dev,
4811 4,
4812 0,
4813 priv->ieee80211->pairwise_key_type,
4814 (u8*)dev->dev_addr,
4815 0,
4816 NULL);
4817 else
4818 setKey(dev,
4819 4,
4820 0,
4821 priv->ieee80211->pairwise_key_type,
4822 MacAddr,
4823 0,
4824 NULL);
4825 }
4826 }
4827
4828
4829
4830 if(priv->ieee80211->group_key_type == KEY_TYPE_TKIP)
4831 {
4832 MacAddr = CAM_CONST_BROAD;
4833 for(EntryId=1 ; EntryId<4 ; EntryId++)
4834 {
4835 {
4836 setKey(dev,
4837 EntryId,
4838 EntryId,
4839 priv->ieee80211->group_key_type,
4840 MacAddr,
4841 0,
4842 NULL);
4843 }
4844 }
4845 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4846 setKey(dev,
4847 0,
4848 0,
4849 priv->ieee80211->group_key_type,
4850 CAM_CONST_ADDR[0],
4851 0,
4852 NULL);
4853 }
4854 else if(priv->ieee80211->group_key_type == KEY_TYPE_CCMP)
4855 {
4856 MacAddr = CAM_CONST_BROAD;
4857 for(EntryId=1; EntryId<4 ; EntryId++)
4858 {
4859 {
4860 setKey(dev,
4861 EntryId ,
4862 EntryId,
4863 priv->ieee80211->group_key_type,
4864 MacAddr,
4865 0,
4866 NULL);
4867 }
4868 }
4869
4870 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4871 setKey(dev,
4872 0 ,
4873 0,
4874 priv->ieee80211->group_key_type,
4875 CAM_CONST_ADDR[0],
4876 0,
4877 NULL);
4878 }
4879}
4880//////////////////////////////////////////////////////////////
4881// This function is used to fix Tx/Rx stop bug temporarily.
4882// This function will do "system reset" to NIC when Tx or Rx is stuck.
4883// The method checking Tx/Rx stuck of this function is supported by FW,
4884// which reports Tx and Rx counter to register 0x128 and 0x130.
4885//////////////////////////////////////////////////////////////
4886void
4887rtl819x_ifsilentreset(struct net_device *dev)
4888{
4889 //OCTET_STRING asocpdu;
4890 struct r8192_priv *priv = ieee80211_priv(dev);
4891 u8 reset_times = 0;
4892 int reset_status = 0;
4893 struct ieee80211_device *ieee = priv->ieee80211;
4894
4895
4896 // 2007.07.20. If we need to check CCK stop, please uncomment this line.
4897 //bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter);
4898
4899 if(priv->ResetProgress==RESET_TYPE_NORESET)
4900 {
4901RESET_START:
4902
4903 RT_TRACE(COMP_RESET,"=========>Reset progress!! \n");
4904
4905 // Set the variable for reset.
4906 priv->ResetProgress = RESET_TYPE_SILENT;
4907// rtl8192_close(dev);
4908#if 1
4909 down(&priv->wx_sem);
4910 if(priv->up == 0)
4911 {
4912 RT_TRACE(COMP_ERR,"%s():the driver is not up! return\n",__FUNCTION__);
4913 up(&priv->wx_sem);
4914 return ;
4915 }
4916 priv->up = 0;
4917 RT_TRACE(COMP_RESET,"%s():======>start to down the driver\n",__FUNCTION__);
4918// if(!netif_queue_stopped(dev))
4919// netif_stop_queue(dev);
4920
4921 rtl8192_rtx_disable(dev);
4922 rtl8192_cancel_deferred_work(priv);
4923 deinit_hal_dm(dev);
4924 del_timer_sync(&priv->watch_dog_timer);
4925
4926 ieee->sync_scan_hurryup = 1;
4927 if(ieee->state == IEEE80211_LINKED)
4928 {
4929 down(&ieee->wx_sem);
4930 printk("ieee->state is IEEE80211_LINKED\n");
4931 ieee80211_stop_send_beacons(priv->ieee80211);
4932 del_timer_sync(&ieee->associate_timer);
4933 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
4934 cancel_delayed_work(&ieee->associate_retry_wq);
4935 #endif
4936 ieee80211_stop_scan(ieee);
4937 netif_carrier_off(dev);
4938 up(&ieee->wx_sem);
4939 }
4940 else{
4941 printk("ieee->state is NOT LINKED\n");
4942 ieee80211_softmac_stop_protocol(priv->ieee80211); }
4943 up(&priv->wx_sem);
4944 RT_TRACE(COMP_RESET,"%s():<==========down process is finished\n",__FUNCTION__);
4945 //rtl8192_irq_disable(dev);
4946 RT_TRACE(COMP_RESET,"%s():===========>start to up the driver\n",__FUNCTION__);
4947 reset_status = _rtl8192_up(dev);
4948
4949 RT_TRACE(COMP_RESET,"%s():<===========up process is finished\n",__FUNCTION__);
4950 if(reset_status == -EAGAIN)
4951 {
4952 if(reset_times < 3)
4953 {
4954 reset_times++;
4955 goto RESET_START;
4956 }
4957 else
4958 {
4959 RT_TRACE(COMP_ERR," ERR!!! %s(): Reset Failed!!\n", __FUNCTION__);
4960 }
4961 }
4962#endif
4963 ieee->is_silent_reset = 1;
4964#if 1
4965 EnableHWSecurityConfig8192(dev);
4966#if 1
4967 if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA)
4968 {
4969 ieee->set_chan(ieee->dev, ieee->current_network.channel);
4970
4971#if 1
4972#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
4973 queue_work(ieee->wq, &ieee->associate_complete_wq);
4974#else
4975 schedule_task(&ieee->associate_complete_wq);
4976#endif
4977#endif
4978
4979 }
4980 else if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC)
4981 {
4982 ieee->set_chan(ieee->dev, ieee->current_network.channel);
4983 ieee->link_change(ieee->dev);
4984
4985 // notify_wx_assoc_event(ieee);
4986
4987 ieee80211_start_send_beacons(ieee);
4988
4989 if (ieee->data_hard_resume)
4990 ieee->data_hard_resume(ieee->dev);
4991 netif_carrier_on(ieee->dev);
4992 }
4993#endif
4994
4995 CamRestoreAllEntry(dev);
4996
4997 priv->ResetProgress = RESET_TYPE_NORESET;
4998 priv->reset_count++;
4999
5000 priv->bForcedSilentReset =false;
5001 priv->bResetInProgress = false;
5002
5003 // For test --> force write UFWP.
5004 write_nic_byte(dev, UFWP, 1);
5005 RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", priv->reset_count);
5006#endif
5007 }
5008}
5009
5010void CAM_read_entry(
5011 struct net_device *dev,
5012 u32 iIndex
5013)
5014{
5015 u32 target_command=0;
5016 u32 target_content=0;
5017 u8 entry_i=0;
5018 u32 ulStatus;
5019 s32 i=100;
5020// printk("=======>start read CAM\n");
5021 for(entry_i=0;entry_i<CAM_CONTENT_COUNT;entry_i++)
5022 {
5023 // polling bit, and No Write enable, and address
5024 target_command= entry_i+CAM_CONTENT_COUNT*iIndex;
5025 target_command= target_command | BIT31;
5026
5027 //Check polling bit is clear
5028// mdelay(1);
5029#if 1
5030 while((i--)>=0)
5031 {
5032 ulStatus = read_nic_dword(dev, RWCAM);
5033 if(ulStatus & BIT31){
5034 continue;
5035 }
5036 else{
5037 break;
5038 }
5039 }
5040#endif
5041 write_nic_dword(dev, RWCAM, target_command);
5042 RT_TRACE(COMP_SEC,"CAM_read_entry(): WRITE A0: %x \n",target_command);
5043 // printk("CAM_read_entry(): WRITE A0: %lx \n",target_command);
5044 target_content = read_nic_dword(dev, RCAMO);
5045 RT_TRACE(COMP_SEC, "CAM_read_entry(): WRITE A8: %x \n",target_content);
5046 // printk("CAM_read_entry(): WRITE A8: %lx \n",target_content);
5047 }
5048 printk("\n");
5049}
5050
5051void rtl819x_update_rxcounts(
5052 struct r8192_priv *priv,
5053 u32* TotalRxBcnNum,
5054 u32* TotalRxDataNum
5055)
5056{
5057 u16 SlotIndex;
5058 u8 i;
5059
5060 *TotalRxBcnNum = 0;
5061 *TotalRxDataNum = 0;
5062
5063 SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++)%(priv->ieee80211->LinkDetectInfo.SlotNum);
5064 priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod;
5065 priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod;
5066 for( i=0; i<priv->ieee80211->LinkDetectInfo.SlotNum; i++ ){
5067 *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i];
5068 *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i];
5069 }
5070}
5071
5072
5073#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5074extern void rtl819x_watchdog_wqcallback(struct work_struct *work)
5075{
5076 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
5077 struct r8192_priv *priv = container_of(dwork,struct r8192_priv,watch_dog_wq);
5078 struct net_device *dev = priv->ieee80211->dev;
5079#else
5080extern void rtl819x_watchdog_wqcallback(struct net_device *dev)
5081{
5082 struct r8192_priv *priv = ieee80211_priv(dev);
5083#endif
5084 struct ieee80211_device* ieee = priv->ieee80211;
5085 RESET_TYPE ResetType = RESET_TYPE_NORESET;
5086 static u8 check_reset_cnt=0;
5087 bool bBusyTraffic = false;
5088
5089 if(!priv->up)
5090 return;
5091 hal_dm_watchdog(dev);
5092
5093 {//to get busy traffic condition
5094 if(ieee->state == IEEE80211_LINKED)
5095 {
5096 if( ieee->LinkDetectInfo.NumRxOkInPeriod> 666 ||
5097 ieee->LinkDetectInfo.NumTxOkInPeriod> 666 ) {
5098 bBusyTraffic = true;
5099 }
5100 ieee->LinkDetectInfo.NumRxOkInPeriod = 0;
5101 ieee->LinkDetectInfo.NumTxOkInPeriod = 0;
5102 ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic;
5103 }
5104 }
5105 //added by amy for AP roaming
5106 {
5107 if(priv->ieee80211->state == IEEE80211_LINKED && priv->ieee80211->iw_mode == IW_MODE_INFRA)
5108 {
5109 u32 TotalRxBcnNum = 0;
5110 u32 TotalRxDataNum = 0;
5111
5112 rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
5113 if((TotalRxBcnNum+TotalRxDataNum) == 0)
5114 {
5115 #ifdef TODO
5116 if(rfState == eRfOff)
5117 RT_TRACE(COMP_ERR,"========>%s()\n",__FUNCTION__);
5118 #endif
5119 printk("===>%s(): AP is power off,connect another one\n",__FUNCTION__);
5120 // Dot11d_Reset(dev);
5121 priv->ieee80211->state = IEEE80211_ASSOCIATING;
5122 notify_wx_assoc_event(priv->ieee80211);
5123 RemovePeerTS(priv->ieee80211,priv->ieee80211->current_network.bssid);
5124 priv->ieee80211->link_change(dev);
5125#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
5126 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
5127#else
5128 schedule_task(&priv->ieee80211->associate_procedure_wq);
5129#endif
5130
5131 }
5132 }
5133 priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod=0;
5134 priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod=0;
5135 }
5136// CAM_read_entry(dev,4);
5137 //check if reset the driver
5138 if(check_reset_cnt++ >= 3)
5139 {
5140 ResetType = rtl819x_ifcheck_resetornot(dev);
5141 check_reset_cnt = 3;
5142 //DbgPrint("Start to check silent reset\n");
5143 }
5144 // 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);
5145#if 1
5146 if( (priv->force_reset) || (priv->ResetProgress==RESET_TYPE_NORESET &&
5147 (priv->bForcedSilentReset ||
5148 (!priv->bDisableNormalResetCheck && ResetType==RESET_TYPE_SILENT)))) // This is control by OID set in Pomelo
5149 {
5150 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);
5151 rtl819x_ifsilentreset(dev);
5152 }
5153#endif
5154 priv->force_reset = false;
5155 priv->bForcedSilentReset = false;
5156 priv->bResetInProgress = false;
5157 RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n");
5158
5159}
5160
5161void watch_dog_timer_callback(unsigned long data)
5162{
5163 struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
5164 //printk("===============>watch_dog timer\n");
5165#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
5166 queue_delayed_work(priv->priv_wq,&priv->watch_dog_wq, 0);
5167#else
5168#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
5169 schedule_task(&priv->watch_dog_wq);
5170#else
5171 queue_work(priv->priv_wq,&priv->watch_dog_wq);
5172#endif
5173#endif
5174 mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME));
5175#if 0
5176 priv->watch_dog_timer.expires = jiffies + MSECS(IEEE80211_WATCH_DOG_TIME);
5177 add_timer(&priv->watch_dog_timer);
5178#endif
5179}
5180int _rtl8192_up(struct net_device *dev)
5181{
5182 struct r8192_priv *priv = ieee80211_priv(dev);
5183 //int i;
5184 int init_status = 0;
5185 priv->up=1;
5186 priv->ieee80211->ieee_up=1;
5187 RT_TRACE(COMP_INIT, "Bringing up iface");
5188 init_status = rtl8192_adapter_start(dev);
5189 if(!init_status)
5190 {
5191 RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n", __FUNCTION__);
5192 priv->up=priv->ieee80211->ieee_up = 0;
5193 return -EAGAIN;
5194 }
5195 RT_TRACE(COMP_INIT, "start adapter finished\n");
5196 rtl8192_rx_enable(dev);
5197// rtl8192_tx_enable(dev);
5198 if(priv->ieee80211->state != IEEE80211_LINKED)
5199 ieee80211_softmac_start_protocol(priv->ieee80211);
5200 ieee80211_reset_queue(priv->ieee80211);
5201 watch_dog_timer_callback((unsigned long) dev);
5202 if(!netif_queue_stopped(dev))
5203 netif_start_queue(dev);
5204 else
5205 netif_wake_queue(dev);
5206
5207 return 0;
5208}
5209
5210
5211int rtl8192_open(struct net_device *dev)
5212{
5213 struct r8192_priv *priv = ieee80211_priv(dev);
5214 int ret;
5215 down(&priv->wx_sem);
5216 ret = rtl8192_up(dev);
5217 up(&priv->wx_sem);
5218 return ret;
5219
5220}
5221
5222
5223int rtl8192_up(struct net_device *dev)
5224{
5225 struct r8192_priv *priv = ieee80211_priv(dev);
5226
5227 if (priv->up == 1) return -1;
5228
5229 return _rtl8192_up(dev);
5230}
5231
5232
5233int rtl8192_close(struct net_device *dev)
5234{
5235 struct r8192_priv *priv = ieee80211_priv(dev);
5236 int ret;
5237
5238 down(&priv->wx_sem);
5239
5240 ret = rtl8192_down(dev);
5241
5242 up(&priv->wx_sem);
5243
5244 return ret;
5245
5246}
5247
5248int rtl8192_down(struct net_device *dev)
5249{
5250 struct r8192_priv *priv = ieee80211_priv(dev);
5251 int i;
5252
5253 if (priv->up == 0) return -1;
5254
5255 priv->up=0;
5256 priv->ieee80211->ieee_up = 0;
5257 RT_TRACE(COMP_DOWN, "==========>%s()\n", __FUNCTION__);
5258/* FIXME */
5259 if (!netif_queue_stopped(dev))
5260 netif_stop_queue(dev);
5261
5262 rtl8192_rtx_disable(dev);
5263 //rtl8192_irq_disable(dev);
5264
5265 /* Tx related queue release */
5266 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
5267 skb_queue_purge(&priv->ieee80211->skb_waitQ [i]);
5268 }
5269 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
5270 skb_queue_purge(&priv->ieee80211->skb_aggQ [i]);
5271 }
5272
5273 for(i = 0; i < MAX_QUEUE_SIZE; i++) {
5274 skb_queue_purge(&priv->ieee80211->skb_drv_aggQ [i]);
5275 }
5276
5277 //as cancel_delayed_work will del work->timer, so if work is not definedas struct delayed_work, it will corrupt
5278// flush_scheduled_work();
5279 rtl8192_cancel_deferred_work(priv);
5280 deinit_hal_dm(dev);
5281 del_timer_sync(&priv->watch_dog_timer);
5282
5283
5284 ieee80211_softmac_stop_protocol(priv->ieee80211);
5285 memset(&priv->ieee80211->current_network, 0 , offsetof(struct ieee80211_network, list));
5286 RT_TRACE(COMP_DOWN, "<==========%s()\n", __FUNCTION__);
5287
5288 return 0;
5289}
5290
5291
5292void rtl8192_commit(struct net_device *dev)
5293{
5294 struct r8192_priv *priv = ieee80211_priv(dev);
5295 int reset_status = 0;
5296 //u8 reset_times = 0;
5297 if (priv->up == 0) return ;
5298 priv->up = 0;
5299
5300 rtl8192_cancel_deferred_work(priv);
5301 del_timer_sync(&priv->watch_dog_timer);
5302 //cancel_delayed_work(&priv->SwChnlWorkItem);
5303
5304 ieee80211_softmac_stop_protocol(priv->ieee80211);
5305
5306 //rtl8192_irq_disable(dev);
5307 rtl8192_rtx_disable(dev);
5308 reset_status = _rtl8192_up(dev);
5309
5310}
5311
5312/*
5313void rtl8192_restart(struct net_device *dev)
5314{
5315 struct r8192_priv *priv = ieee80211_priv(dev);
5316*/
5317#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5318void rtl8192_restart(struct work_struct *work)
5319{
5320 struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq);
5321 struct net_device *dev = priv->ieee80211->dev;
5322#else
5323void rtl8192_restart(struct net_device *dev)
5324{
5325
5326 struct r8192_priv *priv = ieee80211_priv(dev);
5327#endif
5328
5329 down(&priv->wx_sem);
5330
5331 rtl8192_commit(dev);
5332
5333 up(&priv->wx_sem);
5334}
5335
5336static void r8192_set_multicast(struct net_device *dev)
5337{
5338 struct r8192_priv *priv = ieee80211_priv(dev);
5339 short promisc;
5340
5341 //down(&priv->wx_sem);
5342
5343 /* FIXME FIXME */
5344
5345 promisc = (dev->flags & IFF_PROMISC) ? 1:0;
5346
5347 if (promisc != priv->promisc)
5348 // rtl8192_commit(dev);
5349
5350 priv->promisc = promisc;
5351
5352 //schedule_work(&priv->reset_wq);
5353 //up(&priv->wx_sem);
5354}
5355
5356
5357int r8192_set_mac_adr(struct net_device *dev, void *mac)
5358{
5359 struct r8192_priv *priv = ieee80211_priv(dev);
5360 struct sockaddr *addr = mac;
5361
5362 down(&priv->wx_sem);
5363
5364 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
5365
5366#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
5367 schedule_work(&priv->reset_wq);
5368#else
5369 schedule_task(&priv->reset_wq);
5370#endif
5371 up(&priv->wx_sem);
5372
5373 return 0;
5374}
5375
5376/* based on ipw2200 driver */
5377int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5378{
5379 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5380 struct iwreq *wrq = (struct iwreq *)rq;
5381 int ret=-1;
5382 struct ieee80211_device *ieee = priv->ieee80211;
5383 u32 key[4];
5384 u8 broadcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
5385 struct iw_point *p = &wrq->u.data;
5386 struct ieee_param *ipw = NULL;//(struct ieee_param *)wrq->u.data.pointer;
5387
5388 down(&priv->wx_sem);
5389
5390
5391 if (p->length < sizeof(struct ieee_param) || !p->pointer){
5392 ret = -EINVAL;
5393 goto out;
5394 }
5395
5396 ipw = (struct ieee_param *)kmalloc(p->length, GFP_KERNEL);
5397 if (ipw == NULL){
5398 ret = -ENOMEM;
5399 goto out;
5400 }
5401 if (copy_from_user(ipw, p->pointer, p->length)) {
5402 kfree(ipw);
5403 ret = -EFAULT;
5404 goto out;
5405 }
5406
5407 switch (cmd) {
5408 case RTL_IOCTL_WPA_SUPPLICANT:
5409 //parse here for HW security
5410 if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION)
5411 {
5412 if (ipw->u.crypt.set_tx)
5413 {
5414 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
5415 ieee->pairwise_key_type = KEY_TYPE_CCMP;
5416 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
5417 ieee->pairwise_key_type = KEY_TYPE_TKIP;
5418 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
5419 {
5420 if (ipw->u.crypt.key_len == 13)
5421 ieee->pairwise_key_type = KEY_TYPE_WEP104;
5422 else if (ipw->u.crypt.key_len == 5)
5423 ieee->pairwise_key_type = KEY_TYPE_WEP40;
5424 }
5425 else
5426 ieee->pairwise_key_type = KEY_TYPE_NA;
5427
5428 if (ieee->pairwise_key_type)
5429 {
5430 memcpy((u8*)key, ipw->u.crypt.key, 16);
5431 EnableHWSecurityConfig8192(dev);
5432 //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!
5433 //added by WB.
5434 setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
5435 if (ieee->auth_mode != 2)
5436 setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
5437 }
5438 }
5439 else //if (ipw->u.crypt.idx) //group key use idx > 0
5440 {
5441 memcpy((u8*)key, ipw->u.crypt.key, 16);
5442 if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
5443 ieee->group_key_type= KEY_TYPE_CCMP;
5444 else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
5445 ieee->group_key_type = KEY_TYPE_TKIP;
5446 else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
5447 {
5448 if (ipw->u.crypt.key_len == 13)
5449 ieee->group_key_type = KEY_TYPE_WEP104;
5450 else if (ipw->u.crypt.key_len == 5)
5451 ieee->group_key_type = KEY_TYPE_WEP40;
5452 }
5453 else
5454 ieee->group_key_type = KEY_TYPE_NA;
5455
5456 if (ieee->group_key_type)
5457 {
5458 setKey( dev,
5459 ipw->u.crypt.idx,
5460 ipw->u.crypt.idx, //KeyIndex
5461 ieee->group_key_type, //KeyType
5462 broadcast_addr, //MacAddr
5463 0, //DefaultKey
5464 key); //KeyContent
5465 }
5466 }
5467 }
5468#ifdef JOHN_HWSEC_DEBUG
5469 //john's test 0711
5470 printk("@@ wrq->u pointer = ");
5471 for(i=0;i<wrq->u.data.length;i++){
5472 if(i%10==0) printk("\n");
5473 printk( "%8x|", ((u32*)wrq->u.data.pointer)[i] );
5474 }
5475 printk("\n");
5476#endif /*JOHN_HWSEC_DEBUG*/
5477 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
5478 break;
5479
5480 default:
5481 ret = -EOPNOTSUPP;
5482 break;
5483 }
5484 kfree(ipw);
5485 ipw = NULL;
5486out:
5487 up(&priv->wx_sem);
5488 return ret;
5489}
5490
5491u8 HwRateToMRate90(bool bIsHT, u8 rate)
5492{
5493 u8 ret_rate = 0xff;
5494
5495 if(!bIsHT) {
5496 switch(rate) {
5497 case DESC90_RATE1M: ret_rate = MGN_1M; break;
5498 case DESC90_RATE2M: ret_rate = MGN_2M; break;
5499 case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break;
5500 case DESC90_RATE11M: ret_rate = MGN_11M; break;
5501 case DESC90_RATE6M: ret_rate = MGN_6M; break;
5502 case DESC90_RATE9M: ret_rate = MGN_9M; break;
5503 case DESC90_RATE12M: ret_rate = MGN_12M; break;
5504 case DESC90_RATE18M: ret_rate = MGN_18M; break;
5505 case DESC90_RATE24M: ret_rate = MGN_24M; break;
5506 case DESC90_RATE36M: ret_rate = MGN_36M; break;
5507 case DESC90_RATE48M: ret_rate = MGN_48M; break;
5508 case DESC90_RATE54M: ret_rate = MGN_54M; break;
5509
5510 default:
5511 ret_rate = 0xff;
5512 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT);
5513 break;
5514 }
5515
5516 } else {
5517 switch(rate) {
5518 case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break;
5519 case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break;
5520 case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break;
5521 case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break;
5522 case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break;
5523 case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break;
5524 case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break;
5525 case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break;
5526 case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break;
5527 case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break;
5528 case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break;
5529 case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break;
5530 case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break;
5531 case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break;
5532 case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break;
5533 case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break;
5534 case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break;
5535
5536 default:
5537 ret_rate = 0xff;
5538 RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT);
5539 break;
5540 }
5541 }
5542
5543 return ret_rate;
5544}
5545
5546/**
5547 * Function: UpdateRxPktTimeStamp
5548 * Overview: Recored down the TSF time stamp when receiving a packet
5549 *
5550 * Input:
5551 * PADAPTER Adapter
5552 * PRT_RFD pRfd,
5553 *
5554 * Output:
5555 * PRT_RFD pRfd
5556 * (pRfd->Status.TimeStampHigh is updated)
5557 * (pRfd->Status.TimeStampLow is updated)
5558 * Return:
5559 * None
5560 */
5561void UpdateRxPktTimeStamp8190 (struct net_device *dev, struct ieee80211_rx_stats *stats)
5562{
5563 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
5564
5565 if(stats->bIsAMPDU && !stats->bFirstMPDU) {
5566 stats->mac_time[0] = priv->LastRxDescTSFLow;
5567 stats->mac_time[1] = priv->LastRxDescTSFHigh;
5568 } else {
5569 priv->LastRxDescTSFLow = stats->mac_time[0];
5570 priv->LastRxDescTSFHigh = stats->mac_time[1];
5571 }
5572}
5573
5574//by amy 080606
5575
5576long rtl819x_translate_todbm(u8 signal_strength_index )// 0-100 index.
5577{
5578 long signal_power; // in dBm.
5579
5580 // Translate to dBm (x=0.5y-95).
5581 signal_power = (long)((signal_strength_index + 1) >> 1);
5582 signal_power -= 95;
5583
5584 return signal_power;
5585}
5586
5587
5588/* 2008/01/22 MH We can not delcare RSSI/EVM total value of sliding window to
5589 be a local static. Otherwise, it may increase when we return from S3/S4. The
5590 value will be kept in memory or disk. We must delcare the value in adapter
5591 and it will be reinitialized when return from S3/S4. */
5592void rtl8192_process_phyinfo(struct r8192_priv * priv,u8* buffer, struct ieee80211_rx_stats * pprevious_stats, struct ieee80211_rx_stats * pcurrent_stats)
5593{
5594 bool bcheck = false;
5595 u8 rfpath;
5596 u32 nspatial_stream, tmp_val;
5597 //u8 i;
5598 static u32 slide_rssi_index=0, slide_rssi_statistics=0;
5599 static u32 slide_evm_index=0, slide_evm_statistics=0;
5600 static u32 last_rssi=0, last_evm=0;
5601
5602 static u32 slide_beacon_adc_pwdb_index=0, slide_beacon_adc_pwdb_statistics=0;
5603 static u32 last_beacon_adc_pwdb=0;
5604
5605 struct ieee80211_hdr_3addr *hdr;
5606 u16 sc ;
5607 unsigned int frag,seq;
5608 hdr = (struct ieee80211_hdr_3addr *)buffer;
5609 sc = le16_to_cpu(hdr->seq_ctl);
5610 frag = WLAN_GET_SEQ_FRAG(sc);
5611 seq = WLAN_GET_SEQ_SEQ(sc);
5612 //cosa add 04292008 to record the sequence number
5613 pcurrent_stats->Seq_Num = seq;
5614 //
5615 // Check whether we should take the previous packet into accounting
5616 //
5617 if(!pprevious_stats->bIsAMPDU)
5618 {
5619 // if previous packet is not aggregated packet
5620 bcheck = true;
5621 }else
5622 {
5623 #if 0
5624 // if previous packet is aggregated packet, and current packet
5625 // (1) is not AMPDU
5626 // (2) is the first packet of one AMPDU
5627 // that means the previous packet is the last one aggregated packet
5628 if( !pcurrent_stats->bIsAMPDU || pcurrent_stats->bFirstMPDU)
5629 bcheck = true;
5630 #endif
5631 }
5632
5633
5634 if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX)
5635 {
5636 slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX;
5637 last_rssi = priv->stats.slide_signal_strength[slide_rssi_index];
5638 priv->stats.slide_rssi_total -= last_rssi;
5639 }
5640 priv->stats.slide_rssi_total += pprevious_stats->SignalStrength;
5641
5642 priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength;
5643 if(slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX)
5644 slide_rssi_index = 0;
5645
5646 // <1> Showed on UI for user, in dbm
5647 tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics;
5648 priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val);
5649 pcurrent_stats->rssi = priv->stats.signal_strength;
5650 //
5651 // If the previous packet does not match the criteria, neglect it
5652 //
5653 if(!pprevious_stats->bPacketMatchBSSID)
5654 {
5655 if(!pprevious_stats->bToSelfBA)
5656 return;
5657 }
5658
5659 if(!bcheck)
5660 return;
5661
5662
5663 //rtl8190_process_cck_rxpathsel(priv,pprevious_stats);//only rtl8190 supported
5664
5665 //
5666 // Check RSSI
5667 //
5668 priv->stats.num_process_phyinfo++;
5669
5670 /* record the general signal strength to the sliding window. */
5671
5672
5673 // <2> Showed on UI for engineering
5674 // hardware does not provide rssi information for each rf path in CCK
5675 if(!pprevious_stats->bIsCCK && (pprevious_stats->bPacketToSelf || pprevious_stats->bToSelfBA))
5676 {
5677 for (rfpath = RF90_PATH_A; rfpath < priv->NumTotalRFPath; rfpath++)
5678 {
5679 if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath))
5680 continue;
5681
5682 //Fixed by Jacken 2008-03-20
5683 if(priv->stats.rx_rssi_percentage[rfpath] == 0)
5684 {
5685 priv->stats.rx_rssi_percentage[rfpath] = pprevious_stats->RxMIMOSignalStrength[rfpath];
5686 //DbgPrint("MIMO RSSI initialize \n");
5687 }
5688 if(pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath])
5689 {
5690 priv->stats.rx_rssi_percentage[rfpath] =
5691 ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
5692 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
5693 priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1;
5694 }
5695 else
5696 {
5697 priv->stats.rx_rssi_percentage[rfpath] =
5698 ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
5699 (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
5700 }
5701 RT_TRACE(COMP_DBG,"priv->stats.rx_rssi_percentage[rfPath] = %d \n" ,priv->stats.rx_rssi_percentage[rfpath] );
5702 }
5703 }
5704
5705
5706 //
5707 // Check PWDB.
5708 //
5709 RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
5710 pprevious_stats->bIsCCK? "CCK": "OFDM",
5711 pprevious_stats->RxPWDBAll);
5712
5713 if(pprevious_stats->bPacketBeacon)
5714 {
5715/* record the beacon pwdb to the sliding window. */
5716 if(slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX)
5717 {
5718 slide_beacon_adc_pwdb_statistics = PHY_Beacon_RSSI_SLID_WIN_MAX;
5719 last_beacon_adc_pwdb = priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index];
5720 priv->stats.Slide_Beacon_Total -= last_beacon_adc_pwdb;
5721 //DbgPrint("slide_beacon_adc_pwdb_index = %d, last_beacon_adc_pwdb = %d, Adapter->RxStats.Slide_Beacon_Total = %d\n",
5722 // slide_beacon_adc_pwdb_index, last_beacon_adc_pwdb, Adapter->RxStats.Slide_Beacon_Total);
5723 }
5724 priv->stats.Slide_Beacon_Total += pprevious_stats->RxPWDBAll;
5725 priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index] = pprevious_stats->RxPWDBAll;
5726 //DbgPrint("slide_beacon_adc_pwdb_index = %d, pPreviousRfd->Status.RxPWDBAll = %d\n", slide_beacon_adc_pwdb_index, pPreviousRfd->Status.RxPWDBAll);
5727 slide_beacon_adc_pwdb_index++;
5728 if(slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX)
5729 slide_beacon_adc_pwdb_index = 0;
5730 pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total/slide_beacon_adc_pwdb_statistics;
5731 if(pprevious_stats->RxPWDBAll >= 3)
5732 pprevious_stats->RxPWDBAll -= 3;
5733 }
5734
5735 RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n",
5736 pprevious_stats->bIsCCK? "CCK": "OFDM",
5737 pprevious_stats->RxPWDBAll);
5738
5739
5740 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
5741 {
5742 if(priv->undecorated_smoothed_pwdb < 0) // initialize
5743 {
5744 priv->undecorated_smoothed_pwdb = pprevious_stats->RxPWDBAll;
5745 //DbgPrint("First pwdb initialize \n");
5746 }
5747#if 1
5748 if(pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb)
5749 {
5750 priv->undecorated_smoothed_pwdb =
5751 ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
5752 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
5753 priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1;
5754 }
5755 else
5756 {
5757 priv->undecorated_smoothed_pwdb =
5758 ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) +
5759 (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor);
5760 }
5761#else
5762 //Fixed by Jacken 2008-03-20
5763 if(pPreviousRfd->Status.RxPWDBAll > (u32)pHalData->UndecoratedSmoothedPWDB)
5764 {
5765 pHalData->UndecoratedSmoothedPWDB =
5766 ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6;
5767 pHalData->UndecoratedSmoothedPWDB = pHalData->UndecoratedSmoothedPWDB + 1;
5768 }
5769 else
5770 {
5771 pHalData->UndecoratedSmoothedPWDB =
5772 ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6;
5773 }
5774#endif
5775
5776 }
5777
5778 //
5779 // Check EVM
5780 //
5781 /* record the general EVM to the sliding window. */
5782 if(pprevious_stats->SignalQuality == 0)
5783 {
5784 }
5785 else
5786 {
5787 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA){
5788 if(slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX){
5789 slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX;
5790 last_evm = priv->stats.slide_evm[slide_evm_index];
5791 priv->stats.slide_evm_total -= last_evm;
5792 }
5793
5794 priv->stats.slide_evm_total += pprevious_stats->SignalQuality;
5795
5796 priv->stats.slide_evm[slide_evm_index++] = pprevious_stats->SignalQuality;
5797 if(slide_evm_index >= PHY_RSSI_SLID_WIN_MAX)
5798 slide_evm_index = 0;
5799
5800 // <1> Showed on UI for user, in percentage.
5801 tmp_val = priv->stats.slide_evm_total/slide_evm_statistics;
5802 priv->stats.signal_quality = tmp_val;
5803 //cosa add 10/11/2007, Showed on UI for user in Windows Vista, for Link quality.
5804 priv->stats.last_signal_strength_inpercent = tmp_val;
5805 }
5806
5807 // <2> Showed on UI for engineering
5808 if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA)
5809 {
5810 for(nspatial_stream = 0; nspatial_stream<2 ; nspatial_stream++) // 2 spatial stream
5811 {
5812 if(pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1)
5813 {
5814 if(priv->stats.rx_evm_percentage[nspatial_stream] == 0) // initialize
5815 {
5816 priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream];
5817 }
5818 priv->stats.rx_evm_percentage[nspatial_stream] =
5819 ( (priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) +
5820 (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor);
5821 }
5822 }
5823 }
5824 }
5825
5826
5827}
5828
5829/*-----------------------------------------------------------------------------
5830 * Function: rtl819x_query_rxpwrpercentage()
5831 *
5832 * Overview:
5833 *
5834 * Input: char antpower
5835 *
5836 * Output: NONE
5837 *
5838 * Return: 0-100 percentage
5839 *
5840 * Revised History:
5841 * When Who Remark
5842 * 05/26/2008 amy Create Version 0 porting from windows code.
5843 *
5844 *---------------------------------------------------------------------------*/
5845static u8 rtl819x_query_rxpwrpercentage(
5846 char antpower
5847 )
5848{
5849 if ((antpower <= -100) || (antpower >= 20))
5850 {
5851 return 0;
5852 }
5853 else if (antpower >= 0)
5854 {
5855 return 100;
5856 }
5857 else
5858 {
5859 return (100+antpower);
5860 }
5861
5862} /* QueryRxPwrPercentage */
5863
5864static u8
5865rtl819x_evm_dbtopercentage(
5866 char value
5867 )
5868{
5869 char ret_val;
5870
5871 ret_val = value;
5872
5873 if(ret_val >= 0)
5874 ret_val = 0;
5875 if(ret_val <= -33)
5876 ret_val = -33;
5877 ret_val = 0 - ret_val;
5878 ret_val*=3;
5879 if(ret_val == 99)
5880 ret_val = 100;
5881 return(ret_val);
5882}
5883//
5884// Description:
5885// We want good-looking for signal strength/quality
5886// 2007/7/19 01:09, by cosa.
5887//
5888long
5889rtl819x_signal_scale_mapping(
5890 long currsig
5891 )
5892{
5893 long retsig;
5894
5895 // Step 1. Scale mapping.
5896 if(currsig >= 61 && currsig <= 100)
5897 {
5898 retsig = 90 + ((currsig - 60) / 4);
5899 }
5900 else if(currsig >= 41 && currsig <= 60)
5901 {
5902 retsig = 78 + ((currsig - 40) / 2);
5903 }
5904 else if(currsig >= 31 && currsig <= 40)
5905 {
5906 retsig = 66 + (currsig - 30);
5907 }
5908 else if(currsig >= 21 && currsig <= 30)
5909 {
5910 retsig = 54 + (currsig - 20);
5911 }
5912 else if(currsig >= 5 && currsig <= 20)
5913 {
5914 retsig = 42 + (((currsig - 5) * 2) / 3);
5915 }
5916 else if(currsig == 4)
5917 {
5918 retsig = 36;
5919 }
5920 else if(currsig == 3)
5921 {
5922 retsig = 27;
5923 }
5924 else if(currsig == 2)
5925 {
5926 retsig = 18;
5927 }
5928 else if(currsig == 1)
5929 {
5930 retsig = 9;
5931 }
5932 else
5933 {
5934 retsig = currsig;
5935 }
5936
5937 return retsig;
5938}
5939
5940static void rtl8192_query_rxphystatus(
5941 struct r8192_priv * priv,
5942 struct ieee80211_rx_stats * pstats,
5943 rx_drvinfo_819x_usb * pdrvinfo,
5944 struct ieee80211_rx_stats * precord_stats,
5945 bool bpacket_match_bssid,
5946 bool bpacket_toself,
5947 bool bPacketBeacon,
5948 bool bToSelfBA
5949 )
5950{
5951 //PRT_RFD_STATUS pRtRfdStatus = &(pRfd->Status);
5952 phy_sts_ofdm_819xusb_t* pofdm_buf;
5953 phy_sts_cck_819xusb_t * pcck_buf;
5954 phy_ofdm_rx_status_rxsc_sgien_exintfflag* prxsc;
5955 u8 *prxpkt;
5956 u8 i, max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg;
5957 char rx_pwr[4], rx_pwr_all=0;
5958 //long rx_avg_pwr = 0;
5959 char rx_snrX, rx_evmX;
5960 u8 evm, pwdb_all;
5961 u32 RSSI, total_rssi=0;//, total_evm=0;
5962// long signal_strength_index = 0;
5963 u8 is_cck_rate=0;
5964 u8 rf_rx_num = 0;
5965
5966
5967 priv->stats.numqry_phystatus++;
5968
5969 is_cck_rate = rx_hal_is_cck_rate(pdrvinfo);
5970
5971 // Record it for next packet processing
5972 memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats));
5973 pstats->bPacketMatchBSSID = precord_stats->bPacketMatchBSSID = bpacket_match_bssid;
5974 pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself;
5975 pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;//RX_HAL_IS_CCK_RATE(pDrvInfo);
5976 pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon;
5977 pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA;
5978
5979 prxpkt = (u8*)pdrvinfo;
5980
5981 /* Move pointer to the 16th bytes. Phy status start address. */
5982 prxpkt += sizeof(rx_drvinfo_819x_usb);
5983
5984 /* Initial the cck and ofdm buffer pointer */
5985 pcck_buf = (phy_sts_cck_819xusb_t *)prxpkt;
5986 pofdm_buf = (phy_sts_ofdm_819xusb_t *)prxpkt;
5987
5988 pstats->RxMIMOSignalQuality[0] = -1;
5989 pstats->RxMIMOSignalQuality[1] = -1;
5990 precord_stats->RxMIMOSignalQuality[0] = -1;
5991 precord_stats->RxMIMOSignalQuality[1] = -1;
5992
5993 if(is_cck_rate)
5994 {
5995 //
5996 // (1)Hardware does not provide RSSI for CCK
5997 //
5998
5999 //
6000 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
6001 //
6002 u8 report;//, cck_agc_rpt;
6003
6004 priv->stats.numqry_phystatusCCK++;
6005
6006 if(!priv->bCckHighPower)
6007 {
6008 report = pcck_buf->cck_agc_rpt & 0xc0;
6009 report = report>>6;
6010 switch(report)
6011 {
6012 //Fixed by Jacken from Bryant 2008-03-20
6013 //Original value is -38 , -26 , -14 , -2
6014 //Fixed value is -35 , -23 , -11 , 6
6015 case 0x3:
6016 rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e);
6017 break;
6018 case 0x2:
6019 rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e);
6020 break;
6021 case 0x1:
6022 rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e);
6023 break;
6024 case 0x0:
6025 rx_pwr_all = 6 - (pcck_buf->cck_agc_rpt & 0x3e);
6026 break;
6027 }
6028 }
6029 else
6030 {
6031 report = pcck_buf->cck_agc_rpt & 0x60;
6032 report = report>>5;
6033 switch(report)
6034 {
6035 case 0x3:
6036 rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
6037 break;
6038 case 0x2:
6039 rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1);
6040 break;
6041 case 0x1:
6042 rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
6043 break;
6044 case 0x0:
6045 rx_pwr_all = 6 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ;
6046 break;
6047 }
6048 }
6049
6050 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
6051 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
6052 pstats->RecvSignalPower = pwdb_all;
6053
6054 //
6055 // (3) Get Signal Quality (EVM)
6056 //
6057 //if(bpacket_match_bssid)
6058 {
6059 u8 sq;
6060
6061 if(pstats->RxPWDBAll > 40)
6062 {
6063 sq = 100;
6064 }else
6065 {
6066 sq = pcck_buf->sq_rpt;
6067
6068 if(pcck_buf->sq_rpt > 64)
6069 sq = 0;
6070 else if (pcck_buf->sq_rpt < 20)
6071 sq = 100;
6072 else
6073 sq = ((64-sq) * 100) / 44;
6074 }
6075 pstats->SignalQuality = precord_stats->SignalQuality = sq;
6076 pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq;
6077 pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1;
6078 }
6079 }
6080 else
6081 {
6082 priv->stats.numqry_phystatusHT++;
6083 //
6084 // (1)Get RSSI for HT rate
6085 //
6086 for(i=RF90_PATH_A; i<priv->NumTotalRFPath; i++)
6087 {
6088 // 2008/01/30 MH we will judge RF RX path now.
6089 if (priv->brfpath_rxenable[i])
6090 rf_rx_num++;
6091 else
6092 continue;
6093
6094 if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, i))
6095 continue;
6096
6097 //Fixed by Jacken from Bryant 2008-03-20
6098 //Original value is 106
6099 rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 106;
6100
6101 //Get Rx snr value in DB
6102 tmp_rxsnr = pofdm_buf->rxsnr_X[i];
6103 rx_snrX = (char)(tmp_rxsnr);
6104 //rx_snrX >>= 1;;
6105 rx_snrX /= 2;
6106 priv->stats.rxSNRdB[i] = (long)rx_snrX;
6107
6108 /* Translate DBM to percentage. */
6109 RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]);
6110 total_rssi += RSSI;
6111
6112 /* Record Signal Strength for next packet */
6113 //if(bpacket_match_bssid)
6114 {
6115 pstats->RxMIMOSignalStrength[i] =(u8) RSSI;
6116 precord_stats->RxMIMOSignalStrength[i] =(u8) RSSI;
6117 }
6118 }
6119
6120
6121 //
6122 // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive)
6123 //
6124 //Fixed by Jacken from Bryant 2008-03-20
6125 //Original value is 106
6126 rx_pwr_all = (((pofdm_buf->pwdb_all ) >> 1 )& 0x7f) -106;
6127 pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all);
6128
6129 pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all;
6130 pstats->RxPower = precord_stats->RxPower = rx_pwr_all;
6131
6132 //
6133 // (3)EVM of HT rate
6134 //
6135 if(pdrvinfo->RxHT && pdrvinfo->RxRate>=DESC90_RATEMCS8 &&
6136 pdrvinfo->RxRate<=DESC90_RATEMCS15)
6137 max_spatial_stream = 2; //both spatial stream make sense
6138 else
6139 max_spatial_stream = 1; //only spatial stream 1 makes sense
6140
6141 for(i=0; i<max_spatial_stream; i++)
6142 {
6143 tmp_rxevm = pofdm_buf->rxevm_X[i];
6144 rx_evmX = (char)(tmp_rxevm);
6145
6146 // Do not use shift operation like "rx_evmX >>= 1" because the compilor of free build environment
6147 // fill most significant bit to "zero" when doing shifting operation which may change a negative
6148 // value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore.
6149 rx_evmX /= 2; //dbm
6150
6151 evm = rtl819x_evm_dbtopercentage(rx_evmX);
6152#if 0
6153 EVM = SignalScaleMapping(EVM);//make it good looking, from 0~100
6154#endif
6155 //if(bpacket_match_bssid)
6156 {
6157 if(i==0) // Fill value in RFD, Get the first spatial stream only
6158 pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff);
6159 pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff);
6160 }
6161 }
6162
6163
6164 /* record rx statistics for debug */
6165 rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg;
6166 prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)&rxsc_sgien_exflg;
6167 if(pdrvinfo->BW) //40M channel
6168 priv->stats.received_bwtype[1+prxsc->rxsc]++;
6169 else //20M channel
6170 priv->stats.received_bwtype[0]++;
6171 }
6172
6173 //UI BSS List signal strength(in percentage), make it good looking, from 0~100.
6174 //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp().
6175 if(is_cck_rate)
6176 {
6177 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));//PWDB_ALL;
6178
6179 }
6180 else
6181 {
6182 //pRfd->Status.SignalStrength = pRecordRfd->Status.SignalStrength = (u8)(SignalScaleMapping(total_rssi/=RF90_PATH_MAX));//(u8)(total_rssi/=RF90_PATH_MAX);
6183 // We can judge RX path number now.
6184 if (rf_rx_num != 0)
6185 pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi/=rf_rx_num)));
6186 }
6187} /* QueryRxPhyStatus8190Pci */
6188
6189void
6190rtl8192_record_rxdesc_forlateruse(
6191 struct ieee80211_rx_stats * psrc_stats,
6192 struct ieee80211_rx_stats * ptarget_stats
6193)
6194{
6195 ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
6196 ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
6197 ptarget_stats->Seq_Num = psrc_stats->Seq_Num;
6198}
6199
6200
6201void TranslateRxSignalStuff819xUsb(struct sk_buff *skb,
6202 struct ieee80211_rx_stats * pstats,
6203 rx_drvinfo_819x_usb *pdrvinfo)
6204{
6205 // TODO: We must only check packet for current MAC address. Not finish
6206 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
6207 struct net_device *dev=info->dev;
6208 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6209 bool bpacket_match_bssid, bpacket_toself;
6210 bool bPacketBeacon=FALSE, bToSelfBA=FALSE;
6211 static struct ieee80211_rx_stats previous_stats;
6212 struct ieee80211_hdr_3addr *hdr;//by amy
6213 u16 fc,type;
6214
6215 // Get Signal Quality for only RX data queue (but not command queue)
6216
6217 u8* tmp_buf;
6218 //u16 tmp_buf_len = 0;
6219 u8 *praddr;
6220
6221 /* Get MAC frame start address. */
6222 tmp_buf = (u8*)skb->data;// + get_rxpacket_shiftbytes_819xusb(pstats);
6223
6224 hdr = (struct ieee80211_hdr_3addr *)tmp_buf;
6225 fc = le16_to_cpu(hdr->frame_ctl);
6226 type = WLAN_FC_GET_TYPE(fc);
6227 praddr = hdr->addr1;
6228
6229 /* Check if the received packet is acceptabe. */
6230 bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) &&
6231 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3))
6232 && (!pstats->bHwError) && (!pstats->bCRC)&& (!pstats->bICV));
6233 bpacket_toself = bpacket_match_bssid & (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr));
6234
6235#if 1//cosa
6236 if(WLAN_FC_GET_FRAMETYPE(fc)== IEEE80211_STYPE_BEACON)
6237 {
6238 bPacketBeacon = true;
6239 //DbgPrint("Beacon 2, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf);
6240 }
6241 if(WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK)
6242 {
6243 if((eqMacAddr(praddr,dev->dev_addr)))
6244 bToSelfBA = true;
6245 //DbgPrint("BlockAck, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf);
6246 }
6247
6248#endif
6249
6250
6251 if(bpacket_match_bssid)
6252 {
6253 priv->stats.numpacket_matchbssid++;
6254 }
6255 if(bpacket_toself){
6256 priv->stats.numpacket_toself++;
6257 }
6258 //
6259 // Process PHY information for previous packet (RSSI/PWDB/EVM)
6260 //
6261 // Because phy information is contained in the last packet of AMPDU only, so driver
6262 // should process phy information of previous packet
6263 rtl8192_process_phyinfo(priv, tmp_buf, &previous_stats, pstats);
6264 rtl8192_query_rxphystatus(priv, pstats, pdrvinfo, &previous_stats, bpacket_match_bssid,bpacket_toself,bPacketBeacon,bToSelfBA);
6265 rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats);
6266
6267}
6268
6269/**
6270* Function: UpdateReceivedRateHistogramStatistics
6271* Overview: Recored down the received data rate
6272*
6273* Input:
6274* struct net_device *dev
6275* struct ieee80211_rx_stats *stats
6276*
6277* Output:
6278*
6279* (priv->stats.ReceivedRateHistogram[] is updated)
6280* Return:
6281* None
6282*/
6283void
6284UpdateReceivedRateHistogramStatistics8190(
6285 struct net_device *dev,
6286 struct ieee80211_rx_stats *stats
6287 )
6288{
6289 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6290 u32 rcvType=1; //0: Total, 1:OK, 2:CRC, 3:ICV
6291 u32 rateIndex;
6292 u32 preamble_guardinterval; //1: short preamble/GI, 0: long preamble/GI
6293
6294
6295 if(stats->bCRC)
6296 rcvType = 2;
6297 else if(stats->bICV)
6298 rcvType = 3;
6299
6300 if(stats->bShortPreamble)
6301 preamble_guardinterval = 1;// short
6302 else
6303 preamble_guardinterval = 0;// long
6304
6305 switch(stats->rate)
6306 {
6307 //
6308 // CCK rate
6309 //
6310 case MGN_1M: rateIndex = 0; break;
6311 case MGN_2M: rateIndex = 1; break;
6312 case MGN_5_5M: rateIndex = 2; break;
6313 case MGN_11M: rateIndex = 3; break;
6314 //
6315 // Legacy OFDM rate
6316 //
6317 case MGN_6M: rateIndex = 4; break;
6318 case MGN_9M: rateIndex = 5; break;
6319 case MGN_12M: rateIndex = 6; break;
6320 case MGN_18M: rateIndex = 7; break;
6321 case MGN_24M: rateIndex = 8; break;
6322 case MGN_36M: rateIndex = 9; break;
6323 case MGN_48M: rateIndex = 10; break;
6324 case MGN_54M: rateIndex = 11; break;
6325 //
6326 // 11n High throughput rate
6327 //
6328 case MGN_MCS0: rateIndex = 12; break;
6329 case MGN_MCS1: rateIndex = 13; break;
6330 case MGN_MCS2: rateIndex = 14; break;
6331 case MGN_MCS3: rateIndex = 15; break;
6332 case MGN_MCS4: rateIndex = 16; break;
6333 case MGN_MCS5: rateIndex = 17; break;
6334 case MGN_MCS6: rateIndex = 18; break;
6335 case MGN_MCS7: rateIndex = 19; break;
6336 case MGN_MCS8: rateIndex = 20; break;
6337 case MGN_MCS9: rateIndex = 21; break;
6338 case MGN_MCS10: rateIndex = 22; break;
6339 case MGN_MCS11: rateIndex = 23; break;
6340 case MGN_MCS12: rateIndex = 24; break;
6341 case MGN_MCS13: rateIndex = 25; break;
6342 case MGN_MCS14: rateIndex = 26; break;
6343 case MGN_MCS15: rateIndex = 27; break;
6344 default: rateIndex = 28; break;
6345 }
6346 priv->stats.received_preamble_GI[preamble_guardinterval][rateIndex]++;
6347 priv->stats.received_rate_histogram[0][rateIndex]++; //total
6348 priv->stats.received_rate_histogram[rcvType][rateIndex]++;
6349}
6350
6351
6352void query_rxdesc_status(struct sk_buff *skb, struct ieee80211_rx_stats *stats, bool bIsRxAggrSubframe)
6353{
6354 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
6355 struct net_device *dev=info->dev;
6356 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6357 //rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
6358 rx_drvinfo_819x_usb *driver_info = NULL;
6359
6360 //
6361 //Get Rx Descriptor Information
6362 //
6363#ifdef USB_RX_AGGREGATION_SUPPORT
6364 if (bIsRxAggrSubframe)
6365 {
6366 rx_desc_819x_usb_aggr_subframe *desc = (rx_desc_819x_usb_aggr_subframe *)skb->data;
6367 stats->Length = desc->Length ;
6368 stats->RxDrvInfoSize = desc->RxDrvInfoSize;
6369 stats->RxBufShift = 0; //RxBufShift = 2 in RxDesc, but usb didn't shift bytes in fact.
6370 stats->bICV = desc->ICV;
6371 stats->bCRC = desc->CRC32;
6372 stats->bHwError = stats->bCRC|stats->bICV;
6373 stats->Decrypted = !desc->SWDec;//RTL8190 set this bit to indicate that Hw does not decrypt packet
6374 } else
6375#endif
6376 {
6377 rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
6378
6379 stats->Length = desc->Length;
6380 stats->RxDrvInfoSize = desc->RxDrvInfoSize;
6381 stats->RxBufShift = 0;//desc->Shift&0x03;
6382 stats->bICV = desc->ICV;
6383 stats->bCRC = desc->CRC32;
6384 stats->bHwError = stats->bCRC|stats->bICV;
6385 //RTL8190 set this bit to indicate that Hw does not decrypt packet
6386 stats->Decrypted = !desc->SWDec;
6387 }
6388
6389 if((priv->ieee80211->pHTInfo->bCurrentHTSupport == true) && (priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP))
6390 {
6391 stats->bHwError = false;
6392 }
6393 else
6394 {
6395 stats->bHwError = stats->bCRC|stats->bICV;
6396 }
6397
6398 if(stats->Length < 24 || stats->Length > MAX_8192U_RX_SIZE)
6399 stats->bHwError |= 1;
6400 //
6401 //Get Driver Info
6402 //
6403 // TODO: Need to verify it on FGPA platform
6404 //Driver info are written to the RxBuffer following rx desc
6405 if (stats->RxDrvInfoSize != 0) {
6406 driver_info = (rx_drvinfo_819x_usb *)(skb->data + sizeof(rx_desc_819x_usb) + \
6407 stats->RxBufShift);
6408 /* unit: 0.5M */
6409 /* TODO */
6410 if(!stats->bHwError){
6411 u8 ret_rate;
6412 ret_rate = HwRateToMRate90(driver_info->RxHT, driver_info->RxRate);
6413 if(ret_rate == 0xff)
6414 {
6415 // Abnormal Case: Receive CRC OK packet with Rx descriptor indicating non supported rate.
6416 // Special Error Handling here, 2008.05.16, by Emily
6417
6418 stats->bHwError = 1;
6419 stats->rate = MGN_1M; //Set 1M rate by default
6420 }else
6421 {
6422 stats->rate = ret_rate;
6423 }
6424 }
6425 else
6426 stats->rate = 0x02;
6427
6428 stats->bShortPreamble = driver_info->SPLCP;
6429
6430
6431 UpdateReceivedRateHistogramStatistics8190(dev, stats);
6432
6433 stats->bIsAMPDU = (driver_info->PartAggr==1);
6434 stats->bFirstMPDU = (driver_info->PartAggr==1) && (driver_info->FirstAGGR==1);
6435#if 0
6436 // TODO: it is debug only. It should be disabled in released driver. 2007.1.12 by Joseph
6437 UpdateRxAMPDUHistogramStatistics8190(Adapter, pRfd);
6438#endif
6439 stats->TimeStampLow = driver_info->TSFL;
6440 // xiong mask it, 070514
6441 //pRfd->Status.TimeStampHigh = PlatformEFIORead4Byte(Adapter, TSFR+4);
6442 // stats->TimeStampHigh = read_nic_dword(dev, TSFR+4);
6443
6444 UpdateRxPktTimeStamp8190(dev, stats);
6445
6446 //
6447 // Rx A-MPDU
6448 //
6449 if(driver_info->FirstAGGR==1 || driver_info->PartAggr == 1)
6450 RT_TRACE(COMP_RXDESC, "driver_info->FirstAGGR = %d, driver_info->PartAggr = %d\n",
6451 driver_info->FirstAGGR, driver_info->PartAggr);
6452
6453 }
6454
6455 skb_pull(skb,sizeof(rx_desc_819x_usb));
6456 //
6457 // Get Total offset of MPDU Frame Body
6458 //
6459 if((stats->RxBufShift + stats->RxDrvInfoSize) > 0) {
6460 stats->bShift = 1;
6461 skb_pull(skb,stats->RxBufShift + stats->RxDrvInfoSize);
6462 }
6463
6464#ifdef USB_RX_AGGREGATION_SUPPORT
6465 /* for the rx aggregated sub frame, the redundant space truelly contained in the packet */
6466 if(bIsRxAggrSubframe) {
6467 skb_pull(skb, 8);
6468 }
6469#endif
6470 /* for debug 2008.5.29 */
6471#if 0
6472 {
6473 int i;
6474 printk("\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6475 for(i = 0; i < skb->len; i++) {
6476 if(i % 10 == 0) printk("\n");
6477 printk("%02x ", skb->data[i]);
6478 }
6479 printk("\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
6480 }
6481#endif
6482
6483 //added by vivi, for MP, 20080108
6484 stats->RxIs40MHzPacket = driver_info->BW;
6485 if(stats->RxDrvInfoSize != 0)
6486 TranslateRxSignalStuff819xUsb(skb, stats, driver_info);
6487
6488}
6489
6490u32 GetRxPacketShiftBytes819xUsb(struct ieee80211_rx_stats *Status, bool bIsRxAggrSubframe)
6491{
6492#ifdef USB_RX_AGGREGATION_SUPPORT
6493 if (bIsRxAggrSubframe)
6494 return (sizeof(rx_desc_819x_usb) + Status->RxDrvInfoSize
6495 + Status->RxBufShift + 8);
6496 else
6497#endif
6498 return (sizeof(rx_desc_819x_usb) + Status->RxDrvInfoSize
6499 + Status->RxBufShift);
6500}
6501
6502void rtl8192_rx_nomal(struct sk_buff* skb)
6503{
6504 rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
6505 struct net_device *dev=info->dev;
6506 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6507 struct ieee80211_rx_stats stats = {
6508 .signal = 0,
6509 .noise = -98,
6510 .rate = 0,
6511 // .mac_time = jiffies,
6512 .freq = IEEE80211_24GHZ_BAND,
6513 };
6514 u32 rx_pkt_len = 0;
6515 struct ieee80211_hdr_1addr *ieee80211_hdr = NULL;
6516 bool unicast_packet = false;
6517#ifdef USB_RX_AGGREGATION_SUPPORT
6518 struct sk_buff *agg_skb = NULL;
6519 u32 TotalLength = 0;
6520 u32 TempDWord = 0;
6521 u32 PacketLength = 0;
6522 u32 PacketOccupiedLendth = 0;
6523 u8 TempByte = 0;
6524 u32 PacketShiftBytes = 0;
6525 rx_desc_819x_usb_aggr_subframe *RxDescr = NULL;
6526 u8 PaddingBytes = 0;
6527 //add just for testing
6528 u8 testing;
6529
6530#endif
6531
6532 /* 20 is for ps-poll */
6533 if((skb->len >=(20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE)) {
6534#ifdef USB_RX_AGGREGATION_SUPPORT
6535 TempByte = *(skb->data + sizeof(rx_desc_819x_usb));
6536#endif
6537 /* first packet should not contain Rx aggregation header */
6538 query_rxdesc_status(skb, &stats, false);
6539 /* TODO */
6540 /* hardware related info */
6541#ifdef USB_RX_AGGREGATION_SUPPORT
6542 if (TempByte & BIT0) {
6543 agg_skb = skb;
6544 //TotalLength = agg_skb->len - 4; /*sCrcLng*/
6545 TotalLength = stats.Length - 4; /*sCrcLng*/
6546 //RT_TRACE(COMP_RECV, "%s:first aggregated packet!Length=%d\n",__FUNCTION__,TotalLength);
6547 /* though the head pointer has passed this position */
6548 TempDWord = *(u32 *)(agg_skb->data - 4);
6549 PacketLength = (u16)(TempDWord & 0x3FFF); /*sCrcLng*/
6550 skb = dev_alloc_skb(PacketLength);
6551 memcpy(skb_put(skb,PacketLength),agg_skb->data,PacketLength);
6552 PacketShiftBytes = GetRxPacketShiftBytes819xUsb(&stats, false);
6553 }
6554#endif
6555 /* Process the MPDU recevied */
6556 skb_trim(skb, skb->len - 4/*sCrcLng*/);
6557
6558 rx_pkt_len = skb->len;
6559 ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
6560 unicast_packet = false;
6561 if(is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
6562 //TODO
6563 }else if(is_multicast_ether_addr(ieee80211_hdr->addr1)){
6564 //TODO
6565 }else {
6566 /* unicast packet */
6567 unicast_packet = true;
6568 }
6569
6570 if(!ieee80211_rx(priv->ieee80211,skb, &stats)) {
6571 dev_kfree_skb_any(skb);
6572 } else {
6573 priv->stats.rxoktotal++;
6574 if(unicast_packet) {
6575 priv->stats.rxbytesunicast += rx_pkt_len;
6576 }
6577 }
6578#ifdef USB_RX_AGGREGATION_SUPPORT
6579 testing = 1;
6580 // (PipeIndex == 0) && (TempByte & BIT0) => TotalLength > 0.
6581 if (TotalLength > 0) {
6582 PacketOccupiedLendth = PacketLength + (PacketShiftBytes + 8);
6583 if ((PacketOccupiedLendth & 0xFF) != 0)
6584 PacketOccupiedLendth = (PacketOccupiedLendth & 0xFFFFFF00) + 256;
6585 PacketOccupiedLendth -= 8;
6586 TempDWord = PacketOccupiedLendth - PacketShiftBytes; /*- PacketLength */
6587 if (agg_skb->len > TempDWord)
6588 skb_pull(agg_skb, TempDWord);
6589 else
6590 agg_skb->len = 0;
6591
6592 while (agg_skb->len>=GetRxPacketShiftBytes819xUsb(&stats, true)) {
6593 u8 tmpCRC = 0, tmpICV = 0;
6594 //RT_TRACE(COMP_RECV,"%s:aggred pkt,total_len = %d\n",__FUNCTION__,agg_skb->len);
6595 RxDescr = (rx_desc_819x_usb_aggr_subframe *)(agg_skb->data);
6596 tmpCRC = RxDescr->CRC32;
6597 tmpICV = RxDescr->ICV;
6598 memcpy(agg_skb->data, &agg_skb->data[44], 2);
6599 RxDescr->CRC32 = tmpCRC;
6600 RxDescr->ICV = tmpICV;
6601
6602 memset(&stats, 0, sizeof(struct ieee80211_rx_stats));
6603 stats.signal = 0;
6604 stats.noise = -98;
6605 stats.rate = 0;
6606 stats.freq = IEEE80211_24GHZ_BAND;
6607 query_rxdesc_status(agg_skb, &stats, true);
6608 PacketLength = stats.Length;
6609
6610 if(PacketLength > agg_skb->len) {
6611 break;
6612 }
6613 /* Process the MPDU recevied */
6614 skb = dev_alloc_skb(PacketLength);
6615 memcpy(skb_put(skb,PacketLength),agg_skb->data, PacketLength);
6616 skb_trim(skb, skb->len - 4/*sCrcLng*/);
6617
6618 rx_pkt_len = skb->len;
6619 ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data;
6620 unicast_packet = false;
6621 if(is_broadcast_ether_addr(ieee80211_hdr->addr1)) {
6622 //TODO
6623 }else if(is_multicast_ether_addr(ieee80211_hdr->addr1)){
6624 //TODO
6625 }else {
6626 /* unicast packet */
6627 unicast_packet = true;
6628 }
6629 if(!ieee80211_rx(priv->ieee80211,skb, &stats)) {
6630 dev_kfree_skb_any(skb);
6631 } else {
6632 priv->stats.rxoktotal++;
6633 if(unicast_packet) {
6634 priv->stats.rxbytesunicast += rx_pkt_len;
6635 }
6636 }
6637 /* should trim the packet which has been copied to target skb */
6638 skb_pull(agg_skb, PacketLength);
6639 PacketShiftBytes = GetRxPacketShiftBytes819xUsb(&stats, true);
6640 PacketOccupiedLendth = PacketLength + PacketShiftBytes;
6641 if ((PacketOccupiedLendth & 0xFF) != 0) {
6642 PaddingBytes = 256 - (PacketOccupiedLendth & 0xFF);
6643 if (agg_skb->len > PaddingBytes)
6644 skb_pull(agg_skb, PaddingBytes);
6645 else
6646 agg_skb->len = 0;
6647 }
6648 }
6649 dev_kfree_skb(agg_skb);
6650 }
6651#endif
6652 } else {
6653 priv->stats.rxurberr++;
6654 printk("actual_length:%d\n", skb->len);
6655 dev_kfree_skb_any(skb);
6656 }
6657
6658}
6659
6660void
6661rtl819xusb_process_received_packet(
6662 struct net_device *dev,
6663 struct ieee80211_rx_stats *pstats
6664 )
6665{
6666// bool bfreerfd=false, bqueued=false;
6667 u8* frame;
6668 u16 frame_len=0;
6669 struct r8192_priv *priv = ieee80211_priv(dev);
6670// u8 index = 0;
6671// u8 TID = 0;
6672 //u16 seqnum = 0;
6673 //PRX_TS_RECORD pts = NULL;
6674
6675 // Get shifted bytes of Starting address of 802.11 header. 2006.09.28, by Emily
6676 //porting by amy 080508
6677 pstats->virtual_address += get_rxpacket_shiftbytes_819xusb(pstats);
6678 frame = pstats->virtual_address;
6679 frame_len = pstats->packetlength;
6680#ifdef TODO // by amy about HCT
6681 if(!Adapter->bInHctTest)
6682 CountRxErrStatistics(Adapter, pRfd);
6683#endif
6684 {
6685 #ifdef ENABLE_PS //by amy for adding ps function in future
6686 RT_RF_POWER_STATE rtState;
6687 // When RF is off, we should not count the packet for hw/sw synchronize
6688 // reason, ie. there may be a duration while sw switch is changed and hw
6689 // switch is being changed. 2006.12.04, by shien chang.
6690 Adapter->HalFunc.GetHwRegHandler(Adapter, HW_VAR_RF_STATE, (u8* )(&rtState));
6691 if (rtState == eRfOff)
6692 {
6693 return;
6694 }
6695 #endif
6696 priv->stats.rxframgment++;
6697
6698 }
6699#ifdef TODO
6700 RmMonitorSignalStrength(Adapter, pRfd);
6701#endif
6702 /* 2007/01/16 MH Add RX command packet handle here. */
6703 /* 2007/03/01 MH We have to release RFD and return if rx pkt is cmd pkt. */
6704 if (rtl819xusb_rx_command_packet(dev, pstats))
6705 {
6706 return;
6707 }
6708
6709#ifdef SW_CRC_CHECK
6710 SwCrcCheck();
6711#endif
6712
6713
6714}
6715
6716void query_rx_cmdpkt_desc_status(struct sk_buff *skb, struct ieee80211_rx_stats *stats)
6717{
6718// rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
6719// struct net_device *dev=info->dev;
6720// struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
6721 rx_desc_819x_usb *desc = (rx_desc_819x_usb *)skb->data;
6722// rx_drvinfo_819x_usb *driver_info;
6723
6724 //
6725 //Get Rx Descriptor Information
6726 //
6727 stats->virtual_address = (u8*)skb->data;
6728 stats->Length = desc->Length;
6729 stats->RxDrvInfoSize = 0;
6730 stats->RxBufShift = 0;
6731 stats->packetlength = stats->Length-scrclng;
6732 stats->fraglength = stats->packetlength;
6733 stats->fragoffset = 0;
6734 stats->ntotalfrag = 1;
6735}
6736
6737
6738void rtl8192_rx_cmd(struct sk_buff *skb)
6739{
6740 struct rtl8192_rx_info *info = (struct rtl8192_rx_info *)skb->cb;
6741 struct net_device *dev = info->dev;
6742 //int ret;
6743// struct urb *rx_urb = info->urb;
6744 /* TODO */
6745 struct ieee80211_rx_stats stats = {
6746 .signal = 0,
6747 .noise = -98,
6748 .rate = 0,
6749 // .mac_time = jiffies,
6750 .freq = IEEE80211_24GHZ_BAND,
6751 };
6752
6753 if((skb->len >=(20 + sizeof(rx_desc_819x_usb))) && (skb->len < RX_URB_SIZE))
6754 {
6755
6756 query_rx_cmdpkt_desc_status(skb,&stats);
6757 // this is to be done by amy 080508 prfd->queue_id = 1;
6758
6759
6760 //
6761 // Process the command packet received.
6762 //
6763
6764 rtl819xusb_process_received_packet(dev,&stats);
6765
6766 dev_kfree_skb_any(skb);
6767 }
6768 else
6769 ;
6770
6771
6772#if 0
6773 desc = (u32*)(skb->data);
6774 cmd = (desc[0] >> 30) & 0x03;
6775
6776 if(cmd == 0x00) {//beacon interrupt
6777 //send beacon packet
6778 skb = ieee80211_get_beacon(priv->ieee80211);
6779
6780 if(!skb){
6781 DMESG("not enought memory for allocating beacon");
6782 return;
6783 }
6784 skb->cb[0] = BEACON_PRIORITY;
6785 skb->cb[1] = 0;
6786 skb->cb[2] = ieeerate2rtlrate(priv->ieee80211->basic_rate);
6787 ret = rtl8192_tx(dev, skb);
6788
6789 if( ret != 0 ){
6790 printk(KERN_ALERT "tx beacon packet error : %d !\n", ret);
6791 }
6792 dev_kfree_skb_any(skb);
6793 } else {//0x00
6794 //{ log the device information
6795 // At present, It is not implemented just now.
6796 //}
6797 }
6798#endif
6799}
6800
6801void rtl8192_irq_rx_tasklet(struct r8192_priv *priv)
6802{
6803 struct sk_buff *skb;
6804 struct rtl8192_rx_info *info;
6805
6806 while (NULL != (skb = skb_dequeue(&priv->skb_queue))) {
6807 info = (struct rtl8192_rx_info *)skb->cb;
6808 switch (info->out_pipe) {
6809 /* Nomal packet pipe */
6810 case 3:
6811 //RT_TRACE(COMP_RECV, "normal in-pipe index(%d)\n",info->out_pipe);
6812 priv->IrpPendingCount--;
6813 rtl8192_rx_nomal(skb);
6814 break;
6815
6816 /* Command packet pipe */
6817 case 9:
6818 RT_TRACE(COMP_RECV, "command in-pipe index(%d)\n",\
6819 info->out_pipe);
6820
6821 rtl8192_rx_cmd(skb);
6822 break;
6823
6824 default: /* should never get here! */
6825 RT_TRACE(COMP_ERR, "Unknown in-pipe index(%d)\n",\
6826 info->out_pipe);
6827 dev_kfree_skb(skb);
6828 break;
6829
6830 }
6831 }
6832}
6833
6834
6835
6836/****************************************************************************
6837 ---------------------------- USB_STUFF---------------------------
6838*****************************************************************************/
6839
6840#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
6841static int __devinit rtl8192_usb_probe(struct usb_interface *intf,
6842 const struct usb_device_id *id)
6843#else
6844static void * __devinit rtl8192_usb_probe(struct usb_device *udev,
6845 unsigned int ifnum,
6846 const struct usb_device_id *id)
6847#endif
6848{
6849// unsigned long ioaddr = 0;
6850 struct net_device *dev = NULL;
6851 struct r8192_priv *priv= NULL;
6852#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
6853 struct usb_device *udev = interface_to_usbdev(intf);
6854#endif
6855 RT_TRACE(COMP_INIT, "Oops: i'm coming\n");
6856
6857 dev = alloc_ieee80211(sizeof(struct r8192_priv));
6858
6859#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
6860 SET_MODULE_OWNER(dev);
6861#endif
6862
6863#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
6864 usb_set_intfdata(intf, dev);
6865 SET_NETDEV_DEV(dev, &intf->dev);
6866#endif
6867 priv = ieee80211_priv(dev);
6868#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
6869 priv->ieee80211 = netdev_priv(dev);
6870#else
6871 priv->ieee80211 = (struct net_device *)dev->priv;
6872#endif
6873 priv->udev=udev;
6874
6875 dev->open = rtl8192_open;
6876 dev->stop = rtl8192_close;
6877 //dev->hard_start_xmit = rtl8192_8023_hard_start_xmit;
6878 dev->tx_timeout = tx_timeout;
6879 //dev->wireless_handlers = &r8192_wx_handlers_def;
6880 dev->do_ioctl = rtl8192_ioctl;
6881 dev->set_multicast_list = r8192_set_multicast;
6882 dev->set_mac_address = r8192_set_mac_adr;
6883 dev->get_stats = rtl8192_stats;
6884
6885 //DMESG("Oops: i'm coming\n");
6886#if WIRELESS_EXT >= 12
6887#if WIRELESS_EXT < 17
6888 dev->get_wireless_stats = r8192_get_wireless_stats;
6889#endif
6890 dev->wireless_handlers = (struct iw_handler_def *) &r8192_wx_handlers_def;
6891#endif
6892 dev->type=ARPHRD_ETHER;
6893
6894 dev->watchdog_timeo = HZ*3; //modified by john, 0805
6895
6896 if (dev_alloc_name(dev, ifname) < 0){
6897 RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n");
6898 ifname = "wlan%d";
6899 dev_alloc_name(dev, ifname);
6900 }
6901
6902 RT_TRACE(COMP_INIT, "Driver probe completed1\n");
6903#if 1
6904 if(rtl8192_init(dev)!=0){
6905 RT_TRACE(COMP_ERR, "Initialization failed");
6906 goto fail;
6907 }
6908#endif
6909 netif_carrier_off(dev);
6910 netif_stop_queue(dev);
6911
6912 register_netdev(dev);
6913 RT_TRACE(COMP_INIT, "dev name=======> %s\n",dev->name);
6914 rtl8192_proc_init_one(dev);
6915
6916
6917 RT_TRACE(COMP_INIT, "Driver probe completed\n");
6918#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6919 return dev;
6920#else
6921 return 0;
6922#endif
6923
6924
6925fail:
6926 free_ieee80211(dev);
6927
6928 RT_TRACE(COMP_ERR, "wlan driver load failed\n");
6929#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
6930 return NULL;
6931#else
6932 return -ENODEV;
6933#endif
6934
6935}
6936
6937//detach all the work and timer structure declared or inititialize in r8192U_init function.
6938void rtl8192_cancel_deferred_work(struct r8192_priv* priv)
6939{
6940
6941#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
6942 cancel_work_sync(&priv->reset_wq);
6943 cancel_delayed_work(&priv->watch_dog_wq);
6944 cancel_delayed_work(&priv->update_beacon_wq);
6945 cancel_work_sync(&priv->qos_activate);
6946 //cancel_work_sync(&priv->SetBWModeWorkItem);
6947 //cancel_work_sync(&priv->SwChnlWorkItem);
6948#else
6949#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
6950// cancel_delayed_work(&priv->reset_wq);
6951 cancel_delayed_work(&priv->watch_dog_wq);
6952 cancel_delayed_work(&priv->update_beacon_wq);
6953// cancel_delayed_work(&priv->qos_activate);
6954 //cancel_delayed_work(&priv->SetBWModeWorkItem);
6955 //cancel_delayed_work(&priv->SwChnlWorkItem);
6956#endif
6957#endif
6958
6959}
6960
6961
6962#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
6963static void __devexit rtl8192_usb_disconnect(struct usb_interface *intf)
6964#else
6965static void __devexit rtl8192_usb_disconnect(struct usb_device *udev, void *ptr)
6966#endif
6967{
6968#if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
6969 struct net_device *dev = usb_get_intfdata(intf);
6970#else
6971 struct net_device *dev = (struct net_device *)ptr;
6972#endif
6973
6974 struct r8192_priv *priv = ieee80211_priv(dev);
6975 if(dev){
6976
6977 unregister_netdev(dev);
6978
6979 RT_TRACE(COMP_DOWN, "=============>wlan driver to be removed\n");
6980 rtl8192_proc_remove_one(dev);
6981
6982 rtl8192_down(dev);
6983 if (priv->pFirmware)
6984 {
6985 kfree(priv->pFirmware);
6986 priv->pFirmware = NULL;
6987 }
6988 // priv->rf_close(dev);
6989// rtl8192_SetRFPowerState(dev, eRfOff);
6990 rtl8192_usb_deleteendpoints(dev);
6991#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
6992 destroy_workqueue(priv->priv_wq);
6993#endif
6994 //rtl8192_irq_disable(dev);
6995 //rtl8192_reset(dev);
6996 mdelay(10);
6997
6998 }
6999 free_ieee80211(dev);
7000 RT_TRACE(COMP_DOWN, "wlan driver removed\n");
7001}
7002
7003
7004static int __init rtl8192_usb_module_init(void)
7005{
7006 printk(KERN_INFO "\nLinux kernel driver for RTL8192 based WLAN cards\n");
7007 printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan\n");
7008 RT_TRACE(COMP_INIT, "Initializing module");
7009 RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT);
7010 rtl8192_proc_module_init();
7011 return usb_register(&rtl8192_usb_driver);
7012}
7013
7014
7015static void __exit rtl8192_usb_module_exit(void)
7016{
7017 usb_deregister(&rtl8192_usb_driver);
7018
7019 RT_TRACE(COMP_DOWN, "Exiting");
7020// rtl8192_proc_module_remove();
7021}
7022
7023
7024void rtl8192_try_wake_queue(struct net_device *dev, int pri)
7025{
7026 unsigned long flags;
7027 short enough_desc;
7028 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
7029
7030 spin_lock_irqsave(&priv->tx_lock,flags);
7031 enough_desc = check_nic_enough_desc(dev,pri);
7032 spin_unlock_irqrestore(&priv->tx_lock,flags);
7033
7034 if(enough_desc)
7035 ieee80211_wake_queue(priv->ieee80211);
7036}
7037
7038void EnableHWSecurityConfig8192(struct net_device *dev)
7039{
7040 u8 SECR_value = 0x0;
7041 struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
7042 struct ieee80211_device* ieee = priv->ieee80211;
7043 SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
7044#if 1
7045 if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2))
7046 {
7047 SECR_value |= SCR_RxUseDK;
7048 SECR_value |= SCR_TxUseDK;
7049 }
7050 else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP)))
7051 {
7052 SECR_value |= SCR_RxUseDK;
7053 SECR_value |= SCR_TxUseDK;
7054 }
7055#endif
7056 //add HWSec active enable here.
7057//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
7058
7059 ieee->hwsec_active = 1;
7060
7061 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
7062 {
7063 ieee->hwsec_active = 0;
7064 SECR_value &= ~SCR_RxDecEnable;
7065 }
7066 RT_TRACE(COMP_SEC,"%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __FUNCTION__, \
7067 ieee->hwsec_active, ieee->pairwise_key_type, SECR_value);
7068 {
7069 write_nic_byte(dev, SECR, SECR_value);//SECR_value | SCR_UseDK );
7070 }
7071}
7072
7073
7074void setKey( struct net_device *dev,
7075 u8 EntryNo,
7076 u8 KeyIndex,
7077 u16 KeyType,
7078 u8 *MacAddr,
7079 u8 DefaultKey,
7080 u32 *KeyContent )
7081{
7082 u32 TargetCommand = 0;
7083 u32 TargetContent = 0;
7084 u16 usConfig = 0;
7085 u8 i;
7086 if (EntryNo >= TOTAL_CAM_ENTRY)
7087 RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n");
7088
7089 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));
7090
7091 if (DefaultKey)
7092 usConfig |= BIT15 | (KeyType<<2);
7093 else
7094 usConfig |= BIT15 | (KeyType<<2) | KeyIndex;
7095// usConfig |= BIT15 | (KeyType<<2) | (DefaultKey<<5) | KeyIndex;
7096
7097
7098 for(i=0 ; i<CAM_CONTENT_COUNT; i++){
7099 TargetCommand = i+CAM_CONTENT_COUNT*EntryNo;
7100 TargetCommand |= BIT31|BIT16;
7101
7102 if(i==0){//MAC|Config
7103 TargetContent = (u32)(*(MacAddr+0)) << 16|
7104 (u32)(*(MacAddr+1)) << 24|
7105 (u32)usConfig;
7106
7107 write_nic_dword(dev, WCAMI, TargetContent);
7108 write_nic_dword(dev, RWCAM, TargetCommand);
7109 // printk("setkey cam =%8x\n", read_cam(dev, i+6*EntryNo));
7110 }
7111 else if(i==1){//MAC
7112 TargetContent = (u32)(*(MacAddr+2)) |
7113 (u32)(*(MacAddr+3)) << 8|
7114 (u32)(*(MacAddr+4)) << 16|
7115 (u32)(*(MacAddr+5)) << 24;
7116 write_nic_dword(dev, WCAMI, TargetContent);
7117 write_nic_dword(dev, RWCAM, TargetCommand);
7118 }
7119 else {
7120 //Key Material
7121 if(KeyContent !=NULL){
7122 write_nic_dword(dev, WCAMI, (u32)(*(KeyContent+i-2)) );
7123 write_nic_dword(dev, RWCAM, TargetCommand);
7124 }
7125 }
7126 }
7127
7128}
7129
7130/***************************************************************************
7131 ------------------- module init / exit stubs ----------------
7132****************************************************************************/
7133module_init(rtl8192_usb_module_init);
7134module_exit(rtl8192_usb_module_exit);