2 This is part of rtl818x pci OpenSource driver - v 0.1
3 Copyright (C) Andrea Merello 2004-2005 <andreamrl@tiscali.it>
4 Released under the terms of GPL (General Public License)
6 Parts of this driver are based on the GPL part of the official
9 Parts of this driver are based on the rtl8180 driver skeleton
10 from Patric Schenke & Andres Salomon.
12 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver.
14 Parts of BB/RF code are derived from David Young rtl8180 netbsd driver.
16 RSSI calc function from 'The Deuce'
18 Some ideas borrowed from the 8139too.c driver included in linux kernel.
20 We (I?) want to thanks the Authors of those projecs and also the
21 Ndiswrapper's project Authors.
23 A big big thanks goes also to Realtek corp. for their help in my attempt to
24 add RTL8185 and RTL8225 support, and to David Young also.
28 double __floatsidf (int i) { return i; }
29 unsigned int __fixunsdfsi (double d) { return d; }
30 double __adddf3(double a, double b) { return a+b; }
31 double __addsf3(float a, float b) { return a+b; }
32 double __subdf3(double a, double b) { return a-b; }
33 double __extendsfdf2(float a) {return a;}
38 #undef RX_DONT_PASS_UL
40 #undef DEBUG_RX_VERBOSE
46 #undef DEBUG_TX_FILLDESC
51 #undef DEBUG_REGISTERS
53 #undef DEBUG_IRQ_TASKLET
58 //#define DEBUG_TX_DESC2
60 //#define DEBUG_RX_SKB
62 //#define CONFIG_RTL8180_IO_MAP
63 #include <linux/syscalls.h>
64 //#include <linux/fcntl.h>
65 //#include <asm/uaccess.h>
68 #include "r8180_sa2400.h" /* PHILIPS Radio frontend */
69 #include "r8180_max2820.h" /* MAXIM Radio frontend */
70 #include "r8180_gct.h" /* GCT Radio frontend */
71 #include "r8180_rtl8225.h" /* RTL8225 Radio frontend */
72 #include "r8180_rtl8255.h" /* RTL8255 Radio frontend */
73 #include "r8180_93cx6.h" /* Card EEPROM */
77 #ifdef CONFIG_RTL8180_PM
85 #ifdef CONFIG_RTL8185B
86 //#define CONFIG_RTL8180_IO_MAP
89 #ifndef PCI_VENDOR_ID_BELKIN
90 #define PCI_VENDOR_ID_BELKIN 0x1799
92 #ifndef PCI_VENDOR_ID_DLINK
93 #define PCI_VENDOR_ID_DLINK 0x1186
96 static struct pci_device_id rtl8180_pci_id_tbl[] __devinitdata = {
98 .vendor = PCI_VENDOR_ID_REALTEK,
101 .subvendor = PCI_ANY_ID,
102 .subdevice = PCI_ANY_ID,
107 .vendor = PCI_VENDOR_ID_BELKIN,
109 .subvendor = PCI_ANY_ID,
110 .subdevice = PCI_ANY_ID,
113 { /* Belkin F5D6020 v3 */
114 .vendor = PCI_VENDOR_ID_BELKIN,
116 .subvendor = PCI_ANY_ID,
117 .subdevice = PCI_ANY_ID,
120 { /* D-Link DWL-610 */
121 .vendor = PCI_VENDOR_ID_DLINK,
123 .subvendor = PCI_ANY_ID,
124 .subdevice = PCI_ANY_ID,
128 .vendor = PCI_VENDOR_ID_REALTEK,
130 .subvendor = PCI_ANY_ID,
131 .subdevice = PCI_ANY_ID,
145 static char* ifname = "wlan%d";
146 static int hwseqnum = 0;
147 //static char* ifname = "ath%d";
148 static int hwwep = 0;
149 static int channels = 0x3fff;
151 #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 )
152 #define cpMacAddr(des,src) ((des)[0]=(src)[0],(des)[1]=(src)[1],(des)[2]=(src)[2],(des)[3]=(src)[3],(des)[4]=(src)[4],(des)[5]=(src)[5])
153 MODULE_LICENSE("GPL");
154 MODULE_DEVICE_TABLE(pci, rtl8180_pci_id_tbl);
155 MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>");
156 MODULE_DESCRIPTION("Linux driver for Realtek RTL8180 / RTL8185 WiFi cards");
161 MODULE_PARM(ifname, "s");
162 MODULE_PARM_DESC(devname," Net interface name, wlan%d=default");
164 MODULE_PARM(hwseqnum,"i");
165 MODULE_PARM_DESC(hwseqnum," Try to use hardware 802.11 header sequence numbers. Zero=default");
167 MODULE_PARM(hwwep,"i");
168 MODULE_PARM_DESC(hwwep," Try to use hardware WEP support. Still broken and not available on all cards");
170 MODULE_PARM(channels,"i");
171 MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");
174 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 9)
175 module_param(ifname, charp, S_IRUGO|S_IWUSR );
176 module_param(hwseqnum,int, S_IRUGO|S_IWUSR);
177 module_param(hwwep,int, S_IRUGO|S_IWUSR);
178 module_param(channels,int, S_IRUGO|S_IWUSR);
180 MODULE_PARM(ifname, "s");
181 MODULE_PARM(hwseqnum,"i");
182 MODULE_PARM(hwwep,"i");
183 MODULE_PARM(channels,"i");
186 MODULE_PARM_DESC(devname," Net interface name, wlan%d=default");
187 //MODULE_PARM_DESC(devname," Net interface name, ath%d=default");
188 MODULE_PARM_DESC(hwseqnum," Try to use hardware 802.11 header sequence numbers. Zero=default");
189 MODULE_PARM_DESC(hwwep," Try to use hardware WEP support. Still broken and not available on all cards");
190 MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");
193 static int __devinit rtl8180_pci_probe(struct pci_dev *pdev,
194 const struct pci_device_id *id);
196 static void __devexit rtl8180_pci_remove(struct pci_dev *pdev);
198 static void rtl8180_shutdown (struct pci_dev *pdev)
200 struct net_device *dev = pci_get_drvdata(pdev);
201 if (dev->netdev_ops->ndo_stop)
202 dev->netdev_ops->ndo_stop(dev);
203 pci_disable_device(pdev);
206 static struct pci_driver rtl8180_pci_driver = {
207 .name = RTL8180_MODULE_NAME, /* Driver name */
208 .id_table = rtl8180_pci_id_tbl, /* PCI_ID table */
209 .probe = rtl8180_pci_probe, /* probe fn */
210 .remove = __devexit_p(rtl8180_pci_remove),/* remove fn */
211 #ifdef CONFIG_RTL8180_PM
212 .suspend = rtl8180_suspend, /* PM suspend fn */
213 .resume = rtl8180_resume, /* PM resume fn */
215 .suspend = NULL, /* PM suspend fn */
216 .resume = NULL, /* PM resume fn */
218 .shutdown = rtl8180_shutdown,
223 #ifdef CONFIG_RTL8180_IO_MAP
225 u8 read_nic_byte(struct net_device *dev, int x)
227 return 0xff&inb(dev->base_addr +x);
230 u32 read_nic_dword(struct net_device *dev, int x)
232 return inl(dev->base_addr +x);
235 u16 read_nic_word(struct net_device *dev, int x)
237 return inw(dev->base_addr +x);
240 void write_nic_byte(struct net_device *dev, int x,u8 y)
242 outb(y&0xff,dev->base_addr +x);
245 void write_nic_word(struct net_device *dev, int x,u16 y)
247 outw(y,dev->base_addr +x);
250 void write_nic_dword(struct net_device *dev, int x,u32 y)
252 outl(y,dev->base_addr +x);
255 #else /* RTL_IO_MAP */
257 u8 read_nic_byte(struct net_device *dev, int x)
259 return 0xff&readb((u8*)dev->mem_start +x);
262 u32 read_nic_dword(struct net_device *dev, int x)
264 return readl((u8*)dev->mem_start +x);
267 u16 read_nic_word(struct net_device *dev, int x)
269 return readw((u8*)dev->mem_start +x);
272 void write_nic_byte(struct net_device *dev, int x,u8 y)
274 writeb(y,(u8*)dev->mem_start +x);
278 void write_nic_dword(struct net_device *dev, int x,u32 y)
280 writel(y,(u8*)dev->mem_start +x);
284 void write_nic_word(struct net_device *dev, int x,u16 y)
286 writew(y,(u8*)dev->mem_start +x);
290 #endif /* RTL_IO_MAP */
296 inline void force_pci_posting(struct net_device *dev)
298 read_nic_byte(dev,EPROM_CMD);
299 #ifndef CONFIG_RTL8180_IO_MAP
305 irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs);
306 void set_nic_rxring(struct net_device *dev);
307 void set_nic_txring(struct net_device *dev);
308 static struct net_device_stats *rtl8180_stats(struct net_device *dev);
309 void rtl8180_commit(struct net_device *dev);
310 void rtl8180_start_tx_beacon(struct net_device *dev);
312 /****************************************************************************
313 -----------------------------PROCFS STUFF-------------------------
314 *****************************************************************************/
316 static struct proc_dir_entry *rtl8180_proc = NULL;
318 static int proc_get_registers(char *page, char **start,
319 off_t offset, int count,
320 int *eof, void *data)
322 struct net_device *dev = data;
323 // struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
330 /* This dump the current register page */
333 //printk( "\nD: %2x> ", n);
334 len += snprintf(page + len, count - len,
337 for(i=0;i<16 && n<=max;i++,n++)
338 len += snprintf(page + len, count - len,
339 "%2x ",read_nic_byte(dev,n));
341 // printk("%2x ",read_nic_byte(dev,n));
343 len += snprintf(page + len, count - len,"\n");
352 int get_curr_tx_free_desc(struct net_device *dev, int priority);
354 static int proc_get_stats_hw(char *page, char **start,
355 off_t offset, int count,
356 int *eof, void *data)
358 //struct net_device *dev = data;
359 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
362 #ifdef CONFIG_RTL8185B
365 len += snprintf(page + len, count - len,
368 "--------------------\n"
371 "--------------------\n"
372 "LP phys dma addr %x\n"
374 "LP virt 32base %x\n"
375 "LP virt 32tail %x\n"
376 "--------------------\n"
377 "NP phys dma addr %x\n"
379 "NP virt 32base %x\n"
380 "NP virt 32tail %x\n"
381 "--------------------\n"
382 "BP phys dma addr %x\n"
384 "BP virt 32base %x\n"
385 "BP virt 32tail %x\n",
388 get_curr_tx_free_desc(dev,LOW_PRIORITY),
389 get_curr_tx_free_desc(dev,NORM_PRIORITY),
390 (u32)priv->txvipringdma,
391 read_nic_dword(dev,TLPDA),
392 (u32)priv->txvipring,
393 (u32)priv->txvipringtail,
394 (u32)priv->txvopringdma,
395 read_nic_dword(dev,TNPDA),
396 (u32)priv->txvopring,
397 (u32)priv->txvopringtail,
398 (u32)priv->txbeaconringdma,
399 read_nic_dword(dev,TBDA),
400 (u32)priv->txbeaconring,
401 (u32)priv->txbeaconringtail);
408 static int proc_get_stats_rx(char *page, char **start,
409 off_t offset, int count,
410 int *eof, void *data)
412 struct net_device *dev = data;
413 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
417 len += snprintf(page + len, count - len,
418 /* "RX descriptor not available: %lu\n"
419 "RX incomplete (missing last descriptor): %lu\n"
421 //"RX descriptor pointer reset: %lu\n"
422 "RX descriptor pointer lost: %lu\n"
423 //"RX pointer workaround: %lu\n"
424 "RX error int: %lu\n"
425 "RX fifo overflow: %lu\n"
429 "RX DMA fail: %lu\n",
431 priv->stats.rxnolast,
432 priv->stats.rxnodata,
433 //priv->stats.rxreset,
434 priv->stats.rxnopointer,
435 //priv->stats.rxwrkaround,
437 priv->stats.rxoverflow,
439 priv->ieee80211->stats.rx_packets,
440 priv->ieee80211->stats.rx_bytes,
441 priv->stats.rxdmafail */
444 "RX CRC Error(0-500): %lu\n"
445 "RX CRC Error(500-1000): %lu\n"
446 "RX CRC Error(>1000): %lu\n"
447 "RX ICV Error: %lu\n",
450 priv->stats.rxcrcerrmin,
451 priv->stats.rxcrcerrmid,
452 priv->stats.rxcrcerrmax,
461 static int proc_get_stats_ieee(char *page, char **start,
462 off_t offset, int count,
463 int *eof, void *data)
465 struct net_device *dev = data;
466 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
470 len += snprintf(page + len, count - len,
471 "TXed association requests: %u\n"
472 "TXed authentication requests: %u\n"
473 "RXed successful association response: %u\n"
474 "RXed failed association response: %u\n"
475 "RXed successful authentication response: %u\n"
476 "RXed failed authentication response: %u\n"
477 "Association requests without response: %u\n"
478 "Authentication requests without response: %u\n"
479 "TX probe response: %u\n"
480 "RX probe request: %u\n"
481 "TX probe request: %lu\n"
482 "RX authentication requests: %lu\n"
483 "RX association requests: %lu\n"
484 "Reassociations: %lu\n",
485 priv->ieee80211->ieee_stats.tx_ass,
486 priv->ieee80211->ieee_stats.tx_aut,
487 priv->ieee80211->ieee_stats.rx_ass_ok,
488 priv->ieee80211->ieee_stats.rx_ass_err,
489 priv->ieee80211->ieee_stats.rx_aut_ok,
490 priv->ieee80211->ieee_stats.rx_aut_err,
491 priv->ieee80211->ieee_stats.ass_noresp,
492 priv->ieee80211->ieee_stats.aut_noresp,
493 priv->ieee80211->ieee_stats.tx_probe,
494 priv->ieee80211->ieee_stats.rx_probe,
495 priv->ieee80211->ieee_stats.tx_probe_rq,
496 priv->ieee80211->ieee_stats.rx_auth_rq,
497 priv->ieee80211->ieee_stats.rx_assoc_rq,
498 priv->ieee80211->ieee_stats.reassoc);
505 static int proc_get_stats_ap(char *page, char **start,
506 off_t offset, int count,
507 int *eof, void *data)
509 struct net_device *dev = data;
510 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
511 struct mac_htable_t *list;
515 if(priv->ieee80211->iw_mode != IW_MODE_MASTER){
516 len += snprintf(page + len, count - len,
517 "Card is not acting as AP...\n"
520 len += snprintf(page + len, count - len,
521 "List of associated STA:\n"
524 for(i=0;i<MAC_HTABLE_ENTRY;i++)
525 for (list = priv->ieee80211->assoc_htable[i]; list!=NULL; list = list->next){
526 len += snprintf(page + len, count - len,
527 MACSTR"\n",MAC2STR(list->adr));
536 static int proc_get_stats_tx(char *page, char **start,
537 off_t offset, int count,
538 int *eof, void *data)
540 struct net_device *dev = data;
541 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
544 unsigned long totalOK;
546 totalOK=priv->stats.txnpokint+priv->stats.txhpokint+priv->stats.txlpokint;
547 len += snprintf(page + len, count - len,
548 /* "TX normal priority ok int: %lu\n"
549 "TX normal priority error int: %lu\n"
550 "TX high priority ok int: %lu\n"
551 "TX high priority failed error int: %lu\n"
552 "TX low priority ok int: %lu\n"
553 "TX low priority failed error int: %lu\n"
556 "TX queue resume: %lu\n"
557 "TX queue stopped?: %d\n"
558 "TX fifo overflow: %lu\n"
559 //"SW TX stop: %lu\n"
560 //"SW TX wake: %lu\n"
562 "TX beacon aborted: %lu\n",
563 priv->stats.txnpokint,
565 priv->stats.txhpokint,
567 priv->stats.txlpokint,
569 priv->ieee80211->stats.tx_bytes,
570 priv->ieee80211->stats.tx_packets,
571 priv->stats.txresumed,
572 netif_queue_stopped(dev),
573 priv->stats.txoverflow,
574 //priv->ieee80211->ieee_stats.swtxstop,
575 //priv->ieee80211->ieee_stats.swtxawake,
576 priv->stats.txbeacon,
577 priv->stats.txbeaconerr */
581 "TX beacon OK: %lu\n"
582 "TX beacon error: %lu\n",
584 priv->stats.txnperr+priv->stats.txhperr+priv->stats.txlperr,
586 priv->stats.txbeacon,
587 priv->stats.txbeaconerr
595 #if WIRELESS_EXT < 17
596 static struct iw_statistics *r8180_get_wireless_stats(struct net_device *dev)
598 struct r8180_priv *priv = ieee80211_priv(dev);
600 return &priv->wstats;
603 void rtl8180_proc_module_init(void)
605 DMESG("Initializing proc filesystem");
606 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
607 rtl8180_proc=create_proc_entry(RTL8180_MODULE_NAME, S_IFDIR, proc_net);
609 rtl8180_proc=create_proc_entry(RTL8180_MODULE_NAME, S_IFDIR, init_net.proc_net);
614 void rtl8180_proc_module_remove(void)
616 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
617 remove_proc_entry(RTL8180_MODULE_NAME, proc_net);
619 remove_proc_entry(RTL8180_MODULE_NAME, init_net.proc_net);
624 void rtl8180_proc_remove_one(struct net_device *dev)
626 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
628 remove_proc_entry("stats-hw", priv->dir_dev);
629 remove_proc_entry("stats-tx", priv->dir_dev);
630 remove_proc_entry("stats-rx", priv->dir_dev);
631 // remove_proc_entry("stats-ieee", priv->dir_dev);
632 // remove_proc_entry("stats-ap", priv->dir_dev);
633 remove_proc_entry("registers", priv->dir_dev);
634 remove_proc_entry(dev->name, rtl8180_proc);
635 priv->dir_dev = NULL;
640 void rtl8180_proc_init_one(struct net_device *dev)
642 struct proc_dir_entry *e;
643 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
644 priv->dir_dev = rtl8180_proc;
645 if (!priv->dir_dev) {
646 DMESGE("Unable to initialize /proc/net/r8180/%s\n",
651 e = create_proc_read_entry("stats-hw", S_IFREG | S_IRUGO,
652 priv->dir_dev, proc_get_stats_hw, dev);
655 DMESGE("Unable to initialize "
656 "/proc/net/r8180/%s/stats-hw\n",
660 e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
661 priv->dir_dev, proc_get_stats_rx, dev);
664 DMESGE("Unable to initialize "
665 "/proc/net/r8180/%s/stats-rx\n",
670 e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
671 priv->dir_dev, proc_get_stats_tx, dev);
674 DMESGE("Unable to initialize "
675 "/proc/net/r8180/%s/stats-tx\n",
679 e = create_proc_read_entry("stats-ieee", S_IFREG | S_IRUGO,
680 priv->dir_dev, proc_get_stats_ieee, dev);
683 DMESGE("Unable to initialize "
684 "/proc/net/rtl8180/%s/stats-ieee\n",
689 e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO,
690 priv->dir_dev, proc_get_stats_ap, dev);
693 DMESGE("Unable to initialize "
694 "/proc/net/rtl8180/%s/stats-ap\n",
699 e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
700 priv->dir_dev, proc_get_registers, dev);
703 DMESGE("Unable to initialize "
704 "/proc/net/r8180/%s/registers\n",
708 /****************************************************************************
709 -----------------------------MISC STUFF-------------------------
710 *****************************************************************************/
712 FIXME: check if we can use some standard already-existent
713 data type+functions in kernel
716 short buffer_add(struct buffer **buffer, u32 *buf, dma_addr_t dma,
717 struct buffer **bufferhead)
720 DMESG("adding buffer to TX/RX struct");
727 *buffer = kmalloc(sizeof(struct buffer),GFP_KERNEL);
729 if (*buffer == NULL) {
730 DMESGE("Failed to kmalloc head of TX/RX struct");
733 (*buffer)->next=*buffer;
736 if(bufferhead !=NULL)
737 (*bufferhead) = (*buffer);
742 while(tmp->next!=(*buffer)) tmp=tmp->next;
743 if ((tmp->next= kmalloc(sizeof(struct buffer),GFP_KERNEL)) == NULL){
744 DMESGE("Failed to kmalloc TX/RX struct");
749 tmp->next->next=*buffer;
755 void buffer_free(struct net_device *dev,struct buffer **buffer,int len,short
759 struct buffer *tmp,*next;
760 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
761 struct pci_dev *pdev=priv->pdev;
764 if(! *buffer) return;
766 /*for(tmp=*buffer; tmp->next != *buffer; tmp=tmp->next)
773 pci_free_consistent(pdev,len,
776 pci_unmap_single(pdev, tmp->dma,
777 len,PCI_DMA_FROMDEVICE);
783 while(next != *buffer);
789 void print_buffer(u32 *buffer, int len)
792 u8 *buf =(u8*)buffer;
794 printk("ASCII BUFFER DUMP (len: %x):\n",len);
799 printk("\nBINARY BUFFER DUMP (len: %x):\n",len);
802 printk("%02x",buf[i]);
808 int get_curr_tx_free_desc(struct net_device *dev, int priority)
810 struct r8180_priv *priv = ieee80211_priv(dev);
816 case MANAGE_PRIORITY:
817 head = priv->txmapringhead;
818 tail = priv->txmapringtail;
821 head = priv->txbkpringhead;
822 tail = priv->txbkpringtail;
825 head = priv->txbepringhead;
826 tail = priv->txbepringtail;
829 head = priv->txvipringhead;
830 tail = priv->txvipringtail;
833 head = priv->txvopringhead;
834 tail = priv->txvopringtail;
837 head = priv->txhpringhead;
838 tail = priv->txhpringtail;
844 //DMESG("%x %x", head, tail);
846 /* FIXME FIXME FIXME FIXME */
849 if( head <= tail ) return priv->txringcount-1 - (tail - head)/8;
850 return (head - tail)/8/4;
853 ret = priv->txringcount - (tail - head)/8;
855 ret = (head - tail)/8;
857 if(ret > priv->txringcount ) DMESG("BUG");
863 short check_nic_enought_desc(struct net_device *dev, int priority)
865 struct r8180_priv *priv = ieee80211_priv(dev);
866 struct ieee80211_device *ieee = netdev_priv(dev);
868 int requiredbyte, required;
869 requiredbyte = priv->ieee80211->fts + sizeof(struct ieee80211_header_data);
871 if(ieee->current_network.QoS_Enable) {
875 required = requiredbyte / (priv->txbuffsize-4);
876 if (requiredbyte % priv->txbuffsize) required++;
877 /* for now we keep two free descriptor as a safety boundary
878 * between the tail and the head
881 return (required+2 < get_curr_tx_free_desc(dev,priority));
885 /* This function is only for debuging purpose */
886 void check_tx_ring(struct net_device *dev, int pri)
888 static int maxlog =3;
889 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
898 struct buffer* buffer;
901 if (maxlog <0 ) return;
904 case MANAGE_PRIORITY:
905 tail = priv->txmapringtail;
906 begin = priv->txmapring;
907 head = priv->txmapringhead;
908 nic = read_nic_dword(dev,TX_MANAGEPRIORITY_RING_ADDR);
909 buffer = priv->txmapbufs;
910 nicbegin = priv->txmapringdma;
915 tail = priv->txbkpringtail;
916 begin = priv->txbkpring;
917 head = priv->txbkpringhead;
918 nic = read_nic_dword(dev,TX_BKPRIORITY_RING_ADDR);
919 buffer = priv->txbkpbufs;
920 nicbegin = priv->txbkpringdma;
924 tail = priv->txbepringtail;
925 begin = priv->txbepring;
926 head = priv->txbepringhead;
927 nic = read_nic_dword(dev,TX_BEPRIORITY_RING_ADDR);
928 buffer = priv->txbepbufs;
929 nicbegin = priv->txbepringdma;
933 tail = priv->txvipringtail;
934 begin = priv->txvipring;
935 head = priv->txvipringhead;
936 nic = read_nic_dword(dev,TX_VIPRIORITY_RING_ADDR);
937 buffer = priv->txvipbufs;
938 nicbegin = priv->txvipringdma;
943 tail = priv->txvopringtail;
944 begin = priv->txvopring;
945 head = priv->txvopringhead;
946 nic = read_nic_dword(dev,TX_VOPRIORITY_RING_ADDR);
947 buffer = priv->txvopbufs;
948 nicbegin = priv->txvopringdma;
952 tail = priv->txhpringtail;
953 begin = priv->txhpring;
954 head = priv->txhpringhead;
955 nic = read_nic_dword(dev,TX_HIGHPRIORITY_RING_ADDR);
956 buffer = priv->txhpbufs;
957 nicbegin = priv->txhpringdma;
966 DMESGE ("NIC TX ack, but TX queue corrupted!");
969 for(i=0,buf=buffer, tmp=begin;
970 tmp<begin+(priv->txringcount)*8;
971 tmp+=8,buf=buf->next,i++)
973 DMESG("BUF%d %s %x %s. Next : %x",i,
974 *tmp & (1<<31) ? "filled" : "empty",
976 *tmp & (1<<15)? "ok": "err", *(tmp+4));
984 /* this function is only for debugging purpose */
985 void check_rxbuf(struct net_device *dev)
987 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
992 #ifdef CONFIG_RTL8185B
999 DMESGE ("NIC RX ack, but RX queue corrupted!");
1003 for(buf=priv->rxbuffer, tmp=priv->rxring;
1004 tmp < priv->rxring+(priv->rxringcount)*rx_desc_size;
1005 tmp+=rx_desc_size, buf=buf->next)
1008 *tmp & (1<<31) ? "empty" : "filled",
1016 void dump_eprom(struct net_device *dev)
1020 DMESG("EEPROM addr %x : %x", i, eprom_read(dev,i));
1024 void rtl8180_dump_reg(struct net_device *dev)
1030 DMESG("Dumping NIC register map");
1034 printk( "\nD: %2x> ", n);
1035 for(i=0;i<16 && n<=max;i++,n++)
1036 printk("%2x ",read_nic_byte(dev,n));
1042 void fix_tx_fifo(struct net_device *dev)
1044 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1047 #ifdef DEBUG_TX_ALLOC
1048 DMESG("FIXING TX FIFOs");
1050 for (tmp=priv->txmapring, i=0;
1051 i < priv->txringcount;
1053 *tmp = *tmp &~ (1<<31);
1056 for (tmp=priv->txbkpring, i=0;
1057 i < priv->txringcount;
1059 *tmp = *tmp &~ (1<<31);
1062 for (tmp=priv->txbepring, i=0;
1063 i < priv->txringcount;
1065 *tmp = *tmp &~ (1<<31);
1067 for (tmp=priv->txvipring, i=0;
1068 i < priv->txringcount;
1070 *tmp = *tmp &~ (1<<31);
1073 for (tmp=priv->txvopring, i=0;
1074 i < priv->txringcount;
1076 *tmp = *tmp &~ (1<<31);
1079 for (tmp=priv->txhpring, i=0;
1080 i < priv->txringcount;
1082 *tmp = *tmp &~ (1<<31);
1085 for (tmp=priv->txbeaconring, i=0;
1086 i < priv->txbeaconcount;
1088 *tmp = *tmp &~ (1<<31);
1090 #ifdef DEBUG_TX_ALLOC
1091 DMESG("TX FIFOs FIXED");
1093 priv->txmapringtail = priv->txmapring;
1094 priv->txmapringhead = priv->txmapring;
1095 priv->txmapbufstail = priv->txmapbufs;
1097 priv->txbkpringtail = priv->txbkpring;
1098 priv->txbkpringhead = priv->txbkpring;
1099 priv->txbkpbufstail = priv->txbkpbufs;
1101 priv->txbepringtail = priv->txbepring;
1102 priv->txbepringhead = priv->txbepring;
1103 priv->txbepbufstail = priv->txbepbufs;
1105 priv->txvipringtail = priv->txvipring;
1106 priv->txvipringhead = priv->txvipring;
1107 priv->txvipbufstail = priv->txvipbufs;
1109 priv->txvopringtail = priv->txvopring;
1110 priv->txvopringhead = priv->txvopring;
1111 priv->txvopbufstail = priv->txvopbufs;
1113 priv->txhpringtail = priv->txhpring;
1114 priv->txhpringhead = priv->txhpring;
1115 priv->txhpbufstail = priv->txhpbufs;
1117 priv->txbeaconringtail = priv->txbeaconring;
1118 priv->txbeaconbufstail = priv->txbeaconbufs;
1119 set_nic_txring(dev);
1121 ieee80211_reset_queue(priv->ieee80211);
1122 priv->ack_tx_to_ieee = 0;
1126 void fix_rx_fifo(struct net_device *dev)
1128 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1130 struct buffer *rxbuf;
1133 #ifdef CONFIG_RTL8185B
1134 rx_desc_size = 8; // 4*8 = 32 bytes
1139 #ifdef DEBUG_RXALLOC
1140 DMESG("FIXING RX FIFO");
1144 for (tmp=priv->rxring, rxbuf=priv->rxbufferhead;
1145 (tmp < (priv->rxring)+(priv->rxringcount)*rx_desc_size);
1146 tmp+=rx_desc_size,rxbuf=rxbuf->next){
1147 *(tmp+2) = rxbuf->dma;
1149 *tmp=*tmp | priv->rxbuffersize;
1153 #ifdef DEBUG_RXALLOC
1154 DMESG("RX FIFO FIXED");
1158 priv->rxringtail=priv->rxring;
1159 priv->rxbuffer=priv->rxbufferhead;
1160 priv->rx_skb_complete=1;
1161 set_nic_rxring(dev);
1165 /****************************************************************************
1166 ------------------------------HW STUFF---------------------------
1167 *****************************************************************************/
1169 unsigned char QUALITY_MAP[] = {
1170 0x64, 0x64, 0x64, 0x63, 0x63, 0x62, 0x62, 0x61,
1171 0x61, 0x60, 0x60, 0x5f, 0x5f, 0x5e, 0x5d, 0x5c,
1172 0x5b, 0x5a, 0x59, 0x57, 0x56, 0x54, 0x52, 0x4f,
1173 0x4c, 0x49, 0x45, 0x41, 0x3c, 0x37, 0x31, 0x29,
1174 0x24, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
1175 0x22, 0x22, 0x21, 0x21, 0x21, 0x21, 0x21, 0x20,
1176 0x20, 0x20, 0x20, 0x1f, 0x1f, 0x1e, 0x1e, 0x1e,
1177 0x1d, 0x1d, 0x1c, 0x1c, 0x1b, 0x1a, 0x19, 0x19,
1178 0x18, 0x17, 0x16, 0x15, 0x14, 0x12, 0x11, 0x0f,
1179 0x0e, 0x0c, 0x0a, 0x08, 0x06, 0x04, 0x01, 0x00
1182 unsigned char STRENGTH_MAP[] = {
1183 0x64, 0x64, 0x63, 0x62, 0x61, 0x60, 0x5f, 0x5e,
1184 0x5d, 0x5c, 0x5b, 0x5a, 0x57, 0x54, 0x52, 0x50,
1185 0x4e, 0x4c, 0x4a, 0x48, 0x46, 0x44, 0x41, 0x3f,
1186 0x3c, 0x3a, 0x37, 0x36, 0x36, 0x1c, 0x1c, 0x1b,
1187 0x1b, 0x1a, 0x1a, 0x19, 0x19, 0x18, 0x18, 0x17,
1188 0x17, 0x16, 0x16, 0x15, 0x15, 0x14, 0x14, 0x13,
1189 0x13, 0x12, 0x12, 0x11, 0x11, 0x10, 0x10, 0x0f,
1190 0x0f, 0x0e, 0x0e, 0x0d, 0x0d, 0x0c, 0x0c, 0x0b,
1191 0x0b, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x07,
1192 0x07, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x00
1195 void rtl8180_RSSI_calc(struct net_device *dev, u8 *rssi, u8 *qual){
1196 //void Mlme_UpdateRssiSQ(struct net_device *dev, u8 *rssi, u8 *qual){
1197 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1208 _rssi = 0; // avoid gcc complains..
1211 temp = QUALITY_MAP[q];
1223 switch(priv->rf_chip){
1227 if ( !lsb || !(temp2 <= 0x3c) ) {
1230 temp2 = 100 * temp2 / 0x3c;
1232 *rssi = temp2 & 0xff;
1233 _rssi = temp2 & 0xff;
1235 case RFCHIPID_INTERSIL:
1237 temp2 &= 0xfffffffe;
1246 if ( temp2 <= 0x3e0000 ) {
1247 if ( temp2 < 0xffef0000 )
1261 temp3 = temp3 / 0x6d;
1263 _rssi = temp3 & 0xff;
1264 *rssi = temp3 & 0xff;
1269 if ( ! lsb || !(temp2 <= 0x3c) ){
1272 temp2 = (100 * temp2) / 0x3c;
1274 *rssi = temp2 & 0xff;
1275 _rssi = temp2 & 0xff;
1277 case RFCHIPID_PHILIPS:
1278 if( orig_qual <= 0x4e ){
1279 _rssi = STRENGTH_MAP[orig_qual];
1294 case RFCHIPID_MAXIM:
1302 *rssi = temp2 & 0xff;
1303 _rssi = temp2 & 0xff;
1307 if ( _rssi < 0x64 ){
1319 void rtl8180_irq_enable(struct net_device *dev)
1321 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1322 priv->irq_enabled = 1;
1324 write_nic_word(dev,INTA_MASK,INTA_RXOK | INTA_RXDESCERR | INTA_RXOVERFLOW |\
1325 INTA_TXOVERFLOW | INTA_HIPRIORITYDESCERR | INTA_HIPRIORITYDESCOK |\
1326 INTA_NORMPRIORITYDESCERR | INTA_NORMPRIORITYDESCOK |\
1327 INTA_LOWPRIORITYDESCERR | INTA_LOWPRIORITYDESCOK | INTA_TIMEOUT);
1329 write_nic_word(dev,INTA_MASK, priv->irq_mask);
1333 void rtl8180_irq_disable(struct net_device *dev)
1335 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1337 #ifdef CONFIG_RTL8185B
1338 write_nic_dword(dev,IMR,0);
1340 write_nic_word(dev,INTA_MASK,0);
1342 force_pci_posting(dev);
1343 priv->irq_enabled = 0;
1347 void rtl8180_set_mode(struct net_device *dev,int mode)
1350 ecmd=read_nic_byte(dev, EPROM_CMD);
1351 ecmd=ecmd &~ EPROM_CMD_OPERATING_MODE_MASK;
1352 ecmd=ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
1353 ecmd=ecmd &~ (1<<EPROM_CS_SHIFT);
1354 ecmd=ecmd &~ (1<<EPROM_CK_SHIFT);
1355 write_nic_byte(dev, EPROM_CMD, ecmd);
1358 void rtl8180_adapter_start(struct net_device *dev);
1359 void rtl8180_beacon_tx_enable(struct net_device *dev);
1361 void rtl8180_update_msr(struct net_device *dev)
1363 struct r8180_priv *priv = ieee80211_priv(dev);
1367 msr = read_nic_byte(dev, MSR);
1368 msr &= ~ MSR_LINK_MASK;
1370 rxconf=read_nic_dword(dev,RX_CONF);
1372 if(priv->ieee80211->state == IEEE80211_LINKED)
1374 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1375 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
1376 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
1377 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
1378 else if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
1379 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
1381 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
1382 rxconf |= (1<<RX_CHECK_BSSID_SHIFT);
1385 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
1386 rxconf &= ~(1<<RX_CHECK_BSSID_SHIFT);
1389 write_nic_byte(dev, MSR, msr);
1390 write_nic_dword(dev, RX_CONF, rxconf);
1396 void rtl8180_set_chan(struct net_device *dev,short ch)
1398 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1400 if((ch > 14) || (ch < 1))
1402 printk("In %s: Invalid chnanel %d\n", __func__, ch);
1407 //printk("in %s:channel is %d\n",__func__,ch);
1408 priv->rf_set_chan(dev,priv->chan);
1413 void rtl8180_rx_enable(struct net_device *dev)
1417 /* for now we accept data, management & ctl frame*/
1418 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1420 rxconf=read_nic_dword(dev,RX_CONF);
1421 rxconf = rxconf &~ MAC_FILTER_MASK;
1422 rxconf = rxconf | (1<<ACCEPT_MNG_FRAME_SHIFT);
1423 rxconf = rxconf | (1<<ACCEPT_DATA_FRAME_SHIFT);
1424 rxconf = rxconf | (1<<ACCEPT_BCAST_FRAME_SHIFT);
1425 rxconf = rxconf | (1<<ACCEPT_MCAST_FRAME_SHIFT);
1426 // rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
1427 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
1429 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
1430 dev->flags & IFF_PROMISC){
1431 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
1433 rxconf = rxconf | (1<<ACCEPT_NICMAC_FRAME_SHIFT);
1434 if(priv->card_8185 == 0)
1435 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
1438 /*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
1439 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
1440 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
1443 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
1444 rxconf = rxconf | (1<<ACCEPT_CTL_FRAME_SHIFT);
1445 rxconf = rxconf | (1<<ACCEPT_ICVERR_FRAME_SHIFT);
1446 rxconf = rxconf | (1<<ACCEPT_PWR_FRAME_SHIFT);
1449 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
1450 rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
1452 //if(!priv->card_8185){
1453 rxconf = rxconf &~ RX_FIFO_THRESHOLD_MASK;
1454 rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
1457 rxconf = rxconf | (1<<RX_AUTORESETPHY_SHIFT);
1458 rxconf = rxconf &~ MAX_RX_DMA_MASK;
1459 rxconf = rxconf | (MAX_RX_DMA_2048<<MAX_RX_DMA_SHIFT);
1461 //if(!priv->card_8185)
1462 rxconf = rxconf | RCR_ONLYERLPKT;
1464 rxconf = rxconf &~ RCR_CS_MASK;
1465 if(!priv->card_8185)
1466 rxconf |= (priv->rcr_csense<<RCR_CS_SHIFT);
1467 // rxconf &=~ 0xfff00000;
1468 // rxconf |= 0x90100000;//9014f76f;
1469 write_nic_dword(dev, RX_CONF, rxconf);
1474 DMESG("rxconf: %x %x",rxconf ,read_nic_dword(dev,RX_CONF));
1476 cmd=read_nic_byte(dev,CMD);
1477 write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
1479 /* In rtl8139 driver seems that DMA threshold has to be written
1480 * after enabling RX, so we rewrite RX_CONFIG register
1483 // write_nic_dword(dev, RX_CONF, rxconf);
1488 void set_nic_txring(struct net_device *dev)
1490 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1491 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1493 write_nic_dword(dev, TX_MANAGEPRIORITY_RING_ADDR, priv->txmapringdma);
1494 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1495 write_nic_dword(dev, TX_BKPRIORITY_RING_ADDR, priv->txbkpringdma);
1496 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1497 write_nic_dword(dev, TX_BEPRIORITY_RING_ADDR, priv->txbepringdma);
1498 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1499 write_nic_dword(dev, TX_VIPRIORITY_RING_ADDR, priv->txvipringdma);
1500 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1501 write_nic_dword(dev, TX_VOPRIORITY_RING_ADDR, priv->txvopringdma);
1502 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1503 write_nic_dword(dev, TX_HIGHPRIORITY_RING_ADDR, priv->txhpringdma);
1504 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1506 write_nic_dword(dev, TX_BEACON_RING_ADDR, priv->txbeaconringdma);
1510 void rtl8180_conttx_enable(struct net_device *dev)
1513 txconf = read_nic_dword(dev,TX_CONF);
1514 txconf = txconf &~ TX_LOOPBACK_MASK;
1515 txconf = txconf | (TX_LOOPBACK_CONTINUE <<TX_LOOPBACK_SHIFT);
1516 write_nic_dword(dev,TX_CONF,txconf);
1520 void rtl8180_conttx_disable(struct net_device *dev)
1523 txconf = read_nic_dword(dev,TX_CONF);
1524 txconf = txconf &~ TX_LOOPBACK_MASK;
1525 txconf = txconf | (TX_LOOPBACK_NONE <<TX_LOOPBACK_SHIFT);
1526 write_nic_dword(dev,TX_CONF,txconf);
1530 void rtl8180_tx_enable(struct net_device *dev)
1536 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1537 txconf= read_nic_dword(dev,TX_CONF);
1540 if(priv->card_8185){
1543 byte = read_nic_byte(dev,CW_CONF);
1544 byte &= ~(1<<CW_CONF_PERPACKET_CW_SHIFT);
1545 byte &= ~(1<<CW_CONF_PERPACKET_RETRY_SHIFT);
1546 write_nic_byte(dev, CW_CONF, byte);
1548 tx_agc_ctl = read_nic_byte(dev, TX_AGC_CTL);
1549 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_GAIN_SHIFT);
1550 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT);
1551 tx_agc_ctl |=(1<<TX_AGC_CTL_FEEDBACK_ANT);
1552 write_nic_byte(dev, TX_AGC_CTL, tx_agc_ctl);
1554 write_nic_word(dev, 0x5e, 0x01);
1555 force_pci_posting(dev);
1557 write_nic_word(dev, 0xfe, 0x10);
1558 force_pci_posting(dev);
1560 write_nic_word(dev, 0x5e, 0x00);
1561 force_pci_posting(dev);
1564 write_nic_byte(dev, 0xec, 0x3f); /* Disable early TX */
1567 if(priv->card_8185){
1569 txconf = txconf &~ (1<<TCR_PROBE_NOTIMESTAMP_SHIFT);
1574 txconf= txconf &~ (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
1576 txconf= txconf | (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
1579 txconf = txconf &~ TX_LOOPBACK_MASK;
1580 txconf = txconf | (TX_LOOPBACK_NONE <<TX_LOOPBACK_SHIFT);
1581 txconf = txconf &~ TCR_DPRETRY_MASK;
1582 txconf = txconf &~ TCR_RTSRETRY_MASK;
1583 txconf = txconf | (priv->retry_data<<TX_DPRETRY_SHIFT);
1584 txconf = txconf | (priv->retry_rts<<TX_RTSRETRY_SHIFT);
1585 txconf = txconf &~ (1<<TX_NOCRC_SHIFT);
1587 if(priv->card_8185){
1588 if(priv->hw_plcp_len)
1589 txconf = txconf &~ TCR_PLCP_LEN;
1591 txconf = txconf | TCR_PLCP_LEN;
1593 txconf = txconf &~ TCR_SAT;
1595 txconf = txconf &~ TCR_MXDMA_MASK;
1596 txconf = txconf | (TCR_MXDMA_2048<<TCR_MXDMA_SHIFT);
1597 txconf = txconf | TCR_CWMIN;
1598 txconf = txconf | TCR_DISCW;
1600 // if(priv->ieee80211->hw_wep)
1601 // txconf=txconf &~ (1<<TX_NOICV_SHIFT);
1603 txconf=txconf | (1<<TX_NOICV_SHIFT);
1605 write_nic_dword(dev,TX_CONF,txconf);
1611 DMESG("txconf: %x %x",txconf,read_nic_dword(dev,TX_CONF));
1614 cmd=read_nic_byte(dev,CMD);
1615 write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));
1618 write_nic_dword(dev,TX_CONF,txconf);
1621 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1622 write_nic_byte(dev, TX_DMA_POLLING, priv->dma_poll_mask);
1623 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1628 void rtl8180_beacon_tx_enable(struct net_device *dev)
1630 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1632 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1633 #ifdef CONFIG_RTL8185B
1634 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_BQ);
1635 write_nic_byte(dev,TPPollStop, priv->dma_poll_mask);
1637 priv->dma_poll_mask &=~(1<<TX_DMA_STOP_BEACON_SHIFT);
1638 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1640 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1644 void rtl8180_beacon_tx_disable(struct net_device *dev)
1646 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1648 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1649 #ifdef CONFIG_RTL8185B
1650 priv->dma_poll_stop_mask |= TPPOLLSTOP_BQ;
1651 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
1653 priv->dma_poll_mask |= (1<<TX_DMA_STOP_BEACON_SHIFT);
1654 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1656 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1661 void rtl8180_rtx_disable(struct net_device *dev)
1664 struct r8180_priv *priv = ieee80211_priv(dev);
1666 cmd=read_nic_byte(dev,CMD);
1667 write_nic_byte(dev, CMD, cmd &~ \
1668 ((1<<CMD_RX_ENABLE_SHIFT)|(1<<CMD_TX_ENABLE_SHIFT)));
1669 force_pci_posting(dev);
1671 /*while (read_nic_byte(dev,CMD) & (1<<CMD_RX_ENABLE_SHIFT))
1675 if(!priv->rx_skb_complete)
1676 dev_kfree_skb_any(priv->rx_skb);
1680 int alloc_tx_beacon_desc_ring(struct net_device *dev, int count)
1684 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1686 priv->txbeaconring = (u32*)pci_alloc_consistent(priv->pdev,
1687 sizeof(u32)*8*count,
1688 &priv->txbeaconringdma);
1689 if (!priv->txbeaconring) return -1;
1690 for (tmp=priv->txbeaconring,i=0;i<count;i++){
1691 *tmp = *tmp &~ (1<<31); // descriptor empty, owned by the drv
1693 *(tmp+2) = (u32)dma_tmp;
1697 *(tmp+4) = (u32)priv->txbeaconringdma+((i+1)*8*4);
1699 *(tmp+4) = (u32)priv->txbeaconringdma;
1707 short alloc_tx_desc_ring(struct net_device *dev, int bufsize, int count,
1713 dma_addr_t dma_desc, dma_tmp;
1714 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1715 struct pci_dev *pdev = priv->pdev;
1718 if((bufsize & 0xfff) != bufsize) {
1719 DMESGE ("TX buffer allocation too large");
1722 desc = (u32*)pci_alloc_consistent(pdev,
1723 sizeof(u32)*8*count+256, &dma_desc);
1724 if(desc==NULL) return -1;
1725 if(dma_desc & 0xff){
1728 * descriptor's buffer must be 256 byte aligned
1729 * we shouldn't be here, since we set DMA mask !
1731 WARN(1, "DMA buffer is not aligned\n");
1734 for (i=0;i<count;i++)
1736 buf = (void*)pci_alloc_consistent(pdev,bufsize,&dma_tmp);
1737 if (buf == NULL) return -ENOMEM;
1741 case TX_NORMPRIORITY_RING_ADDR:
1742 if(-1 == buffer_add(&(priv->txnpbufs),buf,dma_tmp,NULL)){
1743 DMESGE("Unable to allocate mem for buffer NP");
1748 case TX_LOWPRIORITY_RING_ADDR:
1749 if(-1 == buffer_add(&(priv->txlpbufs),buf,dma_tmp,NULL)){
1750 DMESGE("Unable to allocate mem for buffer LP");
1755 case TX_HIGHPRIORITY_RING_ADDR:
1756 if(-1 == buffer_add(&(priv->txhpbufs),buf,dma_tmp,NULL)){
1757 DMESGE("Unable to allocate mem for buffer HP");
1762 case TX_MANAGEPRIORITY_RING_ADDR:
1763 if(-1 == buffer_add(&(priv->txmapbufs),buf,dma_tmp,NULL)){
1764 DMESGE("Unable to allocate mem for buffer NP");
1769 case TX_BKPRIORITY_RING_ADDR:
1770 if(-1 == buffer_add(&(priv->txbkpbufs),buf,dma_tmp,NULL)){
1771 DMESGE("Unable to allocate mem for buffer LP");
1775 case TX_BEPRIORITY_RING_ADDR:
1776 if(-1 == buffer_add(&(priv->txbepbufs),buf,dma_tmp,NULL)){
1777 DMESGE("Unable to allocate mem for buffer NP");
1782 case TX_VIPRIORITY_RING_ADDR:
1783 if(-1 == buffer_add(&(priv->txvipbufs),buf,dma_tmp,NULL)){
1784 DMESGE("Unable to allocate mem for buffer LP");
1788 case TX_VOPRIORITY_RING_ADDR:
1789 if(-1 == buffer_add(&(priv->txvopbufs),buf,dma_tmp,NULL)){
1790 DMESGE("Unable to allocate mem for buffer NP");
1795 case TX_HIGHPRIORITY_RING_ADDR:
1796 if(-1 == buffer_add(&(priv->txhpbufs),buf,dma_tmp,NULL)){
1797 DMESGE("Unable to allocate mem for buffer HP");
1801 case TX_BEACON_RING_ADDR:
1802 if(-1 == buffer_add(&(priv->txbeaconbufs),buf,dma_tmp,NULL)){
1803 DMESGE("Unable to allocate mem for buffer BP");
1808 *tmp = *tmp &~ (1<<31); // descriptor empty, owned by the drv
1809 *(tmp+2) = (u32)dma_tmp;
1813 *(tmp+4) = (u32)dma_desc+((i+1)*8*4);
1815 *(tmp+4) = (u32)dma_desc;
1821 case TX_MANAGEPRIORITY_RING_ADDR:
1822 priv->txmapringdma=dma_desc;
1823 priv->txmapring=desc;
1826 case TX_BKPRIORITY_RING_ADDR:
1827 priv->txbkpringdma=dma_desc;
1828 priv->txbkpring=desc;
1831 case TX_BEPRIORITY_RING_ADDR:
1832 priv->txbepringdma=dma_desc;
1833 priv->txbepring=desc;
1836 case TX_VIPRIORITY_RING_ADDR:
1837 priv->txvipringdma=dma_desc;
1838 priv->txvipring=desc;
1841 case TX_VOPRIORITY_RING_ADDR:
1842 priv->txvopringdma=dma_desc;
1843 priv->txvopring=desc;
1846 case TX_HIGHPRIORITY_RING_ADDR:
1847 priv->txhpringdma=dma_desc;
1848 priv->txhpring=desc;
1851 case TX_BEACON_RING_ADDR:
1852 priv->txbeaconringdma=dma_desc;
1853 priv->txbeaconring=desc;
1859 DMESG("Tx dma physical address: %x",dma_desc);
1866 void free_tx_desc_rings(struct net_device *dev)
1869 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1870 struct pci_dev *pdev=priv->pdev;
1871 int count = priv->txringcount;
1873 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1874 priv->txmapring, priv->txmapringdma);
1875 buffer_free(dev,&(priv->txmapbufs),priv->txbuffsize,1);
1877 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1878 priv->txbkpring, priv->txbkpringdma);
1879 buffer_free(dev,&(priv->txbkpbufs),priv->txbuffsize,1);
1881 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1882 priv->txbepring, priv->txbepringdma);
1883 buffer_free(dev,&(priv->txbepbufs),priv->txbuffsize,1);
1885 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1886 priv->txvipring, priv->txvipringdma);
1887 buffer_free(dev,&(priv->txvipbufs),priv->txbuffsize,1);
1889 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1890 priv->txvopring, priv->txvopringdma);
1891 buffer_free(dev,&(priv->txvopbufs),priv->txbuffsize,1);
1893 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1894 priv->txhpring, priv->txhpringdma);
1895 buffer_free(dev,&(priv->txhpbufs),priv->txbuffsize,1);
1897 count = priv->txbeaconcount;
1898 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1899 priv->txbeaconring, priv->txbeaconringdma);
1900 buffer_free(dev,&(priv->txbeaconbufs),priv->txbuffsize,1);
1904 void free_beacon_desc_ring(struct net_device *dev,int count)
1907 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1908 struct pci_dev *pdev=priv->pdev;
1910 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1911 priv->txbeaconring, priv->txbeaconringdma);
1913 if (priv->beacon_buf)
1914 pci_free_consistent(priv->pdev,
1915 priv->master_beaconsize,priv->beacon_buf,priv->beacondmabuf);
1919 void free_rx_desc_ring(struct net_device *dev)
1921 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1922 struct pci_dev *pdev = priv->pdev;
1924 int count = priv->rxringcount;
1926 #ifdef CONFIG_RTL8185B
1927 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1928 priv->rxring, priv->rxringdma);
1930 pci_free_consistent(pdev, sizeof(u32)*4*count+256,
1931 priv->rxring, priv->rxringdma);
1934 buffer_free(dev,&(priv->rxbuffer),priv->rxbuffersize,0);
1938 short alloc_rx_desc_ring(struct net_device *dev, u16 bufsize, int count)
1943 dma_addr_t dma_desc,dma_tmp;
1944 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1945 struct pci_dev *pdev=priv->pdev;
1949 #ifdef CONFIG_RTL8185B
1950 rx_desc_size = 8; // 4*8 = 32 bytes
1955 if((bufsize & 0xfff) != bufsize){
1956 DMESGE ("RX buffer allocation too large");
1960 desc = (u32*)pci_alloc_consistent(pdev,sizeof(u32)*rx_desc_size*count+256,
1963 if(dma_desc & 0xff){
1966 * descriptor's buffer must be 256 byte aligned
1967 * should never happen since we specify the DMA mask
1969 WARN(1, "DMA buffer is not aligned\n");
1973 priv->rxringdma=dma_desc;
1976 for (i=0;i<count;i++){
1978 if ((buf= kmalloc(bufsize * sizeof(u8),GFP_ATOMIC)) == NULL){
1979 DMESGE("Failed to kmalloc RX buffer");
1983 dma_tmp = pci_map_single(pdev,buf,bufsize * sizeof(u8),
1984 PCI_DMA_FROMDEVICE);
1986 #ifdef DEBUG_ZERO_RX
1988 for(j=0;j<bufsize;j++) ((u8*)buf)[i] = 0;
1991 //buf = (void*)pci_alloc_consistent(pdev,bufsize,&dma_tmp);
1992 if(-1 == buffer_add(&(priv->rxbuffer), buf,dma_tmp,
1993 &(priv->rxbufferhead))){
1994 DMESGE("Unable to allocate mem RX buf");
1997 *tmp = 0; //zero pads the header of the descriptor
1998 *tmp = *tmp |( bufsize&0xfff);
1999 *(tmp+2) = (u32)dma_tmp;
2000 *tmp = *tmp |(1<<31); // descriptor void, owned by the NIC
2002 #ifdef DEBUG_RXALLOC
2003 DMESG("Alloc %x size buffer, DMA mem @ %x, virtual mem @ %x",
2004 (u32)(bufsize&0xfff), (u32)dma_tmp, (u32)buf);
2007 tmp=tmp+rx_desc_size;
2010 *(tmp-rx_desc_size) = *(tmp-rx_desc_size) | (1<<30); // this is the last descriptor
2013 #ifdef DEBUG_RXALLOC
2014 DMESG("RX DMA physical address: %x",dma_desc);
2021 void set_nic_rxring(struct net_device *dev)
2024 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2026 //rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
2028 pgreg=read_nic_byte(dev, PGSELECT);
2029 write_nic_byte(dev, PGSELECT, pgreg &~ (1<<PGSELECT_PG_SHIFT));
2031 //rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2033 write_nic_dword(dev, RXRING_ADDR,priv->rxringdma);
2037 void rtl8180_reset(struct net_device *dev)
2039 //u32 txconf = 0x80e00707; //FIXME: Make me understandable
2042 //write_nic_dword(dev,TX_CONF,txconf);
2044 rtl8180_irq_disable(dev);
2046 cr=read_nic_byte(dev,CMD);
2048 cr = cr | (1<<CMD_RST_SHIFT);
2049 write_nic_byte(dev,CMD,cr);
2051 force_pci_posting(dev);
2055 if(read_nic_byte(dev,CMD) & (1<<CMD_RST_SHIFT))
2056 DMESGW("Card reset timeout!");
2058 DMESG("Card successfully reset");
2060 //#ifndef CONFIG_RTL8185B
2061 rtl8180_set_mode(dev,EPROM_CMD_LOAD);
2062 force_pci_posting(dev);
2067 inline u16 ieeerate2rtlrate(int rate)
2100 static u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540,720};
2101 inline u16 rtl8180_rate2rate(short rate)
2103 if (rate >12) return 10;
2104 return rtl_rate[rate];
2106 inline u8 rtl8180_IsWirelessBMode(u16 rate)
2108 if( ((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220) )
2112 u16 N_DBPSOfRate(u16 DataRate);
2116 u8 bManagementFrame,
2124 if( rtl8180_IsWirelessBMode(DataRate) )
2126 if( bManagementFrame || !bShortPreamble || DataRate == 10 )
2128 FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
2132 FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
2134 if( ( FrameLength*8 % (DataRate/10) ) != 0 ) //Get the Ceilling
2136 } else { //802.11g DSSS-OFDM PLCP length field calculation.
2137 N_DBPS = N_DBPSOfRate(DataRate);
2138 Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
2139 + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
2140 FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
2144 u16 N_DBPSOfRate(u16 DataRate)
2192 // For Netgear case, they want good-looking singal strength.
2193 // 2004.12.05, by rcnjko.
2196 NetgearSignalStrengthTranslate(
2203 // Step 1. Scale mapping.
2204 if(CurrSS >= 71 && CurrSS <= 100)
2206 RetSS = 90 + ((CurrSS - 70) / 3);
2208 else if(CurrSS >= 41 && CurrSS <= 70)
2210 RetSS = 78 + ((CurrSS - 40) / 3);
2212 else if(CurrSS >= 31 && CurrSS <= 40)
2214 RetSS = 66 + (CurrSS - 30);
2216 else if(CurrSS >= 21 && CurrSS <= 30)
2218 RetSS = 54 + (CurrSS - 20);
2220 else if(CurrSS >= 5 && CurrSS <= 20)
2222 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2224 else if(CurrSS == 4)
2228 else if(CurrSS == 3)
2232 else if(CurrSS == 2)
2236 else if(CurrSS == 1)
2244 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2246 // Step 2. Smoothing.
2249 RetSS = ((LastSS * 5) + (RetSS)+ 5) / 6;
2251 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2257 // Translate 0-100 signal strength index into dBm.
2261 u8 SignalStrengthIndex // 0-100 index.
2264 long SignalPower; // in dBm.
2266 // Translate to dBm (x=0.5y-95).
2267 SignalPower = (long)((SignalStrengthIndex + 1) >> 1);
2274 // Perform signal smoothing for dynamic mechanism.
2275 // This is different with PerformSignalSmoothing8185 in smoothing fomula.
2276 // No dramatic adjustion is apply because dynamic mechanism need some degree
2277 // of correctness. Ported from 8187B.
2278 // 2007-02-26, by Bruce.
2281 PerformUndecoratedSignalSmoothing8185(
2282 struct r8180_priv *priv,
2288 // Determin the current packet is CCK rate.
2289 priv->bCurCCKPkt = bCckRate;
2291 if(priv->UndecoratedSmoothedSS >= 0)
2293 priv->UndecoratedSmoothedSS = ( (priv->UndecoratedSmoothedSS * 5) + (priv->SignalStrength * 10) ) / 6;
2297 priv->UndecoratedSmoothedSS = priv->SignalStrength * 10;
2300 priv->UndercorateSmoothedRxPower = ( (priv->UndercorateSmoothedRxPower * 50) + (priv->RxPower* 11)) / 60;
2302 // printk("Sommthing SignalSterngth (%d) => UndecoratedSmoothedSS (%d)\n", priv->SignalStrength, priv->UndecoratedSmoothedSS);
2303 // printk("Sommthing RxPower (%d) => UndecoratedRxPower (%d)\n", priv->RxPower, priv->UndercorateSmoothedRxPower);
2305 //if(priv->CurCCKRSSI >= 0 && bCckRate)
2308 priv->CurCCKRSSI = priv->RSSI;
2312 priv->CurCCKRSSI = 0;
2315 // Boundary checking.
2316 // TODO: The overflow condition does happen, if we want to fix,
2317 // we shall recalculate thresholds first.
2318 if(priv->UndecoratedSmoothedSS > 100)
2320 // printk("UndecoratedSmoothedSS(%d) overflow, SignalStrength(%d)\n", priv->UndecoratedSmoothedSS, priv->SignalStrength);
2322 if(priv->UndecoratedSmoothedSS < 0)
2324 // printk("UndecoratedSmoothedSS(%d) underflow, SignalStrength(%d)\n", priv->UndecoratedSmoothedSS, priv->SignalStrength);
2331 /* This is rough RX isr handling routine*/
2332 void rtl8180_rx(struct net_device *dev)
2334 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2335 struct sk_buff *tmp_skb;
2337 //struct sk_buff *skb;
2341 unsigned char quality, signal;
2352 u8 LNA_gain[4]={02, 17, 29, 39};
2354 struct ieee80211_hdr *hdr;//by amy
2356 u8 bHwError = 0,bCRC = 0,bICV = 0;
2360 bool bCckRate = false;
2362 long SignalStrengthIndex = 0;//+by amy 080312
2363 // u8 SignalStrength = 0;
2364 struct ieee80211_rx_stats stats = {
2368 // .mac_time = jiffies,
2369 .freq = IEEE80211_24GHZ_BAND,
2372 #ifdef CONFIG_RTL8185B
2373 stats.nic_type = NIC_8185B;
2377 stats.nic_type = NIC_8185;
2380 //printk("receive frame!%d\n",count++);
2381 //if (!priv->rxbuffer) DMESG ("EE: NIC RX ack, but RX queue corrupted!");
2384 if ((*(priv->rxringtail)) & (1<<31)) {
2386 /* we have got an RX int, but the descriptor
2387 * we are pointing is empty*/
2389 priv->stats.rxnodata++;
2390 priv->ieee80211->stats.rx_errors++;
2392 /* if (! *(priv->rxring) & (1<<31)) {
2394 priv->stats.rxreset++;
2395 priv->rxringtail=priv->rxring;
2396 priv->rxbuffer=priv->rxbufferhead;
2401 /* Maybe it is possible that the NIC has skipped some descriptors or
2402 * it has reset its internal pointer to the beginning of the ring
2403 * we search for the first filled descriptor in the ring, or we break
2404 * putting again the pointer in the old location if we do not found any.
2405 * This is quite dangerous, what does happen if the nic writes
2406 * two descriptor (say A and B) when we have just checked the descriptor
2407 * A and we are going to check the descriptor B..This might happen if the
2408 * interrupt was dummy, there was not really filled descriptors and
2409 * the NIC didn't lose pointer
2412 //priv->stats.rxwrkaround++;
2414 tmp = priv->rxringtail;
2415 while (*(priv->rxringtail) & (1<<31)){
2417 priv->rxringtail+=4;
2419 if(priv->rxringtail >=
2420 (priv->rxring)+(priv->rxringcount )*4)
2421 priv->rxringtail=priv->rxring;
2423 priv->rxbuffer=(priv->rxbuffer->next);
2425 if(priv->rxringtail == tmp ){
2426 //DMESG("EE: Could not find RX pointer");
2427 priv->stats.rxnopointer++;
2434 tmp = priv->rxringtail;
2436 if(tmp == priv->rxring)
2437 //tmp = priv->rxring + (priv->rxringcount )*rx_desc_size; xiong-2006-11-15
2438 tmp = priv->rxring + (priv->rxringcount - 1)*rx_desc_size;
2440 tmp -= rx_desc_size;
2442 if(! (*tmp & (1<<31)))
2444 }while(tmp != priv->rxring);
2446 if(tmp2) priv->rxringtail = tmp2;
2451 /* while there are filled descriptors */
2452 while(!(*(priv->rxringtail) & (1<<31))){
2453 if(*(priv->rxringtail) & (1<<26))
2454 DMESGW("RX buffer overflow");
2455 if(*(priv->rxringtail) & (1<<12))
2456 priv->stats.rxicverr++;
2458 if(*(priv->rxringtail) & (1<<27)){
2459 priv->stats.rxdmafail++;
2460 //DMESG("EE: RX DMA FAILED at buffer pointed by descriptor %x",(u32)priv->rxringtail);
2464 pci_dma_sync_single_for_cpu(priv->pdev,
2465 priv->rxbuffer->dma,
2466 priv->rxbuffersize * \
2468 PCI_DMA_FROMDEVICE);
2470 first = *(priv->rxringtail) & (1<<29) ? 1:0;
2471 if(first) priv->rx_prevlen=0;
2473 last = *(priv->rxringtail) & (1<<28) ? 1:0;
2475 lastlen=((*priv->rxringtail) &0xfff);
2477 /* if the last descriptor (that should
2478 * tell us the total packet len) tell
2479 * us something less than the descriptors
2480 * len we had until now, then there is some
2482 * workaround to prevent kernel panic
2484 if(lastlen < priv->rx_prevlen)
2487 len=lastlen-priv->rx_prevlen;
2489 if(*(priv->rxringtail) & (1<<13)) {
2490 //lastlen=((*priv->rxringtail) &0xfff);
2491 if ((*(priv->rxringtail) & 0xfff) <500)
2492 priv->stats.rxcrcerrmin++;
2493 else if ((*(priv->rxringtail) & 0x0fff) >1000)
2494 priv->stats.rxcrcerrmax++;
2496 priv->stats.rxcrcerrmid++;
2501 len = priv->rxbuffersize;
2504 #ifdef CONFIG_RTL8185B
2506 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
2508 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
2515 #ifdef CONFIG_RTL818X_S
2519 priv->rx_prevlen+=len;
2521 if(priv->rx_prevlen > MAX_FRAG_THRESHOLD + 100){
2522 /* HW is probably passing several buggy frames
2523 * without FD or LD flag set.
2524 * Throw this garbage away to prevent skb
2527 if(!priv->rx_skb_complete)
2528 dev_kfree_skb_any(priv->rx_skb);
2529 priv->rx_skb_complete = 1;
2532 #ifdef DEBUG_RX_FRAG
2533 DMESG("Iteration.. len %x",len);
2534 if(first) DMESG ("First descriptor");
2535 if(last) DMESG("Last descriptor");
2538 #ifdef DEBUG_RX_VERBOSE
2539 print_buffer( priv->rxbuffer->buf, len);
2542 #ifdef CONFIG_RTL8185B
2543 signal=(unsigned char)(((*(priv->rxringtail+3))& (0x00ff0000))>>16);
2544 signal=(signal&0xfe)>>1; // Modify by hikaru 6.6
2546 quality=(unsigned char)((*(priv->rxringtail+3)) & (0xff));
2548 stats.mac_time[0] = *(priv->rxringtail+1);
2549 stats.mac_time[1] = *(priv->rxringtail+2);
2550 rxpower =((char)(((*(priv->rxringtail+4))& (0x00ff0000))>>16))/2 - 42;
2551 RSSI = ((u8)(((*(priv->rxringtail+3)) & (0x0000ff00))>> 8)) & (0x7f);
2554 signal=((*(priv->rxringtail+1))& (0xff0000))>>16;
2555 signal=(signal&0xfe)>>1; // Modify by hikaru 6.6
2557 quality=((*(priv->rxringtail+1)) & (0xff));
2559 stats.mac_time[0] = *(priv->rxringtail+2);
2560 stats.mac_time[1] = *(priv->rxringtail+3);
2562 rate=((*(priv->rxringtail)) &
2563 ((1<<23)|(1<<22)|(1<<21)|(1<<20)))>>20;
2565 stats.rate = rtl8180_rate2rate(rate);
2567 Antenna = (((*(priv->rxringtail +3))& (0x00008000)) == 0 )? 0:1 ;
2568 // printk("in rtl8180_rx():Antenna is %d\n",Antenna);
2569 //by amy for antenna
2570 if(!rtl8180_IsWirelessBMode(stats.rate))
2573 RxAGC_dBm = rxpower+1; //bias
2577 RxAGC_dBm = signal;//bit 0 discard
2579 LNA = (u8) (RxAGC_dBm & 0x60 ) >> 5 ; //bit 6~ bit 5
2580 BB = (u8) (RxAGC_dBm & 0x1F); // bit 4 ~ bit 0
2582 RxAGC_dBm = -( LNA_gain[LNA] + (BB *2) ); //Pin_11b=-(LNA_gain+BB_gain) (dBm)
2584 RxAGC_dBm +=4; //bias
2587 if(RxAGC_dBm & 0x80) //absolute value
2588 RXAGC= ~(RxAGC_dBm)+1;
2589 bCckRate = rtl8180_IsWirelessBMode(stats.rate);
2590 // Translate RXAGC into 1-100.
2591 if(!rtl8180_IsWirelessBMode(stats.rate))
2597 RXAGC=(90-RXAGC)*100/65;
2605 RXAGC=(95-RXAGC)*100/65;
2607 priv->SignalStrength = (u8)RXAGC;
2608 priv->RecvSignalPower = RxAGC_dBm ; // It can use directly by SD3 CMLin
2609 priv->RxPower = rxpower;
2612 // SQ translation formular is provided by SD3 DZ. 2006.06.27, by rcnjko.
2614 quality = 1;//0; //0 will cause epc to show signal zero , walk aroud now;
2615 else if(quality < 27)
2618 quality = 127 - quality;
2619 priv->SignalQuality = quality;
2620 if(!priv->card_8185)
2621 printk("check your card type\n");
2623 stats.signal = (u8)quality;//priv->wstats.qual.level = priv->SignalStrength;
2624 stats.signalstrength = RXAGC;
2625 if(stats.signalstrength > 100)
2626 stats.signalstrength = 100;
2627 stats.signalstrength = (stats.signalstrength * 70)/100 + 30;
2628 // printk("==========================>rx : RXAGC is %d,signalstrength is %d\n",RXAGC,stats.signalstrength);
2629 stats.rssi = priv->wstats.qual.qual = priv->SignalQuality;
2630 stats.noise = priv->wstats.qual.noise = 100 - priv ->wstats.qual.qual;
2632 bHwError = (((*(priv->rxringtail))& (0x00000fff)) == 4080)| (((*(priv->rxringtail))& (0x04000000)) != 0 )
2633 | (((*(priv->rxringtail))& (0x08000000)) != 0 )| (((~(*(priv->rxringtail)))& (0x10000000)) != 0 )| (((~(*(priv->rxringtail)))& (0x20000000)) != 0 );
2634 bCRC = ((*(priv->rxringtail)) & (0x00002000)) >> 13;
2635 bICV = ((*(priv->rxringtail)) & (0x00001000)) >> 12;
2636 hdr = (struct ieee80211_hdr *)priv->rxbuffer->buf;
2637 fc = le16_to_cpu(hdr->frame_ctl);
2638 type = WLAN_FC_GET_TYPE(fc);
2640 if((IEEE80211_FTYPE_CTL != type) &&
2641 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3))
2642 && (!bHwError) && (!bCRC)&& (!bICV))
2645 // Perform signal smoothing for dynamic mechanism on demand.
2646 // This is different with PerformSignalSmoothing8185 in smoothing fomula.
2647 // No dramatic adjustion is apply because dynamic mechanism need some degree
2648 // of correctness. 2007.01.23, by shien chang.
2649 PerformUndecoratedSignalSmoothing8185(priv,bCckRate);
2651 // For good-looking singal strength.
2653 SignalStrengthIndex = NetgearSignalStrengthTranslate(
2654 priv->LastSignalStrengthInPercent,
2655 priv->SignalStrength);
2657 priv->LastSignalStrengthInPercent = SignalStrengthIndex;
2658 priv->Stats_SignalStrength = TranslateToDbm8185((u8)SignalStrengthIndex);
2660 // We need more correct power of received packets and the "SignalStrength" of RxStats is beautified,
2661 // so we record the correct power here.
2663 priv->Stats_SignalQuality =(long) (priv->Stats_SignalQuality * 5 + (long)priv->SignalQuality + 5) / 6;
2664 priv->Stats_RecvSignalPower = (long)(priv->Stats_RecvSignalPower * 5 + priv->RecvSignalPower -1) / 6;
2666 // Figure out which antenna that received the lasted packet.
2667 priv->LastRxPktAntenna = Antenna ? 1 : 0; // 0: aux, 1: main.
2669 SwAntennaDiversityRxOk8185(dev, priv->SignalStrength);
2672 //by amy for antenna
2681 if(!priv->rx_skb_complete){
2682 /* seems that HW sometimes fails to reiceve and
2683 doesn't provide the last descriptor */
2685 DMESG("going to free incomplete skb");
2687 dev_kfree_skb_any(priv->rx_skb);
2688 priv->stats.rxnolast++;
2690 DMESG("free incomplete skb OK");
2693 /* support for prism header has been originally added by Christian */
2694 if(priv->prism_hdr && priv->ieee80211->iw_mode == IW_MODE_MONITOR){
2697 priv->rx_skb = dev_alloc_skb(len+2+PRISM_HDR_SIZE);
2698 if(! priv->rx_skb) goto drop;
2700 prism_hdr = (u32*) skb_put(priv->rx_skb,PRISM_HDR_SIZE);
2701 prism_hdr[0]=htonl(0x80211001); //version
2702 prism_hdr[1]=htonl(0x40); //length
2703 prism_hdr[2]=htonl(stats.mac_time[1]); //mactime (HIGH)
2704 prism_hdr[3]=htonl(stats.mac_time[0]); //mactime (LOW)
2705 rdtsc(prism_hdr[5], prism_hdr[4]); //hostime (LOW+HIGH)
2706 prism_hdr[4]=htonl(prism_hdr[4]); //Byte-Order aendern
2707 prism_hdr[5]=htonl(prism_hdr[5]); //Byte-Order aendern
2708 prism_hdr[6]=0x00; //phytype
2709 prism_hdr[7]=htonl(priv->chan); //channel
2710 prism_hdr[8]=htonl(stats.rate); //datarate
2711 prism_hdr[9]=0x00; //antenna
2712 prism_hdr[10]=0x00; //priority
2713 prism_hdr[11]=0x00; //ssi_type
2714 prism_hdr[12]=htonl(stats.signal); //ssi_signal
2715 prism_hdr[13]=htonl(stats.noise); //ssi_noise
2716 prism_hdr[14]=0x00; //preamble
2717 prism_hdr[15]=0x00; //encoding
2721 priv->rx_skb = dev_alloc_skb(len+2);
2722 if( !priv->rx_skb) goto drop;
2724 DMESG("Alloc initial skb %x",len+2);
2728 priv->rx_skb_complete=0;
2729 priv->rx_skb->dev=dev;
2731 /* if we are here we should have already RXed
2733 * If we get here and the skb is not allocated then
2734 * we have just throw out garbage (skb not allocated)
2735 * and we are still rxing garbage....
2737 if(!priv->rx_skb_complete){
2739 tmp_skb= dev_alloc_skb(priv->rx_skb->len +len+2);
2741 if(!tmp_skb) goto drop;
2745 DMESG("Realloc skb %x",len+2);
2749 DMESG("going copy prev frag %x",priv->rx_skb->len);
2751 memcpy(skb_put(tmp_skb,priv->rx_skb->len),
2755 DMESG("skb copy prev frag complete");
2758 dev_kfree_skb_any(priv->rx_skb);
2760 DMESG("prev skb free ok");
2763 priv->rx_skb=tmp_skb;
2767 DMESG("going to copy current payload %x",len);
2769 if(!priv->rx_skb_complete) {
2770 #ifdef CONFIG_RTL8185B
2772 memcpy(skb_put(priv->rx_skb,len),
2773 (((unsigned char *)priv->rxbuffer->buf) + 2),len);
2776 memcpy(skb_put(priv->rx_skb,len),
2777 priv->rxbuffer->buf,len);
2778 #ifdef CONFIG_RTL8185B
2783 DMESG("current fragment skb copy complete");
2786 if(last && !priv->rx_skb_complete){
2789 DMESG("Got last fragment");
2792 if(priv->rx_skb->len > 4)
2793 skb_trim(priv->rx_skb,priv->rx_skb->len-4);
2795 DMESG("yanked out crc, passing to the upper layer");
2798 #ifndef RX_DONT_PASS_UL
2799 if(!ieee80211_rx(priv->ieee80211,
2800 priv->rx_skb, &stats)){
2802 DMESGW("Packet not consumed");
2804 #endif // RX_DONT_PASS_UL
2806 dev_kfree_skb_any(priv->rx_skb);
2807 #ifndef RX_DONT_PASS_UL
2815 priv->rx_skb_complete=1;
2820 pci_dma_sync_single_for_device(priv->pdev,
2821 priv->rxbuffer->dma,
2822 priv->rxbuffersize * \
2824 PCI_DMA_FROMDEVICE);
2827 drop: // this is used when we have not enought mem
2829 /* restore the descriptor */
2830 *(priv->rxringtail+2)=priv->rxbuffer->dma;
2831 *(priv->rxringtail)=*(priv->rxringtail) &~ 0xfff;
2832 *(priv->rxringtail)=
2833 *(priv->rxringtail) | priv->rxbuffersize;
2835 *(priv->rxringtail)=
2836 *(priv->rxringtail) | (1<<31);
2842 DMESG("Current descriptor: %x",(u32)priv->rxringtail);
2844 //unsigned long flags;
2845 //spin_lock_irqsave(&priv->irq_lock,flags);
2847 priv->rxringtail+=rx_desc_size;
2848 if(priv->rxringtail >=
2849 (priv->rxring)+(priv->rxringcount )*rx_desc_size)
2850 priv->rxringtail=priv->rxring;
2852 //spin_unlock_irqrestore(&priv->irq_lock,flags);
2855 priv->rxbuffer=(priv->rxbuffer->next);
2861 // if(get_curr_tx_free_desc(dev,priority))
2862 // ieee80211_sta_ps_sleep(priv->ieee80211, &tmp, &tmp2);
2869 void rtl8180_dma_kick(struct net_device *dev, int priority)
2871 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2873 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2880 write_nic_byte(dev,TX_DMA_POLLING,
2881 (1<< TX_DMA_POLLING_LOWPRIORITY_SHIFT) |
2882 priv->dma_poll_mask);
2887 write_nic_byte(dev,TX_DMA_POLLING,
2888 (1<< TX_DMA_POLLING_NORMPRIORITY_SHIFT) |
2889 priv->dma_poll_mask);
2894 write_nic_byte(dev,TX_DMA_POLLING,
2895 (1<< TX_DMA_POLLING_HIPRIORITY_SHIFT) |
2896 priv->dma_poll_mask);
2901 write_nic_byte(dev, TX_DMA_POLLING,
2902 (1 << (priority + 1)) | priv->dma_poll_mask);
2903 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2905 force_pci_posting(dev);
2909 void rtl8180_tx_queues_stop(struct net_device *dev)
2911 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2912 u8 dma_poll_mask = (1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
2913 dma_poll_mask |= (1<<TX_DMA_STOP_HIPRIORITY_SHIFT);
2914 dma_poll_mask |= (1<<TX_DMA_STOP_NORMPRIORITY_SHIFT);
2915 dma_poll_mask |= (1<<TX_DMA_STOP_BEACON_SHIFT);
2917 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2918 write_nic_byte(dev,TX_DMA_POLLING,dma_poll_mask);
2919 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2923 void rtl8180_data_hard_stop(struct net_device *dev)
2925 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2927 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2928 #ifdef CONFIG_RTL8185B
2929 priv->dma_poll_stop_mask |= TPPOLLSTOP_AC_VIQ;
2930 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
2932 priv->dma_poll_mask |= (1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
2933 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
2935 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2939 void rtl8180_data_hard_resume(struct net_device *dev)
2941 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2943 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2944 #ifdef CONFIG_RTL8185B
2945 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_AC_VIQ);
2946 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
2948 priv->dma_poll_mask &= ~(1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
2949 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
2951 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2955 /* this function TX data frames when the ieee80211 stack requires this.
2956 * It checks also if we need to stop the ieee tx queue, eventually do it
2958 void rtl8180_hard_data_xmit(struct sk_buff *skb,struct net_device *dev, int
2961 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2963 struct ieee80211_hdr_3addr *h = (struct ieee80211_hdr_3addr *) skb->data;
2964 short morefrag = (h->frame_ctl) & IEEE80211_FCTL_MOREFRAGS;
2965 unsigned long flags;
2967 //static int count = 0;
2969 mode = priv->ieee80211->iw_mode;
2971 rate = ieeerate2rtlrate(rate);
2973 * This function doesn't require lock because we make
2974 * sure it's called with the tx_lock already acquired.
2975 * this come from the kernel's hard_xmit callback (trought
2976 * the ieee stack, or from the try_wake_queue (again trought
2979 #ifdef CONFIG_RTL8185B
2980 priority = AC2Q(skb->priority);
2982 priority = LOW_PRIORITY;
2984 spin_lock_irqsave(&priv->tx_lock,flags);
2986 if(priv->ieee80211->bHwRadioOff)
2988 spin_unlock_irqrestore(&priv->tx_lock,flags);
2993 //printk(KERN_WARNING "priority = %d@%d\n", priority, count++);
2994 if (!check_nic_enought_desc(dev, priority)){
2995 //DMESG("Error: no descriptor left by previous TX (avail %d) ",
2996 // get_curr_tx_free_desc(dev, priority));
2997 DMESGW("Error: no descriptor left by previous TX (avail %d) ",
2998 get_curr_tx_free_desc(dev, priority));
2999 //printk(KERN_WARNING "==============================================================> \n");
3000 ieee80211_stop_queue(priv->ieee80211);
3002 rtl8180_tx(dev, skb->data, skb->len, priority, morefrag,0,rate);
3003 if (!check_nic_enought_desc(dev, priority))
3004 ieee80211_stop_queue(priv->ieee80211);
3006 //dev_kfree_skb_any(skb);
3007 spin_unlock_irqrestore(&priv->tx_lock,flags);
3011 /* This is a rough attempt to TX a frame
3012 * This is called by the ieee 80211 stack to TX management frames.
3013 * If the ring is full packet are dropped (for data frame the queue
3014 * is stopped before this can happen). For this reason it is better
3015 * if the descriptors are larger than the largest management frame
3016 * we intend to TX: i'm unsure what the HW does if it will not found
3017 * the last fragment of a frame because it has been dropped...
3018 * Since queues for Management and Data frames are different we
3019 * might use a different lock than tx_lock (for example mgmt_tx_lock)
3021 /* these function may loops if invoked with 0 descriptors or 0 len buffer*/
3022 int rtl8180_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
3024 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3026 unsigned long flags;
3030 #ifdef CONFIG_RTL8185B
3031 priority = MANAGE_PRIORITY;
3033 priority = NORM_PRIORITY;
3036 spin_lock_irqsave(&priv->tx_lock,flags);
3038 if(priv->ieee80211->bHwRadioOff)
3040 spin_unlock_irqrestore(&priv->tx_lock,flags);
3042 dev_kfree_skb_any(skb);
3046 rtl8180_tx(dev, skb->data, skb->len, priority,
3047 0, 0,ieeerate2rtlrate(priv->ieee80211->basic_rate));
3049 priv->ieee80211->stats.tx_bytes+=skb->len;
3050 priv->ieee80211->stats.tx_packets++;
3051 spin_unlock_irqrestore(&priv->tx_lock,flags);
3053 dev_kfree_skb_any(skb);
3057 // longpre 144+48 shortpre 72+24
3058 u16 rtl8180_len2duration(u32 len, short rate,short* ext)
3067 duration = ((len+4)<<4) /0x2;
3068 drift = ((len+4)<<4) % 0x2;
3069 if(drift ==0 ) break;
3075 duration = ((len+4)<<4) /0x4;
3076 drift = ((len+4)<<4) % 0x4;
3077 if(drift ==0 ) break;
3083 duration = ((len+4)<<4) /0xb;
3084 drift = ((len+4)<<4) % 0xb;
3093 duration = ((len+4)<<4) /0x16;
3094 drift = ((len+4)<<4) % 0x16;
3108 void rtl8180_prepare_beacon(struct net_device *dev)
3111 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3113 struct sk_buff *skb;
3115 u16 word = read_nic_word(dev, BcnItv);
3116 word &= ~BcnItv_BcnItv; // clear Bcn_Itv
3117 word |= cpu_to_le16(priv->ieee80211->current_network.beacon_interval);//0x64;
3118 write_nic_word(dev, BcnItv, word);
3121 skb = ieee80211_get_beacon(priv->ieee80211);
3123 rtl8180_tx(dev,skb->data,skb->len,BEACON_PRIORITY,
3124 0,0,ieeerate2rtlrate(priv->ieee80211->basic_rate));
3125 dev_kfree_skb_any(skb);
3128 //DMESG("size %x",len);
3129 if(*tail & (1<<31)){
3131 //DMESG("No more beacon TX desc");
3135 //while(! (*tail & (1<<31))){
3136 *tail= 0; // zeroes header
3138 *tail = *tail| (1<<29) ; //fist segment of the packet
3139 *tail = (*tail) | (1<<28); // last segment
3140 // *tail = *tail | (1<<18); // this is a beacon frame
3141 *(tail+3)=*(tail+3) &~ 0xfff;
3142 *(tail+3)=*(tail+3) | len; // buffer lenght
3144 // zeroes the second 32-bits dword of the descriptor
3146 *tail = *tail | (rate << 24);
3148 duration = rtl8180_len2duration(len,rate,&ext);
3150 *(tail+1) = *(tail+1) | ((duration & 0x7fff)<<16);
3152 *tail = *tail | (1<<31);
3153 //^ descriptor ready to be txed
3154 if((tail - begin)/8 == priv->txbeaconcount-1)
3162 /* This function do the real dirty work: it enqueues a TX command
3163 * descriptor in the ring buffer, copyes the frame in a TX buffer
3164 * and kicks the NIC to ensure it does the DMA transfer.
3166 short rtl8180_tx(struct net_device *dev, u8* txbuf, int len, int priority,
3167 short morefrag, short descfrag, int rate)
3169 struct r8180_priv *priv = ieee80211_priv(dev);
3170 u32 *tail,*temp_tail;
3181 struct buffer* buflist;
3182 //unsigned long flags;
3183 #ifdef CONFIG_RTL8185B
3184 struct ieee80211_hdr_3addr *frag_hdr = (struct ieee80211_hdr_3addr *)txbuf;
3186 u8 bUseShortPreamble = 0;
3190 //u8 RetryLimit = 0;
3193 u16 ThisFrameTime = 0;
3194 u16 TxDescDuration = 0;
3195 u8 ownbit_flag = false; //added by david woo for sync Tx, 2007.12.14
3199 case MANAGE_PRIORITY:
3200 tail=priv->txmapringtail;
3201 begin=priv->txmapring;
3202 buflist = priv->txmapbufstail;
3203 count = priv->txringcount;
3207 tail=priv->txbkpringtail;
3208 begin=priv->txbkpring;
3209 buflist = priv->txbkpbufstail;
3210 count = priv->txringcount;
3214 tail=priv->txbepringtail;
3215 begin=priv->txbepring;
3216 buflist = priv->txbepbufstail;
3217 count = priv->txringcount;
3221 tail=priv->txvipringtail;
3222 begin=priv->txvipring;
3223 buflist = priv->txvipbufstail;
3224 count = priv->txringcount;
3228 tail=priv->txvopringtail;
3229 begin=priv->txvopring;
3230 buflist = priv->txvopbufstail;
3231 count = priv->txringcount;
3235 tail=priv->txhpringtail;
3236 begin=priv->txhpring;
3237 buflist = priv->txhpbufstail;
3238 count = priv->txringcount;
3241 case BEACON_PRIORITY:
3242 tail=priv->txbeaconringtail;
3243 begin=priv->txbeaconring;
3244 buflist = priv->txbeaconbufstail;
3245 count = priv->txbeaconcount;
3253 //printk("in rtl8180_tx(): rate is %d\n",priv->ieee80211->rate);
3255 memcpy(&dest, frag_hdr->addr1, ETH_ALEN);
3256 if (is_multicast_ether_addr(dest) ||
3257 is_broadcast_ether_addr(dest))
3264 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate), 0, bUseShortPreamble);
3265 TxDescDuration = ThisFrameTime;
3266 } else {// Unicast packet
3270 //YJ,add,080828,for Keep alive
3271 priv->NumTxUnicast++;
3273 // Figure out ACK rate according to BSS basic rate and Tx rate, 2006.03.08 by rcnjko.
3274 //AckRate = ComputeAckRate( pMgntInfo->mBrates, (u1Byte)(pTcb->DataRate) );
3275 // Figure out ACK time according to the AckRate and assume long preamble is used on receiver, 2006.03.08, by rcnjko.
3276 //AckTime = ComputeTxTime( sAckCtsLng/8, AckRate, FALSE, FALSE);
3277 //For simplicity, just use the 1M basic rate
3278 //AckTime = ComputeTxTime(14, 540,0, 0); // AckCTSLng = 14 use 1M bps send
3279 AckTime = ComputeTxTime(14, 10,0, 0); // AckCTSLng = 14 use 1M bps send
3280 //AckTime = ComputeTxTime(14, 2,false, false); // AckCTSLng = 14 use 1M bps send
3282 if ( ((len + sCrcLng) > priv->rts) && priv->rts )
3284 u16 RtsTime, CtsTime;
3289 // Rate and time required for RTS.
3290 RtsTime = ComputeTxTime( sAckCtsLng/8,priv->ieee80211->basic_rate, 0, 0);
3291 // Rate and time required for CTS.
3292 CtsTime = ComputeTxTime(14, 10,0, 0); // AckCTSLng = 14 use 1M bps send
3294 // Figure out time required to transmit this frame.
3295 ThisFrameTime = ComputeTxTime(len + sCrcLng,
3296 rtl8180_rate2rate(rate),
3300 // RTS-CTS-ThisFrame-ACK.
3301 RtsDur = CtsTime + ThisFrameTime + AckTime + 3*aSifsTime;
3303 TxDescDuration = RtsTime + RtsDur;
3305 else {// Normal case.
3310 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate), 0, bUseShortPreamble);
3311 TxDescDuration = ThisFrameTime + aSifsTime + AckTime;
3314 if(!(frag_hdr->frame_ctl & IEEE80211_FCTL_MOREFRAGS)) { //no more fragment
3316 Duration = aSifsTime + AckTime;
3317 } else { // One or more fragments remained.
3319 NextFragTime = ComputeTxTime( len + sCrcLng, //pretend following packet length equal current packet
3320 rtl8180_rate2rate(rate),
3322 bUseShortPreamble );
3324 //ThisFrag-ACk-NextFrag-ACK.
3325 Duration = NextFragTime + 3*aSifsTime + 2*AckTime;
3328 } // End of Unicast packet
3330 frag_hdr->duration_id = Duration;
3333 buflen=priv->txbuffsize;
3336 //printk("================================>buflen = %d, remain = %d!\n", buflen,remain);
3338 #ifdef DEBUG_TX_FRAG
3339 DMESG("TX iteration");
3342 DMESG("TX: filling descriptor %x",(u32)tail);
3346 DMESGE("TX buffer error, cannot TX frames. pri %d.", priority);
3347 //spin_unlock_irqrestore(&priv->tx_lock,flags);
3352 if( (*tail & (1<<31)) && (priority != BEACON_PRIORITY)){
3354 DMESGW("No more TX desc, returning %x of %x",
3356 priv->stats.txrdu++;
3357 #ifdef DEBUG_TX_DESC
3358 check_tx_ring(dev,priority);
3359 // netif_stop_queue(dev);
3360 // netif_carrier_off(dev);
3362 // spin_unlock_irqrestore(&priv->tx_lock,flags);
3368 *tail= 0; // zeroes header
3375 if(priv->card_8185){
3376 //FIXME: this should be triggered by HW encryption parameters.
3377 *tail |= (1<<15); //no encrypt
3378 // *tail |= (1<<30); //raise int when completed
3380 // *tail = *tail | (1<<16);
3381 if(remain==len && !descfrag) {
3382 ownbit_flag = false; //added by david woo,2007.12.14
3383 #ifdef DEBUG_TX_FRAG
3384 DMESG("First descriptor");
3386 *tail = *tail| (1<<29) ; //fist segment of the packet
3387 *tail = *tail |(len);
3392 for(i=0;i<buflen&& remain >0;i++,remain--){
3393 ((u8*)buf)[i]=txbuf[i]; //copy data into descriptor pointed DMAble buffer
3394 if(remain == 4 && i+4 >= buflen) break;
3395 /* ensure the last desc has at least 4 bytes payload */
3399 *(tail+3)=*(tail+3) &~ 0xfff;
3400 *(tail+3)=*(tail+3) | i; // buffer lenght
3401 // Use short preamble or not
3402 if (priv->ieee80211->current_network.capability&WLAN_CAPABILITY_SHORT_PREAMBLE)
3403 if (priv->plcp_preamble_mode==1 && rate!=0) // short mode now, not long!
3404 // *tail |= (1<<16); // enable short preamble mode.
3406 #ifdef CONFIG_RTL8185B
3411 if(bRTSEnable) //rts enable
3413 *tail |= ((ieeerate2rtlrate(priv->ieee80211->basic_rate))<<19);//RTS RATE
3414 *tail |= (1<<23);//rts enable
3415 *(tail+1) |=(RtsDur&0xffff);//RTS Duration
3417 *(tail+3) |= ((TxDescDuration&0xffff)<<16); //DURATION
3418 // *(tail+3) |= (0xe6<<16);
3419 *(tail+5) |= (11<<8);//(priv->retry_data<<8); //retry lim ;
3422 #ifdef CONFIG_RTL8187B
3423 if ( (len>priv->rts) && priv->rts && priority!=MANAGE_PRIORITY){
3425 if ( (len>priv->rts) && priv->rts && priority==LOW_PRIORITY){
3427 *tail |= (1<<23); //enalbe RTS function
3428 *tail |= (0<<19); //use 1M bps send RTS packet
3429 AckCtsTime = ComputeTxTime(14, 10,0, 0); // AckCTSLng = 14 use 1M bps send
3430 FrameTime = ComputeTxTime(len + 4, rtl8180_rate2rate(rate), 0, *tail&(1<<16));
3431 // RTS/CTS time is calculate as follow
3432 duration = FrameTime + 3*10 + 2*AckCtsTime; //10us is the SifsTime;
3433 *(tail+1) |= duration; //Need to edit here! ----hikaru
3435 *(tail+1)= 0; // zeroes the second 32-bits dword of the descriptor
3439 *tail = *tail | ((rate&0xf) << 24);
3440 //DMESG("rate %d",rate);
3442 if(priv->card_8185){
3445 *(tail+5)&= ~(1<<24); /* tx ant 0 */
3447 *(tail+5) &= ~(1<<23); /* random tx agc 23-16 */
3448 *(tail+5) |= (1<<22)|(1<<21)|(1<<20)|(1<<19)|(1<<18)|(1<<17)|(1<<16);
3451 ~((1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(1<<10)|(1<<9)|(1<<8));
3452 *(tail+5) |= (7<<8); // Max retry limit
3454 *(tail+5) &= ~((1<<7)|(1<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0));
3455 *(tail+5) |= (8<<4); // Max contention window
3456 *(tail+6) |= 4; // Min contention window
3461 /* hw_plcp_len is not used for rtl8180 chip */
3463 if(priv->card_8185 == 0 || !priv->hw_plcp_len){
3465 duration = rtl8180_len2duration(len,
3470 DMESG("PLCP duration %d",duration );
3471 //DMESG("drift %d",drift);
3472 DMESG("extension %s", (ext==1) ? "on":"off");
3474 *(tail+1) = *(tail+1) | ((duration & 0x7fff)<<16);
3475 if(ext) *(tail+1) = *(tail+1) |(1<<31); //plcp length extension
3478 if(morefrag) *tail = (*tail) | (1<<17); // more fragment
3479 if(!remain) *tail = (*tail) | (1<<28); // last segment of frame
3481 #ifdef DEBUG_TX_FRAG
3482 if(!remain)DMESG("Last descriptor");
3483 if(morefrag)DMESG("More frag");
3485 *(tail+5) = *(tail+5)|(2<<27);
3486 *(tail+7) = *(tail+7)|(1<<4);
3491 *tail = *tail | (1<<31); // descriptor ready to be txed
3494 #ifdef DEBUG_TX_DESC2
3495 printk("tx desc is:\n");
3496 DMESG("%8x %8x %8x %8x %8x %8x %8x %8x", tail[0], tail[1], tail[2], tail[3],
3497 tail[4], tail[5], tail[6], tail[7]);
3500 if((tail - begin)/8 == count-1)
3506 buflist=buflist->next;
3511 case MANAGE_PRIORITY:
3512 priv->txmapringtail=tail;
3513 priv->txmapbufstail=buflist;
3517 priv->txbkpringtail=tail;
3518 priv->txbkpbufstail=buflist;
3522 priv->txbepringtail=tail;
3523 priv->txbepbufstail=buflist;
3527 priv->txvipringtail=tail;
3528 priv->txvipbufstail=buflist;
3532 priv->txvopringtail=tail;
3533 priv->txvopbufstail=buflist;
3537 priv->txhpringtail=tail;
3538 priv->txhpbufstail = buflist;
3541 case BEACON_PRIORITY:
3542 /* the HW seems to be happy with the 1st
3543 * descriptor filled and the 2nd empty...
3544 * So always update descriptor 1 and never
3547 // priv->txbeaconringtail=tail;
3548 // priv->txbeaconbufstail=buflist;
3554 //rtl8180_dma_kick(dev,priority);
3556 *temp_tail = *temp_tail | (1<<31); // descriptor ready to be txed
3557 rtl8180_dma_kick(dev,priority);
3558 //spin_unlock_irqrestore(&priv->tx_lock,flags);
3565 void rtl8180_irq_rx_tasklet(struct r8180_priv * priv);
3568 void rtl8180_link_change(struct net_device *dev)
3570 struct r8180_priv *priv = ieee80211_priv(dev);
3571 u16 beacon_interval;
3573 struct ieee80211_network *net = &priv->ieee80211->current_network;
3574 // rtl8180_adapter_start(dev);
3575 rtl8180_update_msr(dev);
3578 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
3580 write_nic_dword(dev,BSSID,((u32*)net->bssid)[0]);
3581 write_nic_word(dev,BSSID+4,((u16*)net->bssid)[2]);
3584 beacon_interval = read_nic_dword(dev,BEACON_INTERVAL);
3585 beacon_interval &= ~ BEACON_INTERVAL_MASK;
3586 beacon_interval |= net->beacon_interval;
3587 write_nic_dword(dev, BEACON_INTERVAL, beacon_interval);
3589 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
3593 u16 atim = read_nic_dword(dev,ATIM);
3594 u16 = u16 &~ ATIM_MASK;
3595 u16 = u16 | beacon->atim;
3598 if (net->capability & WLAN_CAPABILITY_PRIVACY) {
3600 DMESG("Enabling hardware WEP support");
3601 rtl8180_set_hw_wep(dev);
3602 priv->ieee80211->host_encrypt=0;
3603 priv->ieee80211->host_decrypt=0;
3605 #ifndef CONFIG_IEEE80211_NOWEP
3607 priv->ieee80211->host_encrypt=1;
3608 priv->ieee80211->host_decrypt=1;
3612 #ifndef CONFIG_IEEE80211_NOWEP
3614 priv->ieee80211->host_encrypt=0;
3615 priv->ieee80211->host_decrypt=0;
3622 rtl8180_set_chan(dev, priv->chan);
3627 void rtl8180_rq_tx_ack(struct net_device *dev){
3629 struct r8180_priv *priv = ieee80211_priv(dev);
3630 // printk("====================>%s\n",__func__);
3631 write_nic_byte(dev,CONFIG4,read_nic_byte(dev,CONFIG4)|CONFIG4_PWRMGT);
3632 priv->ack_tx_to_ieee = 1;
3635 short rtl8180_is_tx_queue_empty(struct net_device *dev){
3637 struct r8180_priv *priv = ieee80211_priv(dev);
3640 for (d = priv->txmapring;
3641 d < priv->txmapring + priv->txringcount;d+=8)
3642 if(*d & (1<<31)) return 0;
3644 for (d = priv->txbkpring;
3645 d < priv->txbkpring + priv->txringcount;d+=8)
3646 if(*d & (1<<31)) return 0;
3648 for (d = priv->txbepring;
3649 d < priv->txbepring + priv->txringcount;d+=8)
3650 if(*d & (1<<31)) return 0;
3652 for (d = priv->txvipring;
3653 d < priv->txvipring + priv->txringcount;d+=8)
3654 if(*d & (1<<31)) return 0;
3656 for (d = priv->txvopring;
3657 d < priv->txvopring + priv->txringcount;d+=8)
3658 if(*d & (1<<31)) return 0;
3660 for (d = priv->txhpring;
3661 d < priv->txhpring + priv->txringcount;d+=8)
3662 if(*d & (1<<31)) return 0;
3665 /* FIXME FIXME 5msecs is random */
3666 #define HW_WAKE_DELAY 5
3668 void rtl8180_hw_wakeup(struct net_device *dev)
3670 unsigned long flags;
3672 struct r8180_priv *priv = ieee80211_priv(dev);
3674 spin_lock_irqsave(&priv->ps_lock,flags);
3675 //DMESG("Waken up!");
3676 write_nic_byte(dev,CONFIG4,read_nic_byte(dev,CONFIG4)&~CONFIG4_PWRMGT);
3679 priv->rf_wakeup(dev);
3680 // mdelay(HW_WAKE_DELAY);
3681 spin_unlock_irqrestore(&priv->ps_lock,flags);
3684 void rtl8180_hw_sleep_down(struct net_device *dev)
3686 unsigned long flags;
3688 struct r8180_priv *priv = ieee80211_priv(dev);
3690 spin_lock_irqsave(&priv->ps_lock,flags);
3694 priv->rf_sleep(dev);
3695 spin_unlock_irqrestore(&priv->ps_lock,flags);
3699 void rtl8180_hw_sleep(struct net_device *dev, u32 th, u32 tl)
3702 struct r8180_priv *priv = ieee80211_priv(dev);
3705 unsigned long flags;
3707 spin_lock_irqsave(&priv->ps_lock,flags);
3709 /* Writing HW register with 0 equals to disable
3710 * the timer, that is not really what we want
3712 tl -= MSECS(4+16+7);
3714 //if(tl == 0) tl = 1;
3716 /* FIXME HACK FIXME HACK */
3717 // force_pci_posting(dev);
3720 // rb = read_nic_dword(dev, TSFTR);
3722 /* If the interval in witch we are requested to sleep is too
3723 * short then give up and remain awake
3725 if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME))
3726 ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
3727 spin_unlock_irqrestore(&priv->ps_lock,flags);
3728 printk("too short to sleep\n");
3732 // write_nic_dword(dev, TimerInt, tl);
3733 // rb = read_nic_dword(dev, TSFTR);
3735 u32 tmp = (tl>rb)?(tl-rb):(rb-tl);
3739 priv->DozePeriodInPast2Sec += jiffies_to_msecs(tmp);
3741 queue_delayed_work(priv->ieee80211->wq, &priv->ieee80211->hw_wakeup_wq, tmp); //as tl may be less than rb
3743 /* if we suspect the TimerInt is gone beyond tl
3744 * while setting it, then give up
3747 if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))||
3748 ((tl < rb) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))) {
3749 spin_unlock_irqrestore(&priv->ps_lock,flags);
3753 // if(priv->rf_sleep)
3754 // priv->rf_sleep(dev);
3756 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_sleep_wq);
3757 spin_unlock_irqrestore(&priv->ps_lock,flags);
3761 //void rtl8180_wmm_param_update(struct net_device *dev,u8 *ac_param)
3762 #if LINUX_VERSION_CODE >=KERNEL_VERSION(2,6,20)
3763 void rtl8180_wmm_param_update(struct work_struct * work)
3765 struct ieee80211_device * ieee = container_of(work, struct ieee80211_device,wmm_param_update_wq);
3766 //struct r8180_priv *priv = (struct r8180_priv*)(ieee->priv);
3767 struct net_device *dev = ieee->dev;
3769 void rtl8180_wmm_param_update(struct ieee80211_device *ieee)
3771 struct net_device *dev = ieee->dev;
3772 struct r8180_priv *priv = ieee80211_priv(dev);
3774 u8 *ac_param = (u8 *)(ieee->current_network.wmm_param);
3775 u8 mode = ieee->current_network.mode;
3781 #ifndef CONFIG_RTL8185B
3782 //for legacy 8185 keep the PARAM unchange.
3785 if(!ieee->current_network.QoS_Enable){
3786 //legacy ac_xx_param update
3787 AcParam.longData = 0;
3788 AcParam.f.AciAifsn.f.AIFSN = 2; // Follow 802.11 DIFS.
3789 AcParam.f.AciAifsn.f.ACM = 0;
3790 AcParam.f.Ecw.f.ECWmin = 3; // Follow 802.11 CWmin.
3791 AcParam.f.Ecw.f.ECWmax = 7; // Follow 802.11 CWmax.
3792 AcParam.f.TXOPLimit = 0;
3793 for(eACI = 0; eACI < AC_MAX; eACI++){
3794 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
3798 pAcParam = (PAC_PARAM)(&AcParam);
3799 // Retrive paramters to udpate.
3800 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN *(((mode&IEEE_G) == IEEE_G)?9:20) + aSifsTime;
3801 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit))<<AC_PARAM_TXOP_LIMIT_OFFSET)|
3802 (((u32)(pAcParam->f.Ecw.f.ECWmax))<<AC_PARAM_ECW_MAX_OFFSET)|
3803 (((u32)(pAcParam->f.Ecw.f.ECWmin))<<AC_PARAM_ECW_MIN_OFFSET)|
3804 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
3807 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
3811 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
3815 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
3819 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
3823 printk(KERN_WARNING "SetHwReg8185():invalid ACI: %d!\n", eACI);
3831 for(i = 0; i < AC_MAX; i++){
3832 //AcParam.longData = 0;
3833 pAcParam = (AC_PARAM * )ac_param;
3839 // Retrive paramters to udpate.
3840 eACI = pAcParam->f.AciAifsn.f.ACI;
3841 //Mode G/A: slotTimeTimer = 9; Mode B: 20
3842 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G)?9:20) + aSifsTime;
3843 u4bAcParam = ( (((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
3844 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
3845 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
3846 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
3850 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
3854 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
3858 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
3862 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
3866 printk(KERN_WARNING "SetHwReg8185(): invalid ACI: %d !\n", eACI);
3870 ac_param += (sizeof(AC_PARAM));
3875 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3876 void rtl8180_tx_irq_wq(struct work_struct *work);
3878 void rtl8180_tx_irq_wq(struct net_device *dev);
3884 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3885 void rtl8180_restart_wq(struct work_struct *work);
3886 //void rtl8180_rq_tx_ack(struct work_struct *work);
3888 void rtl8180_restart_wq(struct net_device *dev);
3889 //void rtl8180_rq_tx_ack(struct net_device *dev);
3891 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3892 void rtl8180_watch_dog_wq(struct work_struct *work);
3894 void rtl8180_watch_dog_wq(struct net_device *dev);
3896 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3897 void rtl8180_hw_wakeup_wq(struct work_struct *work);
3899 void rtl8180_hw_wakeup_wq(struct net_device *dev);
3902 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3903 void rtl8180_hw_sleep_wq(struct work_struct *work);
3905 void rtl8180_hw_sleep_wq(struct net_device *dev);
3910 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3911 void rtl8180_sw_antenna_wq(struct work_struct *work);
3913 void rtl8180_sw_antenna_wq(struct net_device *dev);
3915 void rtl8180_watch_dog(struct net_device *dev);
3916 void watch_dog_adaptive(unsigned long data)
3918 struct r8180_priv* priv = ieee80211_priv((struct net_device *)data);
3919 // DMESG("---->watch_dog_adaptive()\n");
3922 DMESG("<----watch_dog_adaptive():driver is not up!\n");
3926 // queue_work(priv->ieee80211->wq,&priv->ieee80211->watch_dog_wq);
3929 // Tx High Power Mechanism.
3931 if(CheckHighPower((struct net_device *)data))
3933 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->tx_pw_wq);
3937 #ifdef CONFIG_RTL818X_S
3938 // Tx Power Tracking on 87SE.
3940 //if( priv->bTxPowerTrack ) //lzm mod 080826
3941 if( CheckTxPwrTracking((struct net_device *)data));
3942 TxPwrTracking87SE((struct net_device *)data);
3946 // Perform DIG immediately.
3948 if(CheckDig((struct net_device *)data) == true)
3950 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_dig_wq);
3955 rtl8180_watch_dog((struct net_device *)data);
3958 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->GPIOChangeRFWorkItem);
3960 priv->watch_dog_timer.expires = jiffies + MSECS(IEEE80211_WATCH_DOG_TIME);
3961 add_timer(&priv->watch_dog_timer);
3962 // DMESG("<----watch_dog_adaptive()\n");
3965 #ifdef ENABLE_DOT11D
3967 static CHANNEL_LIST ChannelPlan[] = {
3968 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64},19}, //FCC
3969 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
3970 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
3971 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //Spain. Change to ETSI.
3972 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //France. Change to ETSI.
3973 {{14,36,40,44,48,52,56,60,64},9}, //MKK
3974 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14, 36,40,44,48,52,56,60,64},22},//MKK1
3975 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //Israel.
3976 {{1,2,3,4,5,6,7,8,9,10,11,12,13,34,38,42,46},17}, // For 11a , TELEC
3977 {{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
3978 {{1,2,3,4,5,6,7,8,9,10,11,12,13},13} //world wide 13: ch1~ch11 active scan, ch12~13 passive //lzm add 080826
3981 static void rtl8180_set_channel_map(u8 channel_plan, struct ieee80211_device *ieee)
3986 ieee->MinPassiveChnlNum=MAX_CHANNEL_NUMBER+1;
3987 ieee->IbssStartChnl=0;
3989 switch (channel_plan)
3991 case COUNTRY_CODE_FCC:
3992 case COUNTRY_CODE_IC:
3993 case COUNTRY_CODE_ETSI:
3994 case COUNTRY_CODE_SPAIN:
3995 case COUNTRY_CODE_FRANCE:
3996 case COUNTRY_CODE_MKK:
3997 case COUNTRY_CODE_MKK1:
3998 case COUNTRY_CODE_ISRAEL:
3999 case COUNTRY_CODE_TELEC:
4002 ieee->bGlobalDomain = false;
4003 if (ChannelPlan[channel_plan].Len != 0){
4004 // Clear old channel map
4005 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
4006 // Set new channel map
4007 for (i=0;i<ChannelPlan[channel_plan].Len;i++)
4009 if(ChannelPlan[channel_plan].Channel[i] <= 14)
4010 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
4015 case COUNTRY_CODE_GLOBAL_DOMAIN:
4017 GET_DOT11D_INFO(ieee)->bEnabled = 0;
4019 ieee->bGlobalDomain = true;
4022 case COUNTRY_CODE_WORLD_WIDE_13_INDEX://lzm add 080826
4024 ieee->MinPassiveChnlNum=12;
4025 ieee->IbssStartChnl= 10;
4031 ieee->bGlobalDomain = false;
4032 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
4035 GET_DOT11D_INFO(ieee)->channel_map[i] = 1;
4043 //Add for RF power on power off by lizhaoming 080512
4044 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
4045 void GPIOChangeRFWorkItemCallBack(struct work_struct *work);
4047 void GPIOChangeRFWorkItemCallBack(struct ieee80211_device *ieee);
4051 static void rtl8180_statistics_init(struct Stats *pstats)
4053 memset(pstats, 0, sizeof(struct Stats));
4055 static void rtl8180_link_detect_init(plink_detect_t plink_detect)
4057 memset(plink_detect, 0, sizeof(link_detect_t));
4058 plink_detect->SlotNum = DEFAULT_SLOT_NUM;
4062 short rtl8180_init(struct net_device *dev)
4064 struct r8180_priv *priv = ieee80211_priv(dev);
4073 #ifdef ENABLE_DOT11D
4075 for(i=0;i<0xFF;i++) {
4077 printk("\n[%x]: ", i/16);
4078 printk("\t%4.4x", eprom_read(dev,i));
4081 priv->channel_plan = eprom_read(dev, EEPROM_COUNTRY_CODE>>1) & 0xFF;
4082 if(priv->channel_plan > COUNTRY_CODE_GLOBAL_DOMAIN){
4083 printk("rtl8180_init:Error channel plan! Set to default.\n");
4084 priv->channel_plan = 0;
4086 //priv->channel_plan = 9; //Global Domain
4088 DMESG("Channel plan is %d\n",priv->channel_plan);
4089 rtl8180_set_channel_map(priv->channel_plan, priv->ieee80211);
4092 //Set Default Channel Plan
4094 DMESG("No channels, aborting");
4098 priv->channel_plan = 0;//hikaru
4099 // set channels 1..14 allowed in given locale
4100 for (i=1; i<=14; i++) {
4101 (priv->ieee80211->channel_map)[i] = (u8)(ch & 0x01);
4106 //memcpy(priv->stats,0,sizeof(struct Stats));
4108 //FIXME: these constants are placed in a bad pleace.
4109 priv->txbuffsize = 2048;//1024;
4110 priv->txringcount = 32;//32;
4111 priv->rxbuffersize = 2048;//1024;
4112 priv->rxringcount = 64;//32;
4113 priv->txbeaconcount = 2;
4114 priv->rx_skb_complete = 1;
4115 //priv->txnp_pending.ispending=0;
4116 /* ^^ the SKB does not containt a partial RXed
4120 #ifdef CONFIG_RTL8185B
4121 #ifdef CONFIG_RTL818X_S
4122 priv->RegThreeWireMode = HW_THREE_WIRE_SI;
4124 priv->RegThreeWireMode = SW_THREE_WIRE;
4128 //Add for RF power on power off by lizhaoming 080512
4129 priv->RFChangeInProgress = false;
4130 priv->SetRFPowerStateInProgress = false;
4131 priv->RFProgType = 0;
4132 priv->bInHctTest = false;
4134 priv->irq_enabled=0;
4136 //YJ,modified,080828
4138 priv->stats.rxdmafail=0;
4139 priv->stats.txrdu=0;
4140 priv->stats.rxrdu=0;
4141 priv->stats.rxnolast=0;
4142 priv->stats.rxnodata=0;
4143 //priv->stats.rxreset=0;
4144 //priv->stats.rxwrkaround=0;
4145 priv->stats.rxnopointer=0;
4146 priv->stats.txnperr=0;
4147 priv->stats.txresumed=0;
4148 priv->stats.rxerr=0;
4149 priv->stats.rxoverflow=0;
4150 priv->stats.rxint=0;
4151 priv->stats.txnpokint=0;
4152 priv->stats.txhpokint=0;
4153 priv->stats.txhperr=0;
4155 priv->stats.shints=0;
4156 priv->stats.txoverflow=0;
4157 priv->stats.txbeacon=0;
4158 priv->stats.txbeaconerr=0;
4159 priv->stats.txlperr=0;
4160 priv->stats.txlpokint=0;
4161 priv->stats.txretry=0;//tony 20060601
4162 priv->stats.rxcrcerrmin=0;
4163 priv->stats.rxcrcerrmid=0;
4164 priv->stats.rxcrcerrmax=0;
4165 priv->stats.rxicverr=0;
4167 rtl8180_statistics_init(&priv->stats);
4168 rtl8180_link_detect_init(&priv->link_detect);
4170 //YJ,modified,080828,end
4173 priv->ack_tx_to_ieee = 0;
4174 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
4175 priv->ieee80211->iw_mode = IW_MODE_INFRA;
4176 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
4177 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
4178 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;
4179 priv->ieee80211->active_scan = 1;
4180 priv->ieee80211->rate = 110; //11 mbps
4181 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION;
4182 priv->ieee80211->host_encrypt = 1;
4183 priv->ieee80211->host_decrypt = 1;
4184 priv->ieee80211->sta_wake_up = rtl8180_hw_wakeup;
4185 priv->ieee80211->ps_request_tx_ack = rtl8180_rq_tx_ack;
4186 priv->ieee80211->enter_sleep_state = rtl8180_hw_sleep;
4187 priv->ieee80211->ps_is_queue_empty = rtl8180_is_tx_queue_empty;
4189 priv->hw_wep = hwwep;
4192 priv->retry_rts = DEFAULT_RETRY_RTS;
4193 priv->retry_data = DEFAULT_RETRY_DATA;
4194 priv->RFChangeInProgress = false;
4195 priv->SetRFPowerStateInProgress = false;
4196 priv->RFProgType = 0;
4197 priv->bInHctTest = false;
4198 priv->bInactivePs = true;//false;
4199 priv->ieee80211->bInactivePs = priv->bInactivePs;
4200 priv->bSwRfProcessing = false;
4201 priv->eRFPowerState = eRfOff;
4202 priv->RfOffReason = 0;
4203 priv->LedStrategy = SW_LED_MODE0;
4204 //priv->NumRxOkInPeriod = 0; //YJ,del,080828
4205 //priv->NumTxOkInPeriod = 0; //YJ,del,080828
4206 priv->TxPollingTimes = 0;//lzm add 080826
4207 priv->bLeisurePs = true;
4208 priv->dot11PowerSaveMode = eActive;
4209 //by amy for antenna
4210 priv->AdMinCheckPeriod = 5;
4211 priv->AdMaxCheckPeriod = 10;
4212 // Lower signal strength threshold to fit the HW participation in antenna diversity. +by amy 080312
4213 priv->AdMaxRxSsThreshold = 30;//60->30
4214 priv->AdRxSsThreshold = 20;//50->20
4215 priv->AdCheckPeriod = priv->AdMinCheckPeriod;
4216 priv->AdTickCount = 0;
4217 priv->AdRxSignalStrength = -1;
4218 priv->RegSwAntennaDiversityMechanism = 0;
4219 priv->RegDefaultAntenna = 0;
4220 priv->SignalStrength = 0;
4221 priv->AdRxOkCnt = 0;
4222 priv->CurrAntennaIndex = 0;
4223 priv->AdRxSsBeforeSwitched = 0;
4224 init_timer(&priv->SwAntennaDiversityTimer);
4225 priv->SwAntennaDiversityTimer.data = (unsigned long)dev;
4226 priv->SwAntennaDiversityTimer.function = (void *)SwAntennaDiversityTimerCallback;
4227 //by amy for antenna
4229 priv->bDigMechanism = 1;
4230 priv->InitialGain = 6;
4231 priv->bXtalCalibration = false;
4232 priv->XtalCal_Xin = 0;
4233 priv->XtalCal_Xout = 0;
4234 priv->bTxPowerTrack = false;
4235 priv->ThermalMeter = 0;
4236 priv->FalseAlarmRegValue = 0;
4237 priv->RegDigOfdmFaUpTh = 0xc; // Upper threhold of OFDM false alarm, which is used in DIG.
4238 priv->DIG_NumberFallbackVote = 0;
4239 priv->DIG_NumberUpgradeVote = 0;
4240 priv->LastSignalStrengthInPercent = 0;
4241 priv->Stats_SignalStrength = 0;
4242 priv->LastRxPktAntenna = 0;
4243 priv->SignalQuality = 0; // in 0-100 index.
4244 priv->Stats_SignalQuality = 0;
4245 priv->RecvSignalPower = 0; // in dBm.
4246 priv->Stats_RecvSignalPower = 0;
4247 priv->AdMainAntennaRxOkCnt = 0;
4248 priv->AdAuxAntennaRxOkCnt = 0;
4249 priv->bHWAdSwitched = false;
4250 priv->bRegHighPowerMechanism = true;
4251 priv->RegHiPwrUpperTh = 77;
4252 priv->RegHiPwrLowerTh = 75;
4253 priv->RegRSSIHiPwrUpperTh = 70;
4254 priv->RegRSSIHiPwrLowerTh = 20;
4255 priv->bCurCCKPkt = false;
4256 priv->UndecoratedSmoothedSS = -1;
4257 priv->bToUpdateTxPwr = false;
4258 priv->CurCCKRSSI = 0;
4262 priv->NumTxOkTotal = 0;
4263 priv->NumTxUnicast = 0;
4264 priv->keepAliveLevel = DEFAULT_KEEP_ALIVE_LEVEL;
4265 priv->PowerProfile = POWER_PROFILE_AC;
4267 //by amy for rate adaptive
4268 priv->CurrRetryCnt=0;
4269 priv->LastRetryCnt=0;
4270 priv->LastTxokCnt=0;
4271 priv->LastRxokCnt=0;
4272 priv->LastRetryRate=0;
4275 priv->CurrRetryRate=0;
4276 priv->TryupingCount=0;
4277 priv->TryupingCountNoData=0;
4278 priv->TryDownCountLowData=0;
4279 priv->LastTxOKBytes=0;
4280 priv->LastFailTxRate=0;
4281 priv->LastFailTxRateSS=0;
4282 priv->FailTxRateCount=0;
4283 priv->LastTxThroughput=0;
4284 priv->NumTxOkBytesTotal=0;
4285 priv->ForcedDataRate = 0;
4286 priv->RegBModeGainStage = 1;
4288 //by amy for rate adaptive
4290 priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
4291 spin_lock_init(&priv->irq_lock);
4292 spin_lock_init(&priv->irq_th_lock);
4293 spin_lock_init(&priv->tx_lock);
4294 spin_lock_init(&priv->ps_lock);
4295 spin_lock_init(&priv->rf_ps_lock);
4296 sema_init(&priv->wx_sem,1);
4297 sema_init(&priv->rf_state,1);
4298 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
4299 INIT_WORK(&priv->reset_wq,(void*) rtl8180_restart_wq);
4300 INIT_WORK(&priv->tx_irq_wq,(void*) rtl8180_tx_irq_wq);
4301 INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8180_hw_wakeup_wq);
4302 INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8180_hw_sleep_wq);
4303 //INIT_DELAYED_WORK(&priv->ieee80211->watch_dog_wq,(void*) rtl8180_watch_dog_wq);
4304 //INIT_DELAYED_WORK(&priv->ieee80211->sw_antenna_wq,(void*) rtl8180_sw_antenna_wq);
4305 INIT_WORK(&priv->ieee80211->wmm_param_update_wq,(void*) rtl8180_wmm_param_update);
4306 INIT_DELAYED_WORK(&priv->ieee80211->rate_adapter_wq,(void*)rtl8180_rate_adapter);//+by amy 080312
4307 INIT_DELAYED_WORK(&priv->ieee80211->hw_dig_wq,(void*)rtl8180_hw_dig_wq);//+by amy 080312
4308 INIT_DELAYED_WORK(&priv->ieee80211->tx_pw_wq,(void*)rtl8180_tx_pw_wq);//+by amy 080312
4310 //add for RF power on power off by lizhaoming 080512
4311 INIT_DELAYED_WORK(&priv->ieee80211->GPIOChangeRFWorkItem,(void*) GPIOChangeRFWorkItemCallBack);
4313 INIT_WORK(&priv->reset_wq,(void*) rtl8180_restart_wq,dev);
4314 INIT_WORK(&priv->tx_irq_wq,(void*) rtl8180_tx_irq_wq,dev);
4315 //INIT_WORK(&priv->ieee80211->watch_dog_wq,(void*) rtl8180_watch_dog_wq,dev);
4316 INIT_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8180_hw_wakeup_wq,dev);
4317 INIT_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8180_hw_sleep_wq,dev);
4318 //INIT_WORK(&priv->ieee80211->sw_antenna_wq,(void*) rtl8180_sw_antenna_wq,dev);
4319 INIT_WORK(&priv->ieee80211->wmm_param_update_wq,(void*) rtl8180_wmm_param_update,priv->ieee80211);
4320 INIT_WORK(&priv->ieee80211->rate_adapter_wq,(void*)rtl8180_rate_adapter,dev);//+by amy 080312
4321 INIT_WORK(&priv->ieee80211->hw_dig_wq,(void*)rtl8180_hw_dig_wq,dev);//+by amy 080312
4322 INIT_WORK(&priv->ieee80211->tx_pw_wq,(void*)rtl8180_tx_pw_wq,dev);//+by amy 080312
4324 //add for RF power on power off by lizhaoming 080512
4325 INIT_WORK(&priv->ieee80211->GPIOChangeRFWorkItem,(void*) GPIOChangeRFWorkItemCallBack, priv->ieee80211);
4327 //INIT_WORK(&priv->reset_wq,(void*) rtl8180_restart_wq,dev);
4329 tasklet_init(&priv->irq_rx_tasklet,
4330 (void(*)(unsigned long)) rtl8180_irq_rx_tasklet,
4331 (unsigned long)priv);
4333 init_timer(&priv->watch_dog_timer);
4334 priv->watch_dog_timer.data = (unsigned long)dev;
4335 priv->watch_dog_timer.function = watch_dog_adaptive;
4339 //by amy for rate adaptive
4340 init_timer(&priv->rateadapter_timer);
4341 priv->rateadapter_timer.data = (unsigned long)dev;
4342 priv->rateadapter_timer.function = timer_rate_adaptive;
4343 priv->RateAdaptivePeriod= RATE_ADAPTIVE_TIMER_PERIOD;
4344 priv->bEnhanceTxPwr=false;
4345 //by amy for rate adaptive
4347 //priv->ieee80211->func =
4348 // kmalloc(sizeof(struct ieee80211_helper_functions),GFP_KERNEL);
4349 //memset(priv->ieee80211->func, 0,
4350 // sizeof(struct ieee80211_helper_functions));
4352 priv->ieee80211->softmac_hard_start_xmit = rtl8180_hard_start_xmit;
4353 priv->ieee80211->set_chan = rtl8180_set_chan;
4354 priv->ieee80211->link_change = rtl8180_link_change;
4355 priv->ieee80211->softmac_data_hard_start_xmit = rtl8180_hard_data_xmit;
4356 priv->ieee80211->data_hard_stop = rtl8180_data_hard_stop;
4357 priv->ieee80211->data_hard_resume = rtl8180_data_hard_resume;
4359 priv->ieee80211->init_wmmparam_flag = 0;
4361 priv->ieee80211->start_send_beacons = rtl8180_start_tx_beacon;
4362 priv->ieee80211->stop_send_beacons = rtl8180_beacon_tx_disable;
4363 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
4365 #ifdef CONFIG_RTL8185B
4366 priv->MWIEnable = 0;
4368 priv->ShortRetryLimit = 7;
4369 priv->LongRetryLimit = 7;
4370 priv->EarlyRxThreshold = 7;
4372 priv->CSMethod = (0x01 << 29);
4374 priv->TransmitConfig =
4375 1<<TCR_DurProcMode_OFFSET | //for RTL8185B, duration setting by HW
4376 (7<<TCR_MXDMA_OFFSET) | // Max DMA Burst Size per Tx DMA Burst, 7: reservied.
4377 (priv->ShortRetryLimit<<TCR_SRL_OFFSET) | // Short retry limit
4378 (priv->LongRetryLimit<<TCR_LRL_OFFSET) | // Long retry limit
4379 (0 ? TCR_SAT : 0); // FALSE: HW provies PLCP length and LENGEXT, TURE: SW proiveds them
4381 priv->ReceiveConfig =
4382 #ifdef CONFIG_RTL818X_S
4387 RCR_AMF | RCR_ADF | //accept management/data
4388 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
4389 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
4390 //RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet
4391 (7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
4392 (priv->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold.
4393 (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT:0);
4395 priv->IntrMask = IMR_TMGDOK | IMR_TBDER | IMR_THPDER |
4396 IMR_THPDER | IMR_THPDOK |
4397 IMR_TVODER | IMR_TVODOK |
4398 IMR_TVIDER | IMR_TVIDOK |
4399 IMR_TBEDER | IMR_TBEDOK |
4400 IMR_TBKDER | IMR_TBKDOK |
4401 IMR_RDU | // To handle the defragmentation not enough Rx descriptors case. Annie, 2006-03-27.
4403 IMR_RQoSOK; // <NOTE> ROK and RQoSOK are mutually exclusive, so, we must handle RQoSOK interrupt to receive QoS frames, 2005.12.09, by rcnjko.
4405 priv->InitialGain = 6;
4408 hw_version =( read_nic_dword(dev, TCR) & TCR_HWVERID_MASK)>>TCR_HWVERID_SHIFT;
4410 switch (hw_version){
4411 #ifdef CONFIG_RTL8185B
4412 case HW_VERID_R8185B_B:
4413 #ifdef CONFIG_RTL818X_S
4414 priv->card_8185 = VERSION_8187S_C;
4415 DMESG("MAC controller is a RTL8187SE b/g");
4419 DMESG("MAC controller is a RTL8185B b/g");
4420 priv->card_8185 = 3;
4425 case HW_VERID_R8185_ABC:
4426 DMESG("MAC controller is a RTL8185 b/g");
4427 priv->card_8185 = 1;
4428 /* you should not find a card with 8225 PHY ver < C*/
4432 case HW_VERID_R8185_D:
4433 DMESG("MAC controller is a RTL8185 b/g (V. D)");
4434 priv->card_8185 = 2;
4435 /* you should not find a card with 8225 PHY ver < C*/
4439 case HW_VERID_R8180_ABCD:
4440 DMESG("MAC controller is a RTL8180");
4441 priv->card_8185 = 0;
4444 case HW_VERID_R8180_F:
4445 DMESG("MAC controller is a RTL8180 (v. F)");
4446 priv->card_8185 = 0;
4450 DMESGW("MAC chip not recognized: version %x. Assuming RTL8180",hw_version);
4451 priv->card_8185 = 0;
4455 if(priv->card_8185){
4456 priv->ieee80211->modulation |= IEEE80211_OFDM_MODULATION;
4457 priv->ieee80211->short_slot = 1;
4459 /* you should not found any 8185 Ver B Card */
4460 priv->card_8185_Bversion = 0;
4462 #ifdef CONFIG_RTL8185B
4463 #ifdef CONFIG_RTL818X_S
4465 priv->card_type = PCI;
4466 DMESG("This is a PCI NIC");
4468 config3 = read_nic_byte(dev, CONFIG3);
4470 priv->card_type = CARDBUS;
4471 DMESG("This is a CARDBUS NIC");
4473 else if( config3 & 0x4){
4474 priv->card_type = MINIPCI;
4475 DMESG("This is a MINI-PCI NIC");
4477 priv->card_type = PCI;
4478 DMESG("This is a PCI NIC");
4482 priv->enable_gpio0 = 0;
4484 //by amy for antenna
4485 #ifdef CONFIG_RTL8185B
4486 usValue = eprom_read(dev, EEPROM_SW_REVD_OFFSET);
4487 DMESG("usValue is 0x%x\n",usValue);
4488 #ifdef CONFIG_RTL818X_S
4489 //3Read AntennaDiversity
4490 // SW Antenna Diversity.
4491 if( (usValue & EEPROM_SW_AD_MASK) != EEPROM_SW_AD_ENABLE )
4493 priv->EEPROMSwAntennaDiversity = false;
4494 //printk("EEPROM Disable SW Antenna Diversity\n");
4498 priv->EEPROMSwAntennaDiversity = true;
4499 //printk("EEPROM Enable SW Antenna Diversity\n");
4501 // Default Antenna to use.
4502 if( (usValue & EEPROM_DEF_ANT_MASK) != EEPROM_DEF_ANT_1 )
4504 priv->EEPROMDefaultAntenna1 = false;
4505 //printk("EEPROM Default Antenna 0\n");
4509 priv->EEPROMDefaultAntenna1 = true;
4510 //printk("EEPROM Default Antenna 1\n");
4514 // Antenna diversity mechanism. Added by Roger, 2007.11.05.
4516 if( priv->RegSwAntennaDiversityMechanism == 0 ) // Auto
4517 {// 0: default from EEPROM.
4518 priv->bSwAntennaDiverity = priv->EEPROMSwAntennaDiversity;
4521 {// 1:disable antenna diversity, 2: enable antenna diversity.
4522 priv->bSwAntennaDiverity = ((priv->RegSwAntennaDiversityMechanism == 1)? false : true);
4524 //printk("bSwAntennaDiverity = %d\n", priv->bSwAntennaDiverity);
4528 // Default antenna settings. Added by Roger, 2007.11.05.
4530 if( priv->RegDefaultAntenna == 0)
4531 {// 0: default from EEPROM.
4532 priv->bDefaultAntenna1 = priv->EEPROMDefaultAntenna1;
4535 {// 1: main, 2: aux.
4536 priv->bDefaultAntenna1 = ((priv->RegDefaultAntenna== 2) ? true : false);
4538 //printk("bDefaultAntenna1 = %d\n", priv->bDefaultAntenna1);
4541 //by amy for antenna
4542 /* rtl8185 can calc plcp len in HW.*/
4543 priv->hw_plcp_len = 1;
4545 priv->plcp_preamble_mode = 2;
4546 /*the eeprom type is stored in RCR register bit #6 */
4547 if (RCR_9356SEL & read_nic_dword(dev, RCR)){
4548 priv->epromtype=EPROM_93c56;
4549 //DMESG("Reported EEPROM chip is a 93c56 (2Kbit)");
4551 priv->epromtype=EPROM_93c46;
4552 //DMESG("Reported EEPROM chip is a 93c46 (1Kbit)");
4555 dev->dev_addr[0]=eprom_read(dev,MAC_ADR) & 0xff;
4556 dev->dev_addr[1]=(eprom_read(dev,MAC_ADR) & 0xff00)>>8;
4557 dev->dev_addr[2]=eprom_read(dev,MAC_ADR+1) & 0xff;
4558 dev->dev_addr[3]=(eprom_read(dev,MAC_ADR+1) & 0xff00)>>8;
4559 dev->dev_addr[4]=eprom_read(dev,MAC_ADR+2) & 0xff;
4560 dev->dev_addr[5]=(eprom_read(dev,MAC_ADR+2) & 0xff00)>>8;
4561 //DMESG("Card MAC address is "MAC_FMT, MAC_ARG(dev->dev_addr));
4564 for(i=1,j=0; i<14; i+=2,j++){
4566 word = eprom_read(dev,EPROM_TXPW_CH1_2 + j);
4567 priv->chtxpwr[i]=word & 0xff;
4568 priv->chtxpwr[i+1]=(word & 0xff00)>>8;
4570 DMESG("tx word %x:%x",j,word);
4571 DMESG("ch %d pwr %x",i,priv->chtxpwr[i]);
4572 DMESG("ch %d pwr %x",i+1,priv->chtxpwr[i+1]);
4575 if(priv->card_8185){
4576 for(i=1,j=0; i<14; i+=2,j++){
4578 word = eprom_read(dev,EPROM_TXPW_OFDM_CH1_2 + j);
4579 priv->chtxpwr_ofdm[i]=word & 0xff;
4580 priv->chtxpwr_ofdm[i+1]=(word & 0xff00)>>8;
4582 DMESG("ofdm tx word %x:%x",j,word);
4583 DMESG("ofdm ch %d pwr %x",i,priv->chtxpwr_ofdm[i]);
4584 DMESG("ofdm ch %d pwr %x",i+1,priv->chtxpwr_ofdm[i+1]);
4589 //3Read crystal calibtration and thermal meter indication on 87SE.
4591 // By SD3 SY's request. Added by Roger, 2007.12.11.
4593 tmpu16 = eprom_read(dev, EEPROM_RSV>>1);
4595 //printk("ReadAdapterInfo8185(): EEPROM_RSV(%04x)\n", tmpu16);
4597 // Crystal calibration for Xin and Xout resp.
4598 priv->XtalCal_Xout = tmpu16 & EEPROM_XTAL_CAL_XOUT_MASK; // 0~7.5pF
4599 priv->XtalCal_Xin = (tmpu16 & EEPROM_XTAL_CAL_XIN_MASK)>>4; // 0~7.5pF
4600 if((tmpu16 & EEPROM_XTAL_CAL_ENABLE)>>12)
4601 priv->bXtalCalibration = true;
4603 // Thermal meter reference indication.
4604 priv->ThermalMeter = (u8)((tmpu16 & EEPROM_THERMAL_METER_MASK)>>8);
4605 if((tmpu16 & EEPROM_THERMAL_METER_ENABLE)>>13)
4606 priv->bTxPowerTrack = true;
4609 #ifdef CONFIG_RTL8185B
4610 word = eprom_read(dev,EPROM_TXPW_BASE);
4611 priv->cck_txpwr_base = word & 0xf;
4612 priv->ofdm_txpwr_base = (word>>4) & 0xf;
4615 version = eprom_read(dev,EPROM_VERSION);
4616 DMESG("EEPROM version %x",version);
4617 if( (!priv->card_8185) && version < 0x0101){
4618 DMESG ("EEPROM version too old, assuming defaults");
4619 DMESG ("If you see this message *plase* send your \
4620 DMESG output to andreamrl@tiscali.it THANKS");
4624 priv->cs_treshold=0xc;
4626 priv->rf_chip=RFCHIPID_PHILIPS;
4628 if(!priv->card_8185){
4629 u8 rfparam = eprom_read(dev,RF_PARAM);
4630 DMESG("RfParam: %x",rfparam);
4632 priv->digphy = rfparam & (1<<RF_PARAM_DIGPHY_SHIFT) ? 0:1;
4633 priv->antb = rfparam & (1<<RF_PARAM_ANTBDEFAULT_SHIFT) ? 1:0;
4635 priv->rcr_csense = (rfparam & RF_PARAM_CARRIERSENSE_MASK) >>
4636 RF_PARAM_CARRIERSENSE_SHIFT;
4639 (read_nic_byte(dev,CONFIG2)&(1<<CONFIG2_ANTENNA_SHIFT)) ? 1:0;
4641 priv->rcr_csense = 3;
4644 priv->cs_treshold = (eprom_read(dev,ENERGY_TRESHOLD)&0xff00) >>8;
4646 priv->rf_chip = 0xff & eprom_read(dev,RFCHIPID);
4649 #ifdef CONFIG_RTL8185B
4650 #ifdef CONFIG_RTL818X_S
4651 priv->rf_chip = RF_ZEBRA4;
4652 priv->rf_sleep = rtl8225z4_rf_sleep;
4653 priv->rf_wakeup = rtl8225z4_rf_wakeup;
4655 priv->rf_chip = RF_ZEBRA2;
4657 //DMESG("Card reports RF frontend Realtek 8225z2");
4658 //DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4659 //DMESGW("use it with care and at your own risk and");
4660 DMESGW("**PLEASE** REPORT SUCCESSFUL/UNSUCCESSFUL TO Realtek!");
4662 priv->rf_close = rtl8225z2_rf_close;
4663 priv->rf_init = rtl8225z2_rf_init;
4664 priv->rf_set_chan = rtl8225z2_rf_set_chan;
4665 priv->rf_set_sens = NULL;
4666 //priv->rf_sleep = rtl8225_rf_sleep;
4667 //priv->rf_wakeup = rtl8225_rf_wakeup;
4670 /* check RF frontend chipset */
4671 switch (priv->rf_chip) {
4673 case RFCHIPID_RTL8225:
4675 if(priv->card_8185){
4676 DMESG("Card reports RF frontend Realtek 8225");
4677 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4678 DMESGW("use it with care and at your own risk and");
4679 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4681 priv->rf_close = rtl8225_rf_close;
4682 priv->rf_init = rtl8225_rf_init;
4683 priv->rf_set_chan = rtl8225_rf_set_chan;
4684 priv->rf_set_sens = NULL;
4685 priv->rf_sleep = rtl8225_rf_sleep;
4686 priv->rf_wakeup = rtl8225_rf_wakeup;
4689 DMESGW("Detected RTL8225 radio on a card recognized as RTL8180");
4690 DMESGW("This could not be... something went wrong....");
4695 case RFCHIPID_RTL8255:
4696 if(priv->card_8185){
4697 DMESG("Card reports RF frontend Realtek 8255");
4698 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4699 DMESGW("use it with care and at your own risk and");
4700 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4702 priv->rf_close = rtl8255_rf_close;
4703 priv->rf_init = rtl8255_rf_init;
4704 priv->rf_set_chan = rtl8255_rf_set_chan;
4705 priv->rf_set_sens = NULL;
4706 priv->rf_sleep = NULL;
4707 priv->rf_wakeup = NULL;
4710 DMESGW("Detected RTL8255 radio on a card recognized as RTL8180");
4711 DMESGW("This could not be... something went wrong....");
4717 case RFCHIPID_INTERSIL:
4718 DMESGW("Card reports RF frontend by Intersil.");
4719 DMESGW("This driver has NO support for this chipset.");
4724 DMESGW("Card reports RF frontend by RFMD.");
4725 DMESGW("This driver has NO support for this chipset.");
4730 DMESGW("Card reports RF frontend by GCT.");
4731 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4732 DMESGW("use it with care and at your own risk and");
4733 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4734 priv->rf_close = gct_rf_close;
4735 priv->rf_init = gct_rf_init;
4736 priv->rf_set_chan = gct_rf_set_chan;
4737 priv->rf_set_sens = NULL;
4738 priv->rf_sleep = NULL;
4739 priv->rf_wakeup = NULL;
4742 case RFCHIPID_MAXIM:
4743 DMESGW("Card reports RF frontend by MAXIM.");
4744 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4745 DMESGW("use it with care and at your own risk and");
4746 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4747 priv->rf_close = maxim_rf_close;
4748 priv->rf_init = maxim_rf_init;
4749 priv->rf_set_chan = maxim_rf_set_chan;
4750 priv->rf_set_sens = NULL;
4751 priv->rf_sleep = NULL;
4752 priv->rf_wakeup = NULL;
4755 case RFCHIPID_PHILIPS:
4756 DMESG("Card reports RF frontend by Philips.");
4757 DMESG("OK! Philips SA2400 radio chipset is supported.");
4758 priv->rf_close = sa2400_rf_close;
4759 priv->rf_init = sa2400_rf_init;
4760 priv->rf_set_chan = sa2400_rf_set_chan;
4761 priv->rf_set_sens = sa2400_rf_set_sens;
4762 priv->sens = SA2400_RF_DEF_SENS; /* default sensitivity */
4763 priv->max_sens = SA2400_RF_MAX_SENS; /* maximum sensitivity */
4764 priv->rf_sleep = NULL;
4765 priv->rf_wakeup = NULL;
4768 DMESGW("Digital PHY found");
4769 DMESGW("Philips DIGITAL PHY is untested! *Please*\
4770 report success/failure to <andreamrl@tiscali.it>");
4772 DMESG ("Analog PHY found");
4778 DMESGW("Unknown RF module %x",priv->rf_chip);
4779 DMESGW("Exiting...");
4786 if(!priv->card_8185){
4788 DMESG ("Antenna B is default antenna");
4790 DMESG ("Antenna A is default antenna");
4793 DMESG ("Antenna diversity is enabled");
4795 DMESG("Antenna diversity is disabled");
4797 DMESG("Carrier sense %d",priv->rcr_csense);
4800 if (0!=alloc_rx_desc_ring(dev, priv->rxbuffersize, priv->rxringcount))
4803 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4804 TX_MANAGEPRIORITY_RING_ADDR))
4807 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4808 TX_BKPRIORITY_RING_ADDR))
4811 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4812 TX_BEPRIORITY_RING_ADDR))
4815 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4816 TX_VIPRIORITY_RING_ADDR))
4819 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4820 TX_VOPRIORITY_RING_ADDR))
4823 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4824 TX_HIGHPRIORITY_RING_ADDR))
4827 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txbeaconcount,
4828 TX_BEACON_RING_ADDR))
4832 //priv->beacon_buf=NULL;
4834 if(!priv->card_8185){
4836 if(read_nic_byte(dev, CONFIG0) & (1<<CONFIG0_WEP40_SHIFT))
4837 DMESG ("40-bit WEP is supported in hardware");
4839 DMESG ("40-bit WEP is NOT supported in hardware");
4841 if(read_nic_byte(dev,CONFIG0) & (1<<CONFIG0_WEP104_SHIFT))
4842 DMESG ("104-bit WEP is supported in hardware");
4844 DMESG ("104-bit WEP is NOT supported in hardware");
4846 #if !defined(SA_SHIRQ)
4847 if(request_irq(dev->irq, (void *)rtl8180_interrupt, IRQF_SHARED, dev->name, dev)){
4849 if(request_irq(dev->irq, (void *)rtl8180_interrupt, SA_SHIRQ, dev->name, dev)){
4851 DMESGE("Error allocating IRQ %d",dev->irq);
4855 DMESG("IRQ %d",dev->irq);
4867 void rtl8180_no_hw_wep(struct net_device *dev)
4869 struct r8180_priv *priv = ieee80211_priv(dev);
4871 if(!priv->card_8185)
4875 security = read_nic_byte(dev, SECURITY);
4876 security &=~(1<<SECURITY_WEP_TX_ENABLE_SHIFT);
4877 security &=~(1<<SECURITY_WEP_RX_ENABLE_SHIFT);
4879 write_nic_byte(dev, SECURITY, security);
4886 write_nic_dword(dev,TX_CONF,read_nic_dword(dev,TX_CONF) |
4887 (1<<TX_NOICV_SHIFT) );
4889 // priv->ieee80211->hw_wep=0;
4893 void rtl8180_set_hw_wep(struct net_device *dev)
4895 struct r8180_priv *priv = ieee80211_priv(dev);
4900 pgreg=read_nic_byte(dev, PGSELECT);
4901 write_nic_byte(dev, PGSELECT, pgreg &~ (1<<PGSELECT_PG_SHIFT));
4903 key0_word4 = read_nic_dword(dev, KEY0+4+4+4);
4904 key0_word4 &= ~ 0xff;
4905 key0_word4 |= priv->key0[3]& 0xff;
4906 write_nic_dword(dev,KEY0,(priv->key0[0]));
4907 write_nic_dword(dev,KEY0+4,(priv->key0[1]));
4908 write_nic_dword(dev,KEY0+4+4,(priv->key0[2]));
4909 write_nic_dword(dev,KEY0+4+4+4,(key0_word4));
4912 TX_CONF,read_nic_dword(dev,TX_CONF) &~(1<<TX_NOICV_SHIFT));
4915 security = read_nic_byte(dev,SECURITY);
4916 security |= (1<<SECURITY_WEP_TX_ENABLE_SHIFT);
4917 security |= (1<<SECURITY_WEP_RX_ENABLE_SHIFT);
4918 security &= ~ SECURITY_ENCRYP_MASK;
4919 security |= (SECURITY_ENCRYP_104<<SECURITY_ENCRYP_SHIFT);
4921 write_nic_byte(dev, SECURITY, security);
4923 DMESG("key %x %x %x %x",read_nic_dword(dev,KEY0+4+4+4),
4924 read_nic_dword(dev,KEY0+4+4),read_nic_dword(dev,KEY0+4),
4925 read_nic_dword(dev,KEY0));
4927 //priv->ieee80211->hw_wep=1;
4931 void rtl8185_rf_pins_enable(struct net_device *dev)
4934 // tmp = read_nic_word(dev, RFPinsEnable);
4935 write_nic_word(dev, RFPinsEnable, 0x1fff);// | tmp);
4936 // write_nic_word(dev, RFPinsEnable,7 | tmp);
4940 void rtl8185_set_anaparam2(struct net_device *dev, u32 a)
4944 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
4946 conf3 = read_nic_byte(dev, CONFIG3);
4947 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
4948 write_nic_dword(dev, ANAPARAM2, a);
4950 conf3 = read_nic_byte(dev, CONFIG3);
4951 write_nic_byte(dev, CONFIG3, conf3 &~(1<<CONFIG3_ANAPARAM_W_SHIFT));
4952 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
4957 void rtl8180_set_anaparam(struct net_device *dev, u32 a)
4961 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
4963 conf3 = read_nic_byte(dev, CONFIG3);
4964 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
4965 write_nic_dword(dev, ANAPARAM, a);
4967 conf3 = read_nic_byte(dev, CONFIG3);
4968 write_nic_byte(dev, CONFIG3, conf3 &~(1<<CONFIG3_ANAPARAM_W_SHIFT));
4969 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
4973 void rtl8185_tx_antenna(struct net_device *dev, u8 ant)
4975 write_nic_byte(dev, TX_ANTENNA, ant);
4976 force_pci_posting(dev);
4981 void rtl8185_write_phy(struct net_device *dev, u8 adr, u32 data)
4989 phyw= ((data<<8) | adr);
4992 write_nic_dword(dev, PHY_ADR, phyw);
4994 //read_nic_dword(dev, PHY_ADR);
4996 write_nic_dword(dev, PHY_ADR, 0xffffff7f & phyw);
4997 phyr = read_nic_byte(dev, PHY_READ);
4998 if(phyr == (data&0xff)) break;
5002 // Note that, we must write 0xff7c after 0x7d-0x7f to write BB register.
5003 write_nic_byte(dev, 0x7f, ((phyw & 0xff000000) >> 24));
5004 write_nic_byte(dev, 0x7e, ((phyw & 0x00ff0000) >> 16));
5005 write_nic_byte(dev, 0x7d, ((phyw & 0x0000ff00) >> 8));
5006 write_nic_byte(dev, 0x7c, ((phyw & 0x000000ff) ));
5008 /* this is ok to fail when we write AGC table. check for AGC table might be
5009 * done by masking with 0x7f instead of 0xff
5011 //if(phyr != (data&0xff)) DMESGW("Phy write timeout %x %x %x", phyr, data,adr);
5015 inline void write_phy_ofdm (struct net_device *dev, u8 adr, u32 data)
5018 rtl8185_write_phy(dev, adr, data);
5022 void write_phy_cck (struct net_device *dev, u8 adr, u32 data)
5025 rtl8185_write_phy(dev, adr, data | 0x10000);
5030 * I hope this is enougth
5033 void write_phy(struct net_device *dev, u8 adr, u8 data)
5040 phy |= 0x80; /* this should enable writing */
5043 //PHY_ADR, PHY_R and PHY_W are contig and treated as one dword
5044 write_nic_dword(dev,PHY_ADR, phy);
5049 write_nic_dword(dev,PHY_ADR, phy);
5050 for(i=0;i<MAX_PHY;i++){
5051 phy=read_nic_dword(dev,PHY_ADR);
5052 phy= phy & 0xff0000;
5054 if(phy == data){ //SUCCESS!
5055 force_pci_posting(dev);
5056 mdelay(3); //random value
5058 DMESG("Phy wr %x,%x",adr,data);
5062 force_pci_posting(dev);
5063 mdelay(3); //random value
5066 DMESGW ("Phy writing %x %x failed!", adr,data);
5069 void rtl8185_set_rate(struct net_device *dev)
5073 int basic_rate,min_rr_rate,max_rr_rate;
5075 // struct r8180_priv *priv = ieee80211_priv(dev);
5077 //if (ieee80211_is_54g(priv->ieee80211->current_network) &&
5078 // priv->ieee80211->state == IEEE80211_LINKED){
5079 basic_rate = ieeerate2rtlrate(240);
5080 min_rr_rate = ieeerate2rtlrate(60);
5081 max_rr_rate = ieeerate2rtlrate(240);
5085 // basic_rate = ieeerate2rtlrate(20);
5086 // min_rr_rate = ieeerate2rtlrate(10);
5087 // max_rr_rate = ieeerate2rtlrate(110);
5090 write_nic_byte(dev, RESP_RATE,
5091 max_rr_rate<<MAX_RESP_RATE_SHIFT| min_rr_rate<<MIN_RESP_RATE_SHIFT);
5093 word = read_nic_word(dev, BRSR);
5094 word &= ~BRSR_MBR_8185;
5097 for(i=0;i<=basic_rate;i++)
5100 write_nic_word(dev, BRSR, word);
5101 //DMESG("RR:%x BRSR: %x", read_nic_byte(dev,RESP_RATE),read_nic_word(dev,BRSR));
5106 void rtl8180_adapter_start(struct net_device *dev)
5108 struct r8180_priv *priv = ieee80211_priv(dev);
5114 rtl8180_rtx_disable(dev);
5117 /* seems that 0xffff or 0xafff will cause
5118 * HW interrupt line crash
5121 //priv->irq_mask = 0xafff;
5122 // priv->irq_mask = 0x4fcf;
5124 /* enable beacon timeout, beacon TX ok and err
5125 * LP tx ok and err, HP TX ok and err, NP TX ok and err,
5126 * RX ok and ERR, and GP timer */
5127 priv->irq_mask = 0x6fcf;
5129 priv->dma_poll_mask = 0;
5131 rtl8180_beacon_tx_disable(dev);
5133 if(priv->card_type == CARDBUS ){
5134 config3=read_nic_byte(dev, CONFIG3);
5135 write_nic_byte(dev,CONFIG3,config3 | CONFIG3_FuncRegEn);
5136 write_nic_word(dev,FEMR, FEMR_INTR | FEMR_WKUP | FEMR_GWAKE |
5137 read_nic_word(dev, FEMR));
5139 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5140 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
5141 write_nic_word(dev, MAC4, ((u32*)dev->dev_addr)[1] & 0xffff );
5142 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5144 rtl8180_update_msr(dev);
5146 if(!priv->card_8185){
5147 anaparam = eprom_read(dev,EPROM_ANAPARAM_ADDRLWORD);
5148 anaparam |= eprom_read(dev,EPROM_ANAPARAM_ADDRHWORD)<<16;
5150 rtl8180_set_anaparam(dev,anaparam);
5152 /* These might be unnecessary since we do in rx_enable / tx_enable */
5155 /*set_nic_rxring(dev);
5156 set_nic_txring(dev);*/
5158 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5161 The following is very strange. seems to be that 1 means test mode,
5162 but we need to acknolwledges the nic when a packet is ready
5163 altought we set it to 0
5167 CONFIG2, read_nic_byte(dev,CONFIG2) &~\
5168 (1<<CONFIG2_DMA_POLLING_MODE_SHIFT));
5169 //^the nic isn't in test mode
5172 CONFIG2, read_nic_byte(dev,CONFIG2)|(1<<4));
5174 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
5176 write_nic_dword(dev,INT_TIMEOUT,0);
5177 #ifdef DEBUG_REGISTERS
5178 rtl8180_dump_reg(dev);
5181 if(!priv->card_8185)
5184 experimental - this might be needed to calibrate AGC,
5185 anyway it shouldn't hurt
5187 write_nic_byte(dev, CONFIG5,
5188 read_nic_byte(dev, CONFIG5) | (1<<AGCRESET_SHIFT));
5189 read_nic_byte(dev, CONFIG5);
5191 write_nic_byte(dev, CONFIG5,
5192 read_nic_byte(dev, CONFIG5) &~ (1<<AGCRESET_SHIFT));
5195 write_nic_byte(dev, WPA_CONFIG, 0);
5196 //write_nic_byte(dev, TESTR, 0xd);
5199 rtl8180_no_hw_wep(dev);
5201 if(priv->card_8185){
5202 rtl8185_set_rate(dev);
5203 write_nic_byte(dev, RATE_FALLBACK, 0x81);
5204 // write_nic_byte(dev, 0xdf, 0x15);
5206 word = read_nic_word(dev, BRSR);
5208 word &= ~BRSR_BPLCP;
5209 word |= ieeerate2rtlrate(priv->ieee80211->basic_rate);
5213 write_nic_word(dev, BRSR, word);
5217 if(priv->card_8185){
5218 write_nic_byte(dev, GP_ENABLE,read_nic_byte(dev, GP_ENABLE) & ~(1<<6));
5220 //FIXME cfg 3 ClkRun enable - isn't it ReadOnly ?
5221 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5222 write_nic_byte(dev,CONFIG3, read_nic_byte(dev, CONFIG3)
5223 |(1<<CONFIG3_CLKRUN_SHIFT));
5224 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5230 if(priv->rf_set_sens != NULL)
5231 priv->rf_set_sens(dev,priv->sens);
5232 rtl8180_irq_enable(dev);
5234 netif_start_queue(dev);
5235 /*DMESG ("lfree %d",get_curr_tx_free_desc(dev,LOW_PRIORITY));
5237 DMESG ("nfree %d",get_curr_tx_free_desc(dev,NORM_PRIORITY));
5239 DMESG ("hfree %d",get_curr_tx_free_desc(dev,HI_PRIORITY));
5240 if(check_nic_enought_desc(dev,NORM_PRIORITY)) DMESG("NORM OK");
5241 if(check_nic_enought_desc(dev,HI_PRIORITY)) DMESG("HI OK");
5242 if(check_nic_enought_desc(dev,LOW_PRIORITY)) DMESG("LOW OK");*/
5247 /* this configures registers for beacon tx and enables it via
5248 * rtl8180_beacon_tx_enable(). rtl8180_beacon_tx_disable() might
5249 * be used to stop beacon transmission
5251 void rtl8180_start_tx_beacon(struct net_device *dev)
5253 // struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
5255 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
5257 DMESG("Enabling beacon TX");
5258 //write_nic_byte(dev, 0x42,0xe6);// TCR
5259 // set_nic_txring(dev);
5260 // fix_tx_fifo(dev);
5261 rtl8180_prepare_beacon(dev);
5262 rtl8180_irq_disable(dev);
5263 rtl8180_beacon_tx_enable(dev);
5265 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
5266 //write_nic_byte(dev,0x9d,0x20); //DMA Poll
5267 //write_nic_word(dev,0x7a,0);
5268 //write_nic_word(dev,0x7a,0x8000);
5271 word = read_nic_word(dev, BcnItv);
5272 word &= ~BcnItv_BcnItv; // clear Bcn_Itv
5273 word |= priv->ieee80211->current_network.beacon_interval;//0x64;
5274 write_nic_word(dev, BcnItv, word);
5277 word = read_nic_word(dev, AtimWnd) &~ AtimWnd_AtimWnd;
5278 write_nic_word(dev, AtimWnd,word);// word |=
5279 //priv->ieee80211->current_network.atim_window);
5281 word = read_nic_word(dev, BintrItv);
5282 word &= ~BintrItv_BintrItv;
5283 word |= 1000;/*priv->ieee80211->current_network.beacon_interval *
5284 ((priv->txbeaconcount > 1)?(priv->txbeaconcount-1):1);
5285 // FIXME: check if correct ^^ worked with 0x3e8;
5287 write_nic_word(dev, BintrItv, word);
5290 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5292 // rtl8180_beacon_tx_enable(dev);
5293 #ifdef CONFIG_RTL8185B
5294 rtl8185b_irq_enable(dev);
5296 rtl8180_irq_enable(dev);
5298 /* VV !!!!!!!!!! VV*/
5300 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
5301 write_nic_byte(dev,0x9d,0x00);
5302 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
5304 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
5310 /***************************************************************************
5311 -------------------------------NET STUFF---------------------------
5312 ***************************************************************************/
5313 static struct net_device_stats *rtl8180_stats(struct net_device *dev)
5315 struct r8180_priv *priv = ieee80211_priv(dev);
5317 return &priv->ieee80211->stats;
5320 // Change current and default preamble mode.
5321 // 2005.01.06, by rcnjko.
5324 MgntActSet_802_11_PowerSaveMode(
5325 struct r8180_priv *priv,
5330 // Currently, we do not change power save mode on IBSS mode.
5331 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
5337 // <RJ_NOTE> If we make HW to fill up the PwrMgt bit for us,
5338 // some AP will not response to our mgnt frames with PwrMgt bit set,
5339 // e.g. cannot associate the AP.
5340 // So I commented out it. 2005.02.16, by rcnjko.
5342 // // Change device's power save mode.
5343 // Adapter->HalFunc.SetPSModeHandler( Adapter, rtPsMode );
5345 // Update power save mode configured.
5346 // priv->dot11PowerSaveMode = rtPsMode;
5347 priv->ieee80211->ps = rtPsMode;
5348 // Determine ListenInterval.
5350 if(priv->dot11PowerSaveMode == eMaxPs)
5352 priv->ieee80211->ListenInterval = 10;
5356 priv->ieee80211->ListenInterval = 2;
5362 //================================================================================
5363 // Leisure Power Save in linked state.
5364 //================================================================================
5368 // Enter the leisure power save mode.
5372 struct r8180_priv *priv
5375 if (priv->bLeisurePs)
5377 if (priv->ieee80211->ps == IEEE80211_PS_DISABLED)
5379 //printk("----Enter PS\n");
5380 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST);//IEEE80211_PS_ENABLE
5388 // Leave the leisure power save mode.
5392 struct r8180_priv *priv
5395 if (priv->bLeisurePs)
5397 if (priv->ieee80211->ps != IEEE80211_PS_DISABLED)
5399 //printk("----Leave PS\n");
5400 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_DISABLED);
5404 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5405 void rtl8180_hw_wakeup_wq (struct work_struct *work)
5407 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
5408 // struct ieee80211_device * ieee = (struct ieee80211_device*)
5409 // container_of(work, struct ieee80211_device, watch_dog_wq);
5410 struct delayed_work *dwork = to_delayed_work(work);
5411 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq);
5412 struct net_device *dev = ieee->dev;
5414 void rtl8180_hw_wakeup_wq(struct net_device *dev)
5416 struct r8180_priv *priv = ieee80211_priv(dev);
5419 // printk("dev is %d\n",dev);
5420 // printk("&*&(^*(&(&=========>%s()\n", __func__);
5421 rtl8180_hw_wakeup(dev);
5425 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5426 void rtl8180_hw_sleep_wq (struct work_struct *work)
5428 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
5429 // struct ieee80211_device * ieee = (struct ieee80211_device*)
5430 // container_of(work, struct ieee80211_device, watch_dog_wq);
5431 struct delayed_work *dwork = to_delayed_work(work);
5432 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq);
5433 struct net_device *dev = ieee->dev;
5435 void rtl8180_hw_sleep_wq(struct net_device *dev)
5437 struct r8180_priv *priv = ieee80211_priv(dev);
5440 rtl8180_hw_sleep_down(dev);
5443 //YJ,add,080828,for KeepAlive
5444 static void MgntLinkKeepAlive(struct r8180_priv *priv )
5446 if (priv->keepAliveLevel == 0)
5449 if(priv->ieee80211->state == IEEE80211_LINKED)
5454 //printk("LastTx:%d Tx:%d LastRx:%d Rx:%ld Idle:%d\n",priv->link_detect.LastNumTxUnicast,priv->NumTxUnicast, priv->link_detect.LastNumRxUnicast, priv->ieee80211->NumRxUnicast, priv->link_detect.IdleCount);
5456 if ( (priv->keepAliveLevel== 2) ||
5457 (priv->link_detect.LastNumTxUnicast == priv->NumTxUnicast &&
5458 priv->link_detect.LastNumRxUnicast == priv->ieee80211->NumRxUnicast )
5461 priv->link_detect.IdleCount++;
5464 // Send a Keep-Alive packet packet to AP if we had been idle for a while.
5466 if(priv->link_detect.IdleCount >= ((KEEP_ALIVE_INTERVAL / CHECK_FOR_HANG_PERIOD)-1) )
5468 priv->link_detect.IdleCount = 0;
5469 ieee80211_sta_ps_send_null_frame(priv->ieee80211, false);
5474 priv->link_detect.IdleCount = 0;
5476 priv->link_detect.LastNumTxUnicast = priv->NumTxUnicast;
5477 priv->link_detect.LastNumRxUnicast = priv->ieee80211->NumRxUnicast;
5480 //YJ,add,080828,for KeepAlive,end
5482 static u8 read_acadapter_file(char *filename);
5483 void rtl8180_watch_dog(struct net_device *dev)
5485 struct r8180_priv *priv = ieee80211_priv(dev);
5486 bool bEnterPS = false;
5487 bool bBusyTraffic = false;
5492 if(priv->ieee80211->actscanning == false){
5493 if((priv->ieee80211->iw_mode != IW_MODE_ADHOC) && (priv->ieee80211->state == IEEE80211_NOLINK) && (priv->ieee80211->beinretry == false) && (priv->eRFPowerState == eRfOn)){
5498 //YJ,add,080828,for link state check
5499 if((priv->ieee80211->state == IEEE80211_LINKED) && (priv->ieee80211->iw_mode == IW_MODE_INFRA)){
5500 SlotIndex = (priv->link_detect.SlotIndex++) % priv->link_detect.SlotNum;
5501 priv->link_detect.RxFrameNum[SlotIndex] = priv->ieee80211->NumRxDataInPeriod + priv->ieee80211->NumRxBcnInPeriod;
5502 for( i=0; i<priv->link_detect.SlotNum; i++ )
5503 TotalRxNum+= priv->link_detect.RxFrameNum[i];
5504 //printk("&&&&&=== TotalRxNum = %d\n", TotalRxNum);
5505 if(TotalRxNum == 0){
5506 priv->ieee80211->state = IEEE80211_ASSOCIATING;
5507 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
5511 //YJ,add,080828,for KeepAlive
5512 MgntLinkKeepAlive(priv);
5514 //YJ,add,080828,for LPS
5516 if(priv->PowerProfile == POWER_PROFILE_BATTERY )
5518 //Turn on LeisurePS on battery power
5519 //printk("!!!!!On battery power\n");
5520 priv->bLeisurePs = true;
5522 else if(priv->PowerProfile == POWER_PROFILE_AC )
5524 // Turn off LeisurePS on AC power
5525 //printk("----On AC power\n");
5526 LeisurePSLeave(priv);
5527 priv->bLeisurePs= false;
5533 if(priv->ieee80211->state == IEEE80211_LINKED){
5534 if( priv->NumRxOkInPeriod> 666 ||
5535 priv->NumTxOkInPeriod > 666 ) {
5536 bBusyTraffic = true;
5538 if((priv->ieee80211->NumRxData + priv->NumTxOkInPeriod)<8) {
5542 LeisurePSEnter(priv);
5545 LeisurePSLeave(priv);
5549 LeisurePSLeave(priv);
5552 priv->NumRxOkInPeriod = 0;
5553 priv->NumTxOkInPeriod = 0;
5554 priv->ieee80211->NumRxData = 0;
5557 if(priv->ieee80211->state == IEEE80211_LINKED){
5558 priv->link_detect.NumRxOkInPeriod = priv->ieee80211->NumRxDataInPeriod;
5559 //printk("TxOk=%d RxOk=%d\n", priv->link_detect.NumTxOkInPeriod, priv->link_detect.NumRxOkInPeriod);
5560 if( priv->link_detect.NumRxOkInPeriod> 666 ||
5561 priv->link_detect.NumTxOkInPeriod> 666 ) {
5562 bBusyTraffic = true;
5564 if(((priv->link_detect.NumRxOkInPeriod + priv->link_detect.NumTxOkInPeriod) > 8)
5565 || (priv->link_detect.NumRxOkInPeriod > 2)) {
5573 LeisurePSEnter(priv);
5576 LeisurePSLeave(priv);
5580 LeisurePSLeave(priv);
5583 priv->link_detect.bBusyTraffic = bBusyTraffic;
5584 priv->link_detect.NumRxOkInPeriod = 0;
5585 priv->link_detect.NumTxOkInPeriod = 0;
5586 priv->ieee80211->NumRxDataInPeriod = 0;
5587 priv->ieee80211->NumRxBcnInPeriod = 0;
5590 int _rtl8180_up(struct net_device *dev)
5592 struct r8180_priv *priv = ieee80211_priv(dev);
5597 DMESG("Bringing up iface");
5598 #ifdef CONFIG_RTL8185B
5599 rtl8185b_adapter_start(dev);
5600 rtl8185b_rx_enable(dev);
5601 rtl8185b_tx_enable(dev);
5603 rtl8180_adapter_start(dev);
5604 rtl8180_rx_enable(dev);
5605 rtl8180_tx_enable(dev);
5608 if(priv->bInactivePs){
5609 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
5615 timer_rate_adaptive((unsigned long)dev);
5618 watch_dog_adaptive((unsigned long)dev);
5620 if(priv->bSwAntennaDiverity)
5621 SwAntennaDiversityTimerCallback(dev);
5624 ieee80211_softmac_start_protocol(priv->ieee80211);
5626 //Add for RF power on power off by lizhaoming 080512
5627 // priv->eRFPowerState = eRfOn;
5628 // printk("\n--------Start queue_work:GPIOChangeRFWorkItem");
5629 // queue_delayed_work(priv->ieee80211->wq,&priv->ieee80211->GPIOChangeRFWorkItem,1000);
5635 int rtl8180_open(struct net_device *dev)
5637 struct r8180_priv *priv = ieee80211_priv(dev);
5640 down(&priv->wx_sem);
5641 ret = rtl8180_up(dev);
5648 int rtl8180_up(struct net_device *dev)
5650 struct r8180_priv *priv = ieee80211_priv(dev);
5652 if (priv->up == 1) return -1;
5654 return _rtl8180_up(dev);
5658 int rtl8180_close(struct net_device *dev)
5660 struct r8180_priv *priv = ieee80211_priv(dev);
5663 down(&priv->wx_sem);
5664 ret = rtl8180_down(dev);
5671 int rtl8180_down(struct net_device *dev)
5673 struct r8180_priv *priv = ieee80211_priv(dev);
5675 if (priv->up == 0) return -1;
5679 ieee80211_softmac_stop_protocol(priv->ieee80211);
5681 if (!netif_queue_stopped(dev))
5682 netif_stop_queue(dev);
5683 rtl8180_rtx_disable(dev);
5684 rtl8180_irq_disable(dev);
5685 del_timer_sync(&priv->watch_dog_timer);
5686 //cancel_delayed_work(&priv->ieee80211->watch_dog_wq);
5688 del_timer_sync(&priv->rateadapter_timer);
5689 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
5691 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
5692 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
5693 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
5694 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
5695 del_timer_sync(&priv->SwAntennaDiversityTimer);
5696 SetZebraRFPowerState8185(dev,eRfOff);
5697 //ieee80211_softmac_stop_protocol(priv->ieee80211);
5698 memset(&(priv->ieee80211->current_network),0,sizeof(struct ieee80211_network));
5699 priv->ieee80211->state = IEEE80211_NOLINK;
5703 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5704 void rtl8180_restart_wq(struct work_struct *work)
5706 struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
5707 struct net_device *dev = priv->dev;
5709 void rtl8180_restart_wq(struct net_device *dev)
5711 struct r8180_priv *priv = ieee80211_priv(dev);
5713 down(&priv->wx_sem);
5715 rtl8180_commit(dev);
5720 void rtl8180_restart(struct net_device *dev)
5722 struct r8180_priv *priv = ieee80211_priv(dev);
5723 //rtl8180_commit(dev);
5724 schedule_work(&priv->reset_wq);
5725 //DMESG("TXTIMEOUT");
5729 void rtl8180_commit(struct net_device *dev)
5731 struct r8180_priv *priv = ieee80211_priv(dev);
5733 if (priv->up == 0) return ;
5735 del_timer_sync(&priv->watch_dog_timer);
5736 //cancel_delayed_work(&priv->ieee80211->watch_dog_wq);
5738 //by amy for rate adaptive
5739 del_timer_sync(&priv->rateadapter_timer);
5740 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
5741 //by amy for rate adaptive
5743 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
5744 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
5745 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
5746 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
5747 del_timer_sync(&priv->SwAntennaDiversityTimer);
5748 ieee80211_softmac_stop_protocol(priv->ieee80211);
5749 rtl8180_irq_disable(dev);
5750 rtl8180_rtx_disable(dev);
5755 static void r8180_set_multicast(struct net_device *dev)
5757 struct r8180_priv *priv = ieee80211_priv(dev);
5760 //down(&priv->wx_sem);
5762 promisc = (dev->flags & IFF_PROMISC) ? 1:0;
5764 if (promisc != priv->promisc)
5765 rtl8180_restart(dev);
5767 priv->promisc = promisc;
5769 //up(&priv->wx_sem);
5773 /* this is called by the kernel when it needs to TX a 802.3 encapsulated frame*/
5774 int rtl8180_8023_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
5776 struct r8180_priv *priv = ieee80211_priv(dev);
5778 unsigned long flags;
5780 spin_lock_irqsave(&priv->tx_lock,flags);
5781 ret = ieee80211_r8180_8023_hardstartxmit(skb,priv->ieee80211);
5782 spin_unlock_irqrestore(&priv->tx_lock,flags);
5787 int r8180_set_mac_adr(struct net_device *dev, void *mac)
5789 struct r8180_priv *priv = ieee80211_priv(dev);
5790 struct sockaddr *addr = mac;
5792 down(&priv->wx_sem);
5794 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
5796 if(priv->ieee80211->iw_mode == IW_MODE_MASTER)
5797 memcpy(priv->ieee80211->current_network.bssid, dev->dev_addr, ETH_ALEN);
5809 /* based on ipw2200 driver */
5810 int rtl8180_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5812 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
5814 struct iwreq *wrq = (struct iwreq *) rq;
5817 case RTL_IOCTL_WPA_SUPPLICANT:
5818 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
5830 /****************************************************************************
5831 -----------------------------PCI STUFF---------------------------
5832 *****************************************************************************/
5834 static const struct net_device_ops rtl8180_netdev_ops = {
5835 .ndo_open = rtl8180_open,
5836 .ndo_stop = rtl8180_close,
5837 .ndo_get_stats = rtl8180_stats,
5838 .ndo_tx_timeout = rtl8180_restart,
5839 .ndo_do_ioctl = rtl8180_ioctl,
5840 .ndo_set_multicast_list = r8180_set_multicast,
5841 .ndo_set_mac_address = r8180_set_mac_adr,
5842 .ndo_validate_addr = eth_validate_addr,
5843 .ndo_change_mtu = eth_change_mtu,
5844 .ndo_start_xmit = ieee80211_xmit,
5847 static int __devinit rtl8180_pci_probe(struct pci_dev *pdev,
5848 const struct pci_device_id *id)
5850 unsigned long ioaddr = 0;
5851 struct net_device *dev = NULL;
5852 struct r8180_priv *priv= NULL;
5856 #ifdef CONFIG_RTL8180_IO_MAP
5857 unsigned long pio_start, pio_len, pio_flags;
5859 unsigned long pmem_start, pmem_len, pmem_flags;
5860 #endif //end #ifdef RTL_IO_MAP
5862 DMESG("Configuring chip resources");
5864 if( pci_enable_device (pdev) ){
5865 DMESG("Failed to enable PCI device");
5869 pci_set_master(pdev);
5870 //pci_set_wmi(pdev);
5871 pci_set_dma_mask(pdev, 0xffffff00ULL);
5872 pci_set_consistent_dma_mask(pdev,0xffffff00ULL);
5873 dev = alloc_ieee80211(sizeof(struct r8180_priv));
5876 priv = ieee80211_priv(dev);
5877 priv->ieee80211 = netdev_priv(dev);
5879 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
5880 SET_MODULE_OWNER(dev);
5882 pci_set_drvdata(pdev, dev);
5883 SET_NETDEV_DEV(dev, &pdev->dev);
5885 priv = ieee80211_priv(dev);
5886 // memset(priv,0,sizeof(struct r8180_priv));
5890 #ifdef CONFIG_RTL8180_IO_MAP
5892 pio_start = (unsigned long)pci_resource_start (pdev, 0);
5893 pio_len = (unsigned long)pci_resource_len (pdev, 0);
5894 pio_flags = (unsigned long)pci_resource_flags (pdev, 0);
5896 if (!(pio_flags & IORESOURCE_IO)) {
5897 DMESG("region #0 not a PIO resource, aborting");
5901 //DMESG("IO space @ 0x%08lx", pio_start );
5902 if( ! request_region( pio_start, pio_len, RTL8180_MODULE_NAME ) ){
5903 DMESG("request_region failed!");
5908 dev->base_addr = ioaddr; // device I/O address
5912 pmem_start = pci_resource_start(pdev, 1);
5913 pmem_len = pci_resource_len(pdev, 1);
5914 pmem_flags = pci_resource_flags (pdev, 1);
5916 if (!(pmem_flags & IORESOURCE_MEM)) {
5917 DMESG("region #1 not a MMIO resource, aborting");
5921 //DMESG("Memory mapped space @ 0x%08lx ", pmem_start);
5922 if( ! request_mem_region(pmem_start, pmem_len, RTL8180_MODULE_NAME)) {
5923 DMESG("request_mem_region failed!");
5928 ioaddr = (unsigned long)ioremap_nocache( pmem_start, pmem_len);
5929 if( ioaddr == (unsigned long)NULL ){
5930 DMESG("ioremap failed!");
5931 // release_mem_region( pmem_start, pmem_len );
5935 dev->mem_start = ioaddr; // shared mem start
5936 dev->mem_end = ioaddr + pci_resource_len(pdev, 0); // shared mem end
5938 #endif //end #ifdef RTL_IO_MAP
5940 #ifdef CONFIG_RTL8185B
5941 //pci_read_config_byte(pdev, 0x05, ptr);
5942 //pci_write_config_byte(pdev, 0x05, (*ptr) & (~0x04));
5943 pci_read_config_byte(pdev, 0x05, &unit);
5944 pci_write_config_byte(pdev, 0x05, unit & (~0x04));
5947 dev->irq = pdev->irq;
5950 dev->netdev_ops = &rtl8180_netdev_ops;
5951 dev->wireless_handlers = &r8180_wx_handlers_def;
5953 #if WIRELESS_EXT >= 12
5954 #if WIRELESS_EXT < 17
5955 dev->get_wireless_stats = r8180_get_wireless_stats;
5957 dev->wireless_handlers = (struct iw_handler_def *) &r8180_wx_handlers_def;
5960 dev->type=ARPHRD_ETHER;
5961 dev->watchdog_timeo = HZ*3; //added by david woo, 2007.12.13
5963 if (dev_alloc_name(dev, ifname) < 0){
5964 DMESG("Oops: devname already taken! Trying wlan%%d...\n");
5966 // ifname = "ath%d";
5967 dev_alloc_name(dev, ifname);
5971 if(rtl8180_init(dev)!=0){
5972 DMESG("Initialization failed");
5976 netif_carrier_off(dev);
5978 register_netdev(dev);
5980 rtl8180_proc_init_one(dev);
5982 DMESG("Driver probe completed\n");
5987 #ifdef CONFIG_RTL8180_IO_MAP
5989 if( dev->base_addr != 0 ){
5991 release_region(dev->base_addr,
5992 pci_resource_len(pdev, 0) );
5995 if( dev->mem_start != (unsigned long)NULL ){
5996 iounmap( (void *)dev->mem_start );
5997 release_mem_region( pci_resource_start(pdev, 1),
5998 pci_resource_len(pdev, 1) );
6000 #endif //end #ifdef RTL_IO_MAP
6007 free_irq(dev->irq, dev);
6010 free_ieee80211(dev);
6013 pci_disable_device(pdev);
6015 DMESG("wlan driver load failed\n");
6016 pci_set_drvdata(pdev, NULL);
6022 static void __devexit rtl8180_pci_remove(struct pci_dev *pdev)
6024 struct r8180_priv *priv;
6025 struct net_device *dev = pci_get_drvdata(pdev);
6028 unregister_netdev(dev);
6030 priv=ieee80211_priv(dev);
6032 rtl8180_proc_remove_one(dev);
6034 priv->rf_close(dev);
6036 //rtl8180_rtx_disable(dev);
6037 //rtl8180_irq_disable(dev);
6039 //write_nic_word(dev,INTA,read_nic_word(dev,INTA));
6040 //force_pci_posting(dev);
6045 DMESG("Freeing irq %d",dev->irq);
6046 free_irq(dev->irq, dev);
6051 free_rx_desc_ring(dev);
6052 free_tx_desc_rings(dev);
6053 // free_beacon_desc_ring(dev,priv->txbeaconcount);
6055 #ifdef CONFIG_RTL8180_IO_MAP
6057 if( dev->base_addr != 0 ){
6059 release_region(dev->base_addr,
6060 pci_resource_len(pdev, 0) );
6063 if( dev->mem_start != (unsigned long)NULL ){
6064 iounmap( (void *)dev->mem_start );
6065 release_mem_region( pci_resource_start(pdev, 1),
6066 pci_resource_len(pdev, 1) );
6068 #endif /*end #ifdef RTL_IO_MAP*/
6070 free_ieee80211(dev);
6072 pci_disable_device(pdev);
6074 DMESG("wlan driver removed\n");
6078 /* fun with the built-in ieee80211 stack... */
6079 extern int ieee80211_crypto_init(void);
6080 extern void ieee80211_crypto_deinit(void);
6081 extern int ieee80211_crypto_tkip_init(void);
6082 extern void ieee80211_crypto_tkip_exit(void);
6083 extern int ieee80211_crypto_ccmp_init(void);
6084 extern void ieee80211_crypto_ccmp_exit(void);
6085 extern int ieee80211_crypto_wep_init(void);
6086 extern void ieee80211_crypto_wep_exit(void);
6088 static int __init rtl8180_pci_module_init(void)
6092 ret = ieee80211_crypto_init();
6094 printk(KERN_ERR "ieee80211_crypto_init() failed %d\n", ret);
6097 ret = ieee80211_crypto_tkip_init();
6099 printk(KERN_ERR "ieee80211_crypto_tkip_init() failed %d\n", ret);
6102 ret = ieee80211_crypto_ccmp_init();
6104 printk(KERN_ERR "ieee80211_crypto_ccmp_init() failed %d\n", ret);
6107 ret = ieee80211_crypto_wep_init();
6109 printk(KERN_ERR "ieee80211_crypto_wep_init() failed %d\n", ret);
6113 printk(KERN_INFO "\nLinux kernel driver for RTL8180 \
6114 / RTL8185 based WLAN cards\n");
6115 printk(KERN_INFO "Copyright (c) 2004-2005, Andrea Merello\n");
6116 DMESG("Initializing module");
6117 DMESG("Wireless extensions version %d", WIRELESS_EXT);
6118 rtl8180_proc_module_init();
6120 #if(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
6121 if(0!=pci_module_init(&rtl8180_pci_driver))
6123 if(0!=pci_register_driver(&rtl8180_pci_driver))
6125 //if(0!=pci_module_init(&rtl8180_pci_driver))
6127 DMESG("No device found");
6128 /*pci_unregister_driver (&rtl8180_pci_driver);*/
6135 static void __exit rtl8180_pci_module_exit(void)
6137 pci_unregister_driver (&rtl8180_pci_driver);
6138 rtl8180_proc_module_remove();
6139 ieee80211_crypto_tkip_exit();
6140 ieee80211_crypto_ccmp_exit();
6141 ieee80211_crypto_wep_exit();
6142 ieee80211_crypto_deinit();
6147 void rtl8180_try_wake_queue(struct net_device *dev, int pri)
6149 unsigned long flags;
6151 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
6153 spin_lock_irqsave(&priv->tx_lock,flags);
6154 enough_desc = check_nic_enought_desc(dev,pri);
6155 spin_unlock_irqrestore(&priv->tx_lock,flags);
6158 ieee80211_wake_queue(priv->ieee80211);
6161 /*****************************************************************************
6162 -----------------------------IRQ STUFF---------------------------
6163 ******************************************************************************/
6165 void rtl8180_tx_isr(struct net_device *dev, int pri,short error)
6167 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
6169 u32 *tail; //tail virtual addr
6170 u32 *head; //head virtual addr
6171 u32 *begin;//start of ring virtual addr
6172 u32 *nicv; //nic pointer virtual addr
6173 // u32 *txdv; //packet just TXed
6174 u32 nic; //nic pointer physical addr
6175 u32 nicbegin;// start of ring physical addr
6178 /* physical addr are ok on 32 bits since we set DMA mask*/
6183 if (error) priv->stats.txretry++; //tony 20060601
6184 spin_lock_irqsave(&priv->tx_lock,flag);
6186 case MANAGE_PRIORITY:
6187 tail = priv->txmapringtail;
6188 begin = priv->txmapring;
6189 head = priv->txmapringhead;
6190 nic = read_nic_dword(dev,TX_MANAGEPRIORITY_RING_ADDR);
6191 nicbegin = priv->txmapringdma;
6195 tail = priv->txbkpringtail;
6196 begin = priv->txbkpring;
6197 head = priv->txbkpringhead;
6198 nic = read_nic_dword(dev,TX_BKPRIORITY_RING_ADDR);
6199 nicbegin = priv->txbkpringdma;
6203 tail = priv->txbepringtail;
6204 begin = priv->txbepring;
6205 head = priv->txbepringhead;
6206 nic = read_nic_dword(dev,TX_BEPRIORITY_RING_ADDR);
6207 nicbegin = priv->txbepringdma;
6211 tail = priv->txvipringtail;
6212 begin = priv->txvipring;
6213 head = priv->txvipringhead;
6214 nic = read_nic_dword(dev,TX_VIPRIORITY_RING_ADDR);
6215 nicbegin = priv->txvipringdma;
6219 tail = priv->txvopringtail;
6220 begin = priv->txvopring;
6221 head = priv->txvopringhead;
6222 nic = read_nic_dword(dev,TX_VOPRIORITY_RING_ADDR);
6223 nicbegin = priv->txvopringdma;
6227 tail = priv->txhpringtail;
6228 begin = priv->txhpring;
6229 head = priv->txhpringhead;
6230 nic = read_nic_dword(dev,TX_HIGHPRIORITY_RING_ADDR);
6231 nicbegin = priv->txhpringdma;
6235 spin_unlock_irqrestore(&priv->tx_lock,flag);
6238 /* DMESG("%x %s %x %x",((int)nic & 0xfff)/8/4,
6239 *(priv->txnpring + ((int)nic&0xfff)/4/8) & (1<<31) ? "filled" : "empty",
6240 (priv->txnpringtail - priv->txnpring)/8,(priv->txnpringhead -
6243 //nicv = (u32*) ((nic - nicbegin) + (int)begin);
6244 nicv = (u32*) ((nic - nicbegin) + (u8*)begin);
6245 if((head <= tail && (nicv > tail || nicv < head)) ||
6246 (head > tail && (nicv > tail && nicv < head))){
6248 DMESGW("nic has lost pointer");
6249 #ifdef DEBUG_TX_DESC
6250 //check_tx_ring(dev,NORM_PRIORITY);
6251 check_tx_ring(dev,pri);
6253 spin_unlock_irqrestore(&priv->tx_lock,flag);
6254 rtl8180_restart(dev);
6258 /* we check all the descriptors between the head and the nic,
6259 * but not the currenly pointed by the nic (the next to be txed)
6260 * and the previous of the pointed (might be in process ??)
6262 //if (head == nic) return;
6263 //DMESG("%x %x",head,nic);
6264 offs = (nic - nicbegin);
6265 //DMESG("%x %x %x",nic ,(u32)nicbegin, (int)nic -nicbegin);
6269 hd = (head - begin) /8;
6274 j = offs + (priv->txringcount -1 -hd);
6275 // j= priv->txringcount -1- (hd - offs);
6283 // printk("+++++++++++++check status desc\n");
6284 if((*head) & (1<<31))
6286 if(((*head)&(0x10000000)) != 0){
6287 // printk("++++++++++++++last desc,retry count is %d\n",((*head) & (0x000000ff)));
6288 priv->CurrRetryCnt += (u16)((*head) & (0x000000ff));
6292 priv->NumTxOkTotal++;
6293 // printk("NumTxOkTotal is %d\n",priv->NumTxOkTotal++);
6296 // printk("in function %s:curr_retry_count is %d\n",__func__,((*head) & (0x000000ff)));
6299 priv->NumTxOkBytesTotal += (*(head+3)) & (0x00000fff);
6301 // printk("in function %s:curr_txokbyte_count is %d\n",__func__,(*(head+3)) & (0x00000fff));
6302 *head = *head &~ (1<<31);
6304 if((head - begin)/8 == priv->txringcount-1)
6312 txdv = begin + (priv->txringcount -1)*8;
6316 txed = !(txdv[0] &(1<<31));
6319 if(!(txdv[0] & (1<<15))) error = 1;
6320 //if(!(txdv[0] & (1<<30))) error = 1;
6321 if(error)DMESG("%x",txdv[0]);
6324 //DMESG("%x",txdv[0]);
6325 /* the head has been moved to the last certainly TXed
6326 * (or at least processed by the nic) packet.
6327 * The driver take forcefully owning of all these packets
6328 * If the packet previous of the nic pointer has been
6329 * processed this doesn't matter: it will be checked
6330 * here at the next round. Anyway if no more packet are
6331 * TXed no memory leak occour at all.
6335 case MANAGE_PRIORITY:
6336 priv->txmapringhead = head;
6337 //printk("1==========================================> priority check!\n");
6338 if(priv->ack_tx_to_ieee){
6339 // try to implement power-save mode 2008.1.22
6340 // printk("2==========================================> priority check!\n");
6342 if(rtl8180_is_tx_queue_empty(dev)){
6343 // printk("tx queue empty, after send null sleep packet, try to sleep !\n");
6344 priv->ack_tx_to_ieee = 0;
6345 ieee80211_ps_tx_ack(priv->ieee80211,!error);
6352 priv->txbkpringhead = head;
6356 priv->txbepringhead = head;
6360 priv->txvipringhead = head;
6364 priv->txvopringhead = head;
6368 priv->txhpringhead = head;
6372 /*DMESG("%x %x %x", (priv->txnpringhead - priv->txnpring) /8 ,
6373 (priv->txnpringtail - priv->txnpring) /8,
6377 spin_unlock_irqrestore(&priv->tx_lock,flag);
6381 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
6382 void rtl8180_tx_irq_wq(struct work_struct *work)
6384 //struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
6385 struct delayed_work *dwork = to_delayed_work(work);
6386 struct ieee80211_device * ieee = (struct ieee80211_device*)
6387 container_of(dwork, struct ieee80211_device, watch_dog_wq);
6388 struct net_device *dev = ieee->dev;
6390 void rtl8180_tx_irq_wq(struct net_device *dev)
6392 //struct r8180_priv *priv = ieee80211_priv(dev);
6394 rtl8180_tx_isr(dev,MANAGE_PRIORITY,0);
6396 irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs)
6398 struct net_device *dev = (struct net_device *) netdev;
6399 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
6400 unsigned long flags;
6403 /* We should return IRQ_NONE, but for now let me keep this */
6404 if(priv->irq_enabled == 0) return IRQ_HANDLED;
6406 spin_lock_irqsave(&priv->irq_th_lock,flags);
6408 #ifdef CONFIG_RTL8185B
6410 inta = read_nic_dword(dev, ISR);// & priv->IntrMask;
6411 write_nic_dword(dev,ISR,inta); // reset int situation
6413 inta = read_nic_word(dev,INTA) & priv->irq_mask;
6414 write_nic_word(dev,INTA,inta); // reset int situation
6417 priv->stats.shints++;
6419 //DMESG("Enter interrupt, ISR value = 0x%08x", inta);
6422 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6425 most probably we can safely return IRQ_NONE,
6426 but for now is better to avoid problems
6432 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6438 DMESG("NIC irq %x",inta);
6440 //priv->irqpending = inta;
6443 if(!netif_running(dev)) {
6444 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6448 if(inta & ISR_TimeOut){
6449 write_nic_dword(dev, TimerInt, 0);
6450 //DMESG("=================>waking up");
6451 // rtl8180_hw_wakeup(dev);
6454 if(inta & ISR_TBDOK){
6455 priv->stats.txbeacon++;
6458 if(inta & ISR_TBDER){
6459 priv->stats.txbeaconerr++;
6462 if(inta & IMR_TMGDOK ) {
6463 // priv->NumTxOkTotal++;
6464 rtl8180_tx_isr(dev,MANAGE_PRIORITY,0);
6465 // schedule_work(&priv->tx_irq_wq);
6469 if(inta & ISR_THPDER){
6471 DMESG ("TX high priority ERR");
6473 priv->stats.txhperr++;
6474 rtl8180_tx_isr(dev,HI_PRIORITY,1);
6475 priv->ieee80211->stats.tx_errors++;
6478 if(inta & ISR_THPDOK){ //High priority tx ok
6480 DMESG ("TX high priority OK");
6482 // priv->NumTxOkTotal++;
6483 //priv->NumTxOkInPeriod++; //YJ,del,080828
6484 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6485 priv->stats.txhpokint++;
6486 rtl8180_tx_isr(dev,HI_PRIORITY,0);
6489 if(inta & ISR_RER) {
6490 priv->stats.rxerr++;
6492 DMESGW("RX error int");
6495 #ifdef CONFIG_RTL8185B
6496 if(inta & ISR_TBKDER){ //corresponding to BK_PRIORITY
6497 priv->stats.txbkperr++;
6498 priv->ieee80211->stats.tx_errors++;
6500 DMESGW("TX bkp error int");
6502 //tasklet_schedule(&priv->irq_tx_tasklet);
6503 rtl8180_tx_isr(dev,BK_PRIORITY,1);
6504 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6507 if(inta & ISR_TBEDER){ //corresponding to BE_PRIORITY
6508 priv->stats.txbeperr++;
6509 priv->ieee80211->stats.tx_errors++;
6511 DMESGW("TX bep error int");
6513 rtl8180_tx_isr(dev,BE_PRIORITY,1);
6514 //tasklet_schedule(&priv->irq_tx_tasklet);
6515 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6518 if(inta & ISR_TNPDER){ //corresponding to VO_PRIORITY
6519 priv->stats.txnperr++;
6520 priv->ieee80211->stats.tx_errors++;
6522 DMESGW("TX np error int");
6524 //tasklet_schedule(&priv->irq_tx_tasklet);
6525 rtl8180_tx_isr(dev,NORM_PRIORITY,1);
6526 #ifdef CONFIG_RTL8185B
6527 rtl8180_try_wake_queue(dev, NORM_PRIORITY);
6531 if(inta & ISR_TLPDER){ //corresponding to VI_PRIORITY
6532 priv->stats.txlperr++;
6533 priv->ieee80211->stats.tx_errors++;
6535 DMESGW("TX lp error int");
6537 rtl8180_tx_isr(dev,LOW_PRIORITY,1);
6538 //tasklet_schedule(&priv->irq_tx_tasklet);
6539 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
6544 DMESG("Frame arrived !");
6546 //priv->NumRxOkInPeriod++; //YJ,del,080828
6547 priv->stats.rxint++;
6548 tasklet_schedule(&priv->irq_rx_tasklet);
6551 if(inta & ISR_RQoSOK ){
6553 DMESG("QoS Frame arrived !");
6555 //priv->NumRxOkInPeriod++; //YJ,del,080828
6556 priv->stats.rxint++;
6557 tasklet_schedule(&priv->irq_rx_tasklet);
6559 if(inta & ISR_BcnInt) {
6560 //DMESG("Preparing Beacons");
6561 rtl8180_prepare_beacon(dev);
6566 DMESGW("No RX descriptor available");
6567 priv->stats.rxrdu++;
6569 tasklet_schedule(&priv->irq_rx_tasklet);
6570 /*queue_work(priv->workqueue ,&priv->restart_work);*/
6573 if(inta & ISR_RXFOVW){
6575 DMESGW("RX fifo overflow");
6577 priv->stats.rxoverflow++;
6578 tasklet_schedule(&priv->irq_rx_tasklet);
6579 //queue_work(priv->workqueue ,&priv->restart_work);
6582 if(inta & ISR_TXFOVW) priv->stats.txoverflow++;
6584 if(inta & ISR_TNPDOK){ //Normal priority tx ok
6586 DMESG ("TX normal priority OK");
6588 // priv->NumTxOkTotal++;
6589 //priv->NumTxOkInPeriod++; //YJ,del,080828
6590 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6591 // priv->ieee80211->stats.tx_packets++;
6592 priv->stats.txnpokint++;
6593 rtl8180_tx_isr(dev,NORM_PRIORITY,0);
6596 if(inta & ISR_TLPDOK){ //Low priority tx ok
6598 DMESG ("TX low priority OK");
6600 // priv->NumTxOkTotal++;
6601 //priv->NumTxOkInPeriod++; //YJ,del,080828
6602 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6603 // priv->ieee80211->stats.tx_packets++;
6604 priv->stats.txlpokint++;
6605 rtl8180_tx_isr(dev,LOW_PRIORITY,0);
6606 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
6609 #ifdef CONFIG_RTL8185B
6610 if(inta & ISR_TBKDOK){ //corresponding to BK_PRIORITY
6611 priv->stats.txbkpokint++;
6613 DMESGW("TX bk priority ok");
6615 // priv->NumTxOkTotal++;
6616 //priv->NumTxOkInPeriod++; //YJ,del,080828
6617 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6618 rtl8180_tx_isr(dev,BK_PRIORITY,0);
6619 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6622 if(inta & ISR_TBEDOK){ //corresponding to BE_PRIORITY
6623 priv->stats.txbeperr++;
6625 DMESGW("TX be priority ok");
6627 // priv->NumTxOkTotal++;
6628 //priv->NumTxOkInPeriod++; //YJ,del,080828
6629 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6630 rtl8180_tx_isr(dev,BE_PRIORITY,0);
6631 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6634 force_pci_posting(dev);
6635 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6641 void rtl8180_irq_rx_tasklet(struct r8180_priv* priv)
6643 // unsigned long flags;
6645 /* spin_lock_irqsave(&priv->irq_lock, flags);
6646 priv->irq_mask &=~IMR_ROK;
6647 priv->irq_mask &=~IMR_RDU;
6649 rtl8180_irq_enable(priv->dev);
6650 spin_unlock_irqrestore(&priv->irq_lock, flags);
6652 rtl8180_rx(priv->dev);
6654 /* spin_lock_irqsave(&priv->irq_lock, flags);
6655 priv->irq_mask |= IMR_ROK;
6656 priv->irq_mask |= IMR_RDU;
6657 rtl8180_irq_enable(priv->dev);
6658 spin_unlock_irqrestore(&priv->irq_lock, flags);
6662 /****************************************************************************
6663 lizhaoming--------------------------- RF power on/power off -----------------
6664 *****************************************************************************/
6666 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
6667 void GPIOChangeRFWorkItemCallBack(struct work_struct *work)
6669 //struct delayed_work *dwork = to_delayed_work(work);
6670 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, GPIOChangeRFWorkItem.work);
6671 struct net_device *dev = ieee->dev;
6672 struct r8180_priv *priv = ieee80211_priv(dev);
6674 void GPIOChangeRFWorkItemCallBack(struct ieee80211_device *ieee)
6676 struct net_device *dev = ieee->dev;
6677 struct r8180_priv *priv = ieee80211_priv(dev);
6683 RT_RF_POWER_STATE eRfPowerStateToSet;
6684 bool bActuallySet=false;
6687 static char *RadioPowerPath = "/etc/acpi/events/RadioPower.sh";
6688 static char *envp[] = {"HOME=/", "TERM=linux", "PATH=/usr/bin:/bin", NULL};
6689 static int readf_count = 0;
6690 //printk("============>%s in \n", __func__);
6693 if(readf_count % 10 == 0)
6694 priv->PowerProfile = read_acadapter_file("/proc/acpi/ac_adapter/AC0/state");
6696 readf_count = (readf_count+1)%0xffff;
6699 if(priv->up == 0)//driver stopped
6701 printk("\nDo nothing...");
6707 // We should turn off LED before polling FF51[4].
6710 btPSR = read_nic_byte(dev, PSR);
6711 write_nic_byte(dev, PSR, (btPSR & ~BIT3));
6713 //It need to delay 4us suggested by Jong, 2008-01-16
6716 //HW radio On/Off according to the value of FF51[4](config0)
6717 btConfig0 = btPSR = read_nic_byte(dev, CONFIG0);
6720 write_nic_byte(dev, PSR, btPSR| BIT3);
6722 eRfPowerStateToSet = (btConfig0 & BIT4) ? eRfOn : eRfOff;
6724 if((priv->ieee80211->bHwRadioOff == true) && (eRfPowerStateToSet == eRfOn))
6726 priv->ieee80211->bHwRadioOff = false;
6727 bActuallySet = true;
6729 else if((priv->ieee80211->bHwRadioOff == false) && (eRfPowerStateToSet == eRfOff))
6731 priv->ieee80211->bHwRadioOff = true;
6732 bActuallySet = true;
6737 MgntActSet_RF_State(dev, eRfPowerStateToSet, RF_CHANGE_BY_HW);
6739 /* To update the UI status for Power status changed */
6740 if(priv->ieee80211->bHwRadioOff == true)
6743 //if(!priv->RfOffReason)
6746 // argv[1] = "RFOFF";
6748 argv[0] = RadioPowerPath;
6751 call_usermodehelper(RadioPowerPath,argv,envp,1);
6758 static u8 read_acadapter_file(char *filename)
6760 //#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21))
6767 mm_segment_t old_fs = get_fs();
6770 fd = sys_open(filename, O_RDONLY, 0);
6772 while (sys_read(fd, buf, 1) == 1)
6787 // printk("%s \n", ret);
6790 if(strncmp(ret, "off-line",8) == 0)
6798 /***************************************************************************
6799 ------------------- module init / exit stubs ----------------
6800 ****************************************************************************/
6801 module_init(rtl8180_pci_module_init);
6802 module_exit(rtl8180_pci_module_exit);