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);
202 pci_disable_device(pdev);
205 static struct pci_driver rtl8180_pci_driver = {
206 .name = RTL8180_MODULE_NAME, /* Driver name */
207 .id_table = rtl8180_pci_id_tbl, /* PCI_ID table */
208 .probe = rtl8180_pci_probe, /* probe fn */
209 .remove = __devexit_p(rtl8180_pci_remove),/* remove fn */
210 #ifdef CONFIG_RTL8180_PM
211 .suspend = rtl8180_suspend, /* PM suspend fn */
212 .resume = rtl8180_resume, /* PM resume fn */
214 .suspend = NULL, /* PM suspend fn */
215 .resume = NULL, /* PM resume fn */
217 .shutdown = rtl8180_shutdown,
222 #ifdef CONFIG_RTL8180_IO_MAP
224 u8 read_nic_byte(struct net_device *dev, int x)
226 return 0xff&inb(dev->base_addr +x);
229 u32 read_nic_dword(struct net_device *dev, int x)
231 return inl(dev->base_addr +x);
234 u16 read_nic_word(struct net_device *dev, int x)
236 return inw(dev->base_addr +x);
239 void write_nic_byte(struct net_device *dev, int x,u8 y)
241 outb(y&0xff,dev->base_addr +x);
244 void write_nic_word(struct net_device *dev, int x,u16 y)
246 outw(y,dev->base_addr +x);
249 void write_nic_dword(struct net_device *dev, int x,u32 y)
251 outl(y,dev->base_addr +x);
254 #else /* RTL_IO_MAP */
256 u8 read_nic_byte(struct net_device *dev, int x)
258 return 0xff&readb((u8*)dev->mem_start +x);
261 u32 read_nic_dword(struct net_device *dev, int x)
263 return readl((u8*)dev->mem_start +x);
266 u16 read_nic_word(struct net_device *dev, int x)
268 return readw((u8*)dev->mem_start +x);
271 void write_nic_byte(struct net_device *dev, int x,u8 y)
273 writeb(y,(u8*)dev->mem_start +x);
277 void write_nic_dword(struct net_device *dev, int x,u32 y)
279 writel(y,(u8*)dev->mem_start +x);
283 void write_nic_word(struct net_device *dev, int x,u16 y)
285 writew(y,(u8*)dev->mem_start +x);
289 #endif /* RTL_IO_MAP */
295 inline void force_pci_posting(struct net_device *dev)
297 read_nic_byte(dev,EPROM_CMD);
298 #ifndef CONFIG_RTL8180_IO_MAP
304 irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs);
305 void set_nic_rxring(struct net_device *dev);
306 void set_nic_txring(struct net_device *dev);
307 static struct net_device_stats *rtl8180_stats(struct net_device *dev);
308 void rtl8180_commit(struct net_device *dev);
309 void rtl8180_start_tx_beacon(struct net_device *dev);
311 /****************************************************************************
312 -----------------------------PROCFS STUFF-------------------------
313 *****************************************************************************/
315 static struct proc_dir_entry *rtl8180_proc = NULL;
317 static int proc_get_registers(char *page, char **start,
318 off_t offset, int count,
319 int *eof, void *data)
321 struct net_device *dev = data;
322 // struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
329 /* This dump the current register page */
332 //printk( "\nD: %2x> ", n);
333 len += snprintf(page + len, count - len,
336 for(i=0;i<16 && n<=max;i++,n++)
337 len += snprintf(page + len, count - len,
338 "%2x ",read_nic_byte(dev,n));
340 // printk("%2x ",read_nic_byte(dev,n));
342 len += snprintf(page + len, count - len,"\n");
351 int get_curr_tx_free_desc(struct net_device *dev, int priority);
353 static int proc_get_stats_hw(char *page, char **start,
354 off_t offset, int count,
355 int *eof, void *data)
357 //struct net_device *dev = data;
358 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
361 #ifdef CONFIG_RTL8185B
364 len += snprintf(page + len, count - len,
367 "--------------------\n"
370 "--------------------\n"
371 "LP phys dma addr %x\n"
373 "LP virt 32base %x\n"
374 "LP virt 32tail %x\n"
375 "--------------------\n"
376 "NP phys dma addr %x\n"
378 "NP virt 32base %x\n"
379 "NP virt 32tail %x\n"
380 "--------------------\n"
381 "BP phys dma addr %x\n"
383 "BP virt 32base %x\n"
384 "BP virt 32tail %x\n",
387 get_curr_tx_free_desc(dev,LOW_PRIORITY),
388 get_curr_tx_free_desc(dev,NORM_PRIORITY),
389 (u32)priv->txvipringdma,
390 read_nic_dword(dev,TLPDA),
391 (u32)priv->txvipring,
392 (u32)priv->txvipringtail,
393 (u32)priv->txvopringdma,
394 read_nic_dword(dev,TNPDA),
395 (u32)priv->txvopring,
396 (u32)priv->txvopringtail,
397 (u32)priv->txbeaconringdma,
398 read_nic_dword(dev,TBDA),
399 (u32)priv->txbeaconring,
400 (u32)priv->txbeaconringtail);
407 static int proc_get_stats_rx(char *page, char **start,
408 off_t offset, int count,
409 int *eof, void *data)
411 struct net_device *dev = data;
412 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
416 len += snprintf(page + len, count - len,
417 /* "RX descriptor not available: %lu\n"
418 "RX incomplete (missing last descriptor): %lu\n"
420 //"RX descriptor pointer reset: %lu\n"
421 "RX descriptor pointer lost: %lu\n"
422 //"RX pointer workaround: %lu\n"
423 "RX error int: %lu\n"
424 "RX fifo overflow: %lu\n"
428 "RX DMA fail: %lu\n",
430 priv->stats.rxnolast,
431 priv->stats.rxnodata,
432 //priv->stats.rxreset,
433 priv->stats.rxnopointer,
434 //priv->stats.rxwrkaround,
436 priv->stats.rxoverflow,
438 priv->ieee80211->stats.rx_packets,
439 priv->ieee80211->stats.rx_bytes,
440 priv->stats.rxdmafail */
443 "RX CRC Error(0-500): %lu\n"
444 "RX CRC Error(500-1000): %lu\n"
445 "RX CRC Error(>1000): %lu\n"
446 "RX ICV Error: %lu\n",
449 priv->stats.rxcrcerrmin,
450 priv->stats.rxcrcerrmid,
451 priv->stats.rxcrcerrmax,
460 static int proc_get_stats_ieee(char *page, char **start,
461 off_t offset, int count,
462 int *eof, void *data)
464 struct net_device *dev = data;
465 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
469 len += snprintf(page + len, count - len,
470 "TXed association requests: %u\n"
471 "TXed authentication requests: %u\n"
472 "RXed successful association response: %u\n"
473 "RXed failed association response: %u\n"
474 "RXed successful authentication response: %u\n"
475 "RXed failed authentication response: %u\n"
476 "Association requests without response: %u\n"
477 "Authentication requests without response: %u\n"
478 "TX probe response: %u\n"
479 "RX probe request: %u\n"
480 "TX probe request: %lu\n"
481 "RX authentication requests: %lu\n"
482 "RX association requests: %lu\n"
483 "Reassociations: %lu\n",
484 priv->ieee80211->ieee_stats.tx_ass,
485 priv->ieee80211->ieee_stats.tx_aut,
486 priv->ieee80211->ieee_stats.rx_ass_ok,
487 priv->ieee80211->ieee_stats.rx_ass_err,
488 priv->ieee80211->ieee_stats.rx_aut_ok,
489 priv->ieee80211->ieee_stats.rx_aut_err,
490 priv->ieee80211->ieee_stats.ass_noresp,
491 priv->ieee80211->ieee_stats.aut_noresp,
492 priv->ieee80211->ieee_stats.tx_probe,
493 priv->ieee80211->ieee_stats.rx_probe,
494 priv->ieee80211->ieee_stats.tx_probe_rq,
495 priv->ieee80211->ieee_stats.rx_auth_rq,
496 priv->ieee80211->ieee_stats.rx_assoc_rq,
497 priv->ieee80211->ieee_stats.reassoc);
504 static int proc_get_stats_ap(char *page, char **start,
505 off_t offset, int count,
506 int *eof, void *data)
508 struct net_device *dev = data;
509 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
510 struct mac_htable_t *list;
514 if(priv->ieee80211->iw_mode != IW_MODE_MASTER){
515 len += snprintf(page + len, count - len,
516 "Card is not acting as AP...\n"
519 len += snprintf(page + len, count - len,
520 "List of associated STA:\n"
523 for(i=0;i<MAC_HTABLE_ENTRY;i++)
524 for (list = priv->ieee80211->assoc_htable[i]; list!=NULL; list = list->next){
525 len += snprintf(page + len, count - len,
526 MACSTR"\n",MAC2STR(list->adr));
535 static int proc_get_stats_tx(char *page, char **start,
536 off_t offset, int count,
537 int *eof, void *data)
539 struct net_device *dev = data;
540 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
543 unsigned long totalOK;
545 totalOK=priv->stats.txnpokint+priv->stats.txhpokint+priv->stats.txlpokint;
546 len += snprintf(page + len, count - len,
547 /* "TX normal priority ok int: %lu\n"
548 "TX normal priority error int: %lu\n"
549 "TX high priority ok int: %lu\n"
550 "TX high priority failed error int: %lu\n"
551 "TX low priority ok int: %lu\n"
552 "TX low priority failed error int: %lu\n"
555 "TX queue resume: %lu\n"
556 "TX queue stopped?: %d\n"
557 "TX fifo overflow: %lu\n"
558 //"SW TX stop: %lu\n"
559 //"SW TX wake: %lu\n"
561 "TX beacon aborted: %lu\n",
562 priv->stats.txnpokint,
564 priv->stats.txhpokint,
566 priv->stats.txlpokint,
568 priv->ieee80211->stats.tx_bytes,
569 priv->ieee80211->stats.tx_packets,
570 priv->stats.txresumed,
571 netif_queue_stopped(dev),
572 priv->stats.txoverflow,
573 //priv->ieee80211->ieee_stats.swtxstop,
574 //priv->ieee80211->ieee_stats.swtxawake,
575 priv->stats.txbeacon,
576 priv->stats.txbeaconerr */
580 "TX beacon OK: %lu\n"
581 "TX beacon error: %lu\n",
583 priv->stats.txnperr+priv->stats.txhperr+priv->stats.txlperr,
585 priv->stats.txbeacon,
586 priv->stats.txbeaconerr
594 #if WIRELESS_EXT < 17
595 static struct iw_statistics *r8180_get_wireless_stats(struct net_device *dev)
597 struct r8180_priv *priv = ieee80211_priv(dev);
599 return &priv->wstats;
602 void rtl8180_proc_module_init(void)
604 DMESG("Initializing proc filesystem");
605 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
606 rtl8180_proc=create_proc_entry(RTL8180_MODULE_NAME, S_IFDIR, proc_net);
608 rtl8180_proc=create_proc_entry(RTL8180_MODULE_NAME, S_IFDIR, init_net.proc_net);
613 void rtl8180_proc_module_remove(void)
615 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
616 remove_proc_entry(RTL8180_MODULE_NAME, proc_net);
618 remove_proc_entry(RTL8180_MODULE_NAME, init_net.proc_net);
623 void rtl8180_proc_remove_one(struct net_device *dev)
625 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
627 remove_proc_entry("stats-hw", priv->dir_dev);
628 remove_proc_entry("stats-tx", priv->dir_dev);
629 remove_proc_entry("stats-rx", priv->dir_dev);
630 // remove_proc_entry("stats-ieee", priv->dir_dev);
631 // remove_proc_entry("stats-ap", priv->dir_dev);
632 remove_proc_entry("registers", priv->dir_dev);
633 remove_proc_entry(dev->name, rtl8180_proc);
634 priv->dir_dev = NULL;
639 void rtl8180_proc_init_one(struct net_device *dev)
641 struct proc_dir_entry *e;
642 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
643 priv->dir_dev = create_proc_entry(dev->name,
644 S_IFDIR | S_IRUGO | S_IXUGO,
646 if (!priv->dir_dev) {
647 DMESGE("Unable to initialize /proc/net/rtl8180/%s\n",
652 e = create_proc_read_entry("stats-hw", S_IFREG | S_IRUGO,
653 priv->dir_dev, proc_get_stats_hw, dev);
656 DMESGE("Unable to initialize "
657 "/proc/net/rtl8180/%s/stats-hw\n",
661 e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
662 priv->dir_dev, proc_get_stats_rx, dev);
665 DMESGE("Unable to initialize "
666 "/proc/net/rtl8180/%s/stats-rx\n",
671 e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
672 priv->dir_dev, proc_get_stats_tx, dev);
675 DMESGE("Unable to initialize "
676 "/proc/net/rtl8180/%s/stats-tx\n",
680 e = create_proc_read_entry("stats-ieee", S_IFREG | S_IRUGO,
681 priv->dir_dev, proc_get_stats_ieee, dev);
684 DMESGE("Unable to initialize "
685 "/proc/net/rtl8180/%s/stats-ieee\n",
690 e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO,
691 priv->dir_dev, proc_get_stats_ap, dev);
694 DMESGE("Unable to initialize "
695 "/proc/net/rtl8180/%s/stats-ap\n",
700 e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
701 priv->dir_dev, proc_get_registers, dev);
704 DMESGE("Unable to initialize "
705 "/proc/net/rtl8180/%s/registers\n",
709 /****************************************************************************
710 -----------------------------MISC STUFF-------------------------
711 *****************************************************************************/
713 FIXME: check if we can use some standard already-existent
714 data type+functions in kernel
717 short buffer_add(struct buffer **buffer, u32 *buf, dma_addr_t dma,
718 struct buffer **bufferhead)
721 DMESG("adding buffer to TX/RX struct");
728 *buffer = kmalloc(sizeof(struct buffer),GFP_KERNEL);
730 if (*buffer == NULL) {
731 DMESGE("Failed to kmalloc head of TX/RX struct");
734 (*buffer)->next=*buffer;
737 if(bufferhead !=NULL)
738 (*bufferhead) = (*buffer);
743 while(tmp->next!=(*buffer)) tmp=tmp->next;
744 if ((tmp->next= kmalloc(sizeof(struct buffer),GFP_KERNEL)) == NULL){
745 DMESGE("Failed to kmalloc TX/RX struct");
750 tmp->next->next=*buffer;
756 void buffer_free(struct net_device *dev,struct buffer **buffer,int len,short
760 struct buffer *tmp,*next;
761 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
762 struct pci_dev *pdev=priv->pdev;
765 if(! *buffer) return;
767 /*for(tmp=*buffer; tmp->next != *buffer; tmp=tmp->next)
774 pci_free_consistent(pdev,len,
777 pci_unmap_single(pdev, tmp->dma,
778 len,PCI_DMA_FROMDEVICE);
784 while(next != *buffer);
790 void print_buffer(u32 *buffer, int len)
793 u8 *buf =(u8*)buffer;
795 printk("ASCII BUFFER DUMP (len: %x):\n",len);
800 printk("\nBINARY BUFFER DUMP (len: %x):\n",len);
803 printk("%02x",buf[i]);
809 int get_curr_tx_free_desc(struct net_device *dev, int priority)
811 struct r8180_priv *priv = ieee80211_priv(dev);
817 case MANAGE_PRIORITY:
818 head = priv->txmapringhead;
819 tail = priv->txmapringtail;
822 head = priv->txbkpringhead;
823 tail = priv->txbkpringtail;
826 head = priv->txbepringhead;
827 tail = priv->txbepringtail;
830 head = priv->txvipringhead;
831 tail = priv->txvipringtail;
834 head = priv->txvopringhead;
835 tail = priv->txvopringtail;
838 head = priv->txhpringhead;
839 tail = priv->txhpringtail;
845 //DMESG("%x %x", head, tail);
847 /* FIXME FIXME FIXME FIXME */
850 if( head <= tail ) return priv->txringcount-1 - (tail - head)/8;
851 return (head - tail)/8/4;
854 ret = priv->txringcount - (tail - head)/8;
856 ret = (head - tail)/8;
858 if(ret > priv->txringcount ) DMESG("BUG");
864 short check_nic_enought_desc(struct net_device *dev, int priority)
866 struct r8180_priv *priv = ieee80211_priv(dev);
867 struct ieee80211_device *ieee = netdev_priv(dev);
869 int requiredbyte, required;
870 requiredbyte = priv->ieee80211->fts + sizeof(struct ieee80211_header_data);
872 if(ieee->current_network.QoS_Enable) {
876 required = requiredbyte / (priv->txbuffsize-4);
877 if (requiredbyte % priv->txbuffsize) required++;
878 /* for now we keep two free descriptor as a safety boundary
879 * between the tail and the head
882 return (required+2 < get_curr_tx_free_desc(dev,priority));
886 /* This function is only for debuging purpose */
887 void check_tx_ring(struct net_device *dev, int pri)
889 static int maxlog =3;
890 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
899 struct buffer* buffer;
902 if (maxlog <0 ) return;
905 case MANAGE_PRIORITY:
906 tail = priv->txmapringtail;
907 begin = priv->txmapring;
908 head = priv->txmapringhead;
909 nic = read_nic_dword(dev,TX_MANAGEPRIORITY_RING_ADDR);
910 buffer = priv->txmapbufs;
911 nicbegin = priv->txmapringdma;
916 tail = priv->txbkpringtail;
917 begin = priv->txbkpring;
918 head = priv->txbkpringhead;
919 nic = read_nic_dword(dev,TX_BKPRIORITY_RING_ADDR);
920 buffer = priv->txbkpbufs;
921 nicbegin = priv->txbkpringdma;
925 tail = priv->txbepringtail;
926 begin = priv->txbepring;
927 head = priv->txbepringhead;
928 nic = read_nic_dword(dev,TX_BEPRIORITY_RING_ADDR);
929 buffer = priv->txbepbufs;
930 nicbegin = priv->txbepringdma;
934 tail = priv->txvipringtail;
935 begin = priv->txvipring;
936 head = priv->txvipringhead;
937 nic = read_nic_dword(dev,TX_VIPRIORITY_RING_ADDR);
938 buffer = priv->txvipbufs;
939 nicbegin = priv->txvipringdma;
944 tail = priv->txvopringtail;
945 begin = priv->txvopring;
946 head = priv->txvopringhead;
947 nic = read_nic_dword(dev,TX_VOPRIORITY_RING_ADDR);
948 buffer = priv->txvopbufs;
949 nicbegin = priv->txvopringdma;
953 tail = priv->txhpringtail;
954 begin = priv->txhpring;
955 head = priv->txhpringhead;
956 nic = read_nic_dword(dev,TX_HIGHPRIORITY_RING_ADDR);
957 buffer = priv->txhpbufs;
958 nicbegin = priv->txhpringdma;
967 DMESGE ("NIC TX ack, but TX queue corrupted!");
970 for(i=0,buf=buffer, tmp=begin;
971 tmp<begin+(priv->txringcount)*8;
972 tmp+=8,buf=buf->next,i++)
974 DMESG("BUF%d %s %x %s. Next : %x",i,
975 *tmp & (1<<31) ? "filled" : "empty",
977 *tmp & (1<<15)? "ok": "err", *(tmp+4));
981 (nic-nicbegin) / 8 /4);
982 DMESG("tail at %d", ((int)tail - (int)begin) /8 /4);
983 DMESG("head at %d", ((int)head - (int)begin) /8 /4);
984 DMESG("check free desc returns %d", check_nic_enought_desc(dev,pri));
985 DMESG("free desc is %d\n", get_curr_tx_free_desc(dev,pri));
986 //rtl8180_reset(dev);
992 /* this function is only for debugging purpose */
993 void check_rxbuf(struct net_device *dev)
995 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1000 #ifdef CONFIG_RTL8185B
1007 DMESGE ("NIC RX ack, but RX queue corrupted!");
1011 for(buf=priv->rxbuffer, tmp=priv->rxring;
1012 tmp < priv->rxring+(priv->rxringcount)*rx_desc_size;
1013 tmp+=rx_desc_size, buf=buf->next)
1016 *tmp & (1<<31) ? "empty" : "filled",
1024 void dump_eprom(struct net_device *dev)
1028 DMESG("EEPROM addr %x : %x", i, eprom_read(dev,i));
1032 void rtl8180_dump_reg(struct net_device *dev)
1038 DMESG("Dumping NIC register map");
1042 printk( "\nD: %2x> ", n);
1043 for(i=0;i<16 && n<=max;i++,n++)
1044 printk("%2x ",read_nic_byte(dev,n));
1050 void fix_tx_fifo(struct net_device *dev)
1052 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1055 #ifdef DEBUG_TX_ALLOC
1056 DMESG("FIXING TX FIFOs");
1058 for (tmp=priv->txmapring, i=0;
1059 i < priv->txringcount;
1061 *tmp = *tmp &~ (1<<31);
1064 for (tmp=priv->txbkpring, i=0;
1065 i < priv->txringcount;
1067 *tmp = *tmp &~ (1<<31);
1070 for (tmp=priv->txbepring, i=0;
1071 i < priv->txringcount;
1073 *tmp = *tmp &~ (1<<31);
1075 for (tmp=priv->txvipring, i=0;
1076 i < priv->txringcount;
1078 *tmp = *tmp &~ (1<<31);
1081 for (tmp=priv->txvopring, i=0;
1082 i < priv->txringcount;
1084 *tmp = *tmp &~ (1<<31);
1087 for (tmp=priv->txhpring, i=0;
1088 i < priv->txringcount;
1090 *tmp = *tmp &~ (1<<31);
1093 for (tmp=priv->txbeaconring, i=0;
1094 i < priv->txbeaconcount;
1096 *tmp = *tmp &~ (1<<31);
1098 #ifdef DEBUG_TX_ALLOC
1099 DMESG("TX FIFOs FIXED");
1101 priv->txmapringtail = priv->txmapring;
1102 priv->txmapringhead = priv->txmapring;
1103 priv->txmapbufstail = priv->txmapbufs;
1105 priv->txbkpringtail = priv->txbkpring;
1106 priv->txbkpringhead = priv->txbkpring;
1107 priv->txbkpbufstail = priv->txbkpbufs;
1109 priv->txbepringtail = priv->txbepring;
1110 priv->txbepringhead = priv->txbepring;
1111 priv->txbepbufstail = priv->txbepbufs;
1113 priv->txvipringtail = priv->txvipring;
1114 priv->txvipringhead = priv->txvipring;
1115 priv->txvipbufstail = priv->txvipbufs;
1117 priv->txvopringtail = priv->txvopring;
1118 priv->txvopringhead = priv->txvopring;
1119 priv->txvopbufstail = priv->txvopbufs;
1121 priv->txhpringtail = priv->txhpring;
1122 priv->txhpringhead = priv->txhpring;
1123 priv->txhpbufstail = priv->txhpbufs;
1125 priv->txbeaconringtail = priv->txbeaconring;
1126 priv->txbeaconbufstail = priv->txbeaconbufs;
1127 set_nic_txring(dev);
1129 ieee80211_reset_queue(priv->ieee80211);
1130 priv->ack_tx_to_ieee = 0;
1134 void fix_rx_fifo(struct net_device *dev)
1136 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1138 struct buffer *rxbuf;
1141 #ifdef CONFIG_RTL8185B
1142 rx_desc_size = 8; // 4*8 = 32 bytes
1147 #ifdef DEBUG_RXALLOC
1148 DMESG("FIXING RX FIFO");
1152 for (tmp=priv->rxring, rxbuf=priv->rxbufferhead;
1153 (tmp < (priv->rxring)+(priv->rxringcount)*rx_desc_size);
1154 tmp+=rx_desc_size,rxbuf=rxbuf->next){
1155 *(tmp+2) = rxbuf->dma;
1157 *tmp=*tmp | priv->rxbuffersize;
1161 #ifdef DEBUG_RXALLOC
1162 DMESG("RX FIFO FIXED");
1166 priv->rxringtail=priv->rxring;
1167 priv->rxbuffer=priv->rxbufferhead;
1168 priv->rx_skb_complete=1;
1169 set_nic_rxring(dev);
1173 /****************************************************************************
1174 ------------------------------HW STUFF---------------------------
1175 *****************************************************************************/
1177 unsigned char QUALITY_MAP[] = {
1178 0x64, 0x64, 0x64, 0x63, 0x63, 0x62, 0x62, 0x61,
1179 0x61, 0x60, 0x60, 0x5f, 0x5f, 0x5e, 0x5d, 0x5c,
1180 0x5b, 0x5a, 0x59, 0x57, 0x56, 0x54, 0x52, 0x4f,
1181 0x4c, 0x49, 0x45, 0x41, 0x3c, 0x37, 0x31, 0x29,
1182 0x24, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
1183 0x22, 0x22, 0x21, 0x21, 0x21, 0x21, 0x21, 0x20,
1184 0x20, 0x20, 0x20, 0x1f, 0x1f, 0x1e, 0x1e, 0x1e,
1185 0x1d, 0x1d, 0x1c, 0x1c, 0x1b, 0x1a, 0x19, 0x19,
1186 0x18, 0x17, 0x16, 0x15, 0x14, 0x12, 0x11, 0x0f,
1187 0x0e, 0x0c, 0x0a, 0x08, 0x06, 0x04, 0x01, 0x00
1190 unsigned char STRENGTH_MAP[] = {
1191 0x64, 0x64, 0x63, 0x62, 0x61, 0x60, 0x5f, 0x5e,
1192 0x5d, 0x5c, 0x5b, 0x5a, 0x57, 0x54, 0x52, 0x50,
1193 0x4e, 0x4c, 0x4a, 0x48, 0x46, 0x44, 0x41, 0x3f,
1194 0x3c, 0x3a, 0x37, 0x36, 0x36, 0x1c, 0x1c, 0x1b,
1195 0x1b, 0x1a, 0x1a, 0x19, 0x19, 0x18, 0x18, 0x17,
1196 0x17, 0x16, 0x16, 0x15, 0x15, 0x14, 0x14, 0x13,
1197 0x13, 0x12, 0x12, 0x11, 0x11, 0x10, 0x10, 0x0f,
1198 0x0f, 0x0e, 0x0e, 0x0d, 0x0d, 0x0c, 0x0c, 0x0b,
1199 0x0b, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x07,
1200 0x07, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x00
1203 void rtl8180_RSSI_calc(struct net_device *dev, u8 *rssi, u8 *qual){
1204 //void Mlme_UpdateRssiSQ(struct net_device *dev, u8 *rssi, u8 *qual){
1205 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1216 _rssi = 0; // avoid gcc complains..
1219 temp = QUALITY_MAP[q];
1231 switch(priv->rf_chip){
1235 if ( !lsb || !(temp2 <= 0x3c) ) {
1238 temp2 = 100 * temp2 / 0x3c;
1240 *rssi = temp2 & 0xff;
1241 _rssi = temp2 & 0xff;
1243 case RFCHIPID_INTERSIL:
1245 temp2 &= 0xfffffffe;
1254 if ( temp2 <= 0x3e0000 ) {
1255 if ( temp2 < 0xffef0000 )
1269 temp3 = temp3 / 0x6d;
1271 _rssi = temp3 & 0xff;
1272 *rssi = temp3 & 0xff;
1277 if ( ! lsb || !(temp2 <= 0x3c) ){
1280 temp2 = (100 * temp2) / 0x3c;
1282 *rssi = temp2 & 0xff;
1283 _rssi = temp2 & 0xff;
1285 case RFCHIPID_PHILIPS:
1286 if( orig_qual <= 0x4e ){
1287 _rssi = STRENGTH_MAP[orig_qual];
1302 case RFCHIPID_MAXIM:
1310 *rssi = temp2 & 0xff;
1311 _rssi = temp2 & 0xff;
1315 if ( _rssi < 0x64 ){
1327 void rtl8180_irq_enable(struct net_device *dev)
1329 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1330 priv->irq_enabled = 1;
1332 write_nic_word(dev,INTA_MASK,INTA_RXOK | INTA_RXDESCERR | INTA_RXOVERFLOW |\
1333 INTA_TXOVERFLOW | INTA_HIPRIORITYDESCERR | INTA_HIPRIORITYDESCOK |\
1334 INTA_NORMPRIORITYDESCERR | INTA_NORMPRIORITYDESCOK |\
1335 INTA_LOWPRIORITYDESCERR | INTA_LOWPRIORITYDESCOK | INTA_TIMEOUT);
1337 write_nic_word(dev,INTA_MASK, priv->irq_mask);
1341 void rtl8180_irq_disable(struct net_device *dev)
1343 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1345 #ifdef CONFIG_RTL8185B
1346 write_nic_dword(dev,IMR,0);
1348 write_nic_word(dev,INTA_MASK,0);
1350 force_pci_posting(dev);
1351 priv->irq_enabled = 0;
1355 void rtl8180_set_mode(struct net_device *dev,int mode)
1358 ecmd=read_nic_byte(dev, EPROM_CMD);
1359 ecmd=ecmd &~ EPROM_CMD_OPERATING_MODE_MASK;
1360 ecmd=ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
1361 ecmd=ecmd &~ (1<<EPROM_CS_SHIFT);
1362 ecmd=ecmd &~ (1<<EPROM_CK_SHIFT);
1363 write_nic_byte(dev, EPROM_CMD, ecmd);
1366 void rtl8180_adapter_start(struct net_device *dev);
1367 void rtl8180_beacon_tx_enable(struct net_device *dev);
1369 void rtl8180_update_msr(struct net_device *dev)
1371 struct r8180_priv *priv = ieee80211_priv(dev);
1375 msr = read_nic_byte(dev, MSR);
1376 msr &= ~ MSR_LINK_MASK;
1378 rxconf=read_nic_dword(dev,RX_CONF);
1380 if(priv->ieee80211->state == IEEE80211_LINKED)
1382 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1383 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
1384 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
1385 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
1386 else if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
1387 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
1389 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
1390 rxconf |= (1<<RX_CHECK_BSSID_SHIFT);
1393 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
1394 rxconf &= ~(1<<RX_CHECK_BSSID_SHIFT);
1397 write_nic_byte(dev, MSR, msr);
1398 write_nic_dword(dev, RX_CONF, rxconf);
1404 void rtl8180_set_chan(struct net_device *dev,short ch)
1406 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1408 if((ch > 14) || (ch < 1))
1410 printk("In %s: Invalid chnanel %d\n", __func__, ch);
1415 //printk("in %s:channel is %d\n",__func__,ch);
1416 priv->rf_set_chan(dev,priv->chan);
1421 void rtl8180_rx_enable(struct net_device *dev)
1425 /* for now we accept data, management & ctl frame*/
1426 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1428 rxconf=read_nic_dword(dev,RX_CONF);
1429 rxconf = rxconf &~ MAC_FILTER_MASK;
1430 rxconf = rxconf | (1<<ACCEPT_MNG_FRAME_SHIFT);
1431 rxconf = rxconf | (1<<ACCEPT_DATA_FRAME_SHIFT);
1432 rxconf = rxconf | (1<<ACCEPT_BCAST_FRAME_SHIFT);
1433 rxconf = rxconf | (1<<ACCEPT_MCAST_FRAME_SHIFT);
1434 // rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
1435 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
1437 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
1438 dev->flags & IFF_PROMISC){
1439 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
1441 rxconf = rxconf | (1<<ACCEPT_NICMAC_FRAME_SHIFT);
1442 if(priv->card_8185 == 0)
1443 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
1446 /*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
1447 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
1448 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
1451 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
1452 rxconf = rxconf | (1<<ACCEPT_CTL_FRAME_SHIFT);
1453 rxconf = rxconf | (1<<ACCEPT_ICVERR_FRAME_SHIFT);
1454 rxconf = rxconf | (1<<ACCEPT_PWR_FRAME_SHIFT);
1457 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
1458 rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
1460 //if(!priv->card_8185){
1461 rxconf = rxconf &~ RX_FIFO_THRESHOLD_MASK;
1462 rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
1465 rxconf = rxconf | (1<<RX_AUTORESETPHY_SHIFT);
1466 rxconf = rxconf &~ MAX_RX_DMA_MASK;
1467 rxconf = rxconf | (MAX_RX_DMA_2048<<MAX_RX_DMA_SHIFT);
1469 //if(!priv->card_8185)
1470 rxconf = rxconf | RCR_ONLYERLPKT;
1472 rxconf = rxconf &~ RCR_CS_MASK;
1473 if(!priv->card_8185)
1474 rxconf |= (priv->rcr_csense<<RCR_CS_SHIFT);
1475 // rxconf &=~ 0xfff00000;
1476 // rxconf |= 0x90100000;//9014f76f;
1477 write_nic_dword(dev, RX_CONF, rxconf);
1482 DMESG("rxconf: %x %x",rxconf ,read_nic_dword(dev,RX_CONF));
1484 cmd=read_nic_byte(dev,CMD);
1485 write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
1487 /* In rtl8139 driver seems that DMA threshold has to be written
1488 * after enabling RX, so we rewrite RX_CONFIG register
1491 // write_nic_dword(dev, RX_CONF, rxconf);
1496 void set_nic_txring(struct net_device *dev)
1498 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1499 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1501 write_nic_dword(dev, TX_MANAGEPRIORITY_RING_ADDR, priv->txmapringdma);
1502 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1503 write_nic_dword(dev, TX_BKPRIORITY_RING_ADDR, priv->txbkpringdma);
1504 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1505 write_nic_dword(dev, TX_BEPRIORITY_RING_ADDR, priv->txbepringdma);
1506 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1507 write_nic_dword(dev, TX_VIPRIORITY_RING_ADDR, priv->txvipringdma);
1508 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1509 write_nic_dword(dev, TX_VOPRIORITY_RING_ADDR, priv->txvopringdma);
1510 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1511 write_nic_dword(dev, TX_HIGHPRIORITY_RING_ADDR, priv->txhpringdma);
1512 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1514 write_nic_dword(dev, TX_BEACON_RING_ADDR, priv->txbeaconringdma);
1518 void rtl8180_conttx_enable(struct net_device *dev)
1521 txconf = read_nic_dword(dev,TX_CONF);
1522 txconf = txconf &~ TX_LOOPBACK_MASK;
1523 txconf = txconf | (TX_LOOPBACK_CONTINUE <<TX_LOOPBACK_SHIFT);
1524 write_nic_dword(dev,TX_CONF,txconf);
1528 void rtl8180_conttx_disable(struct net_device *dev)
1531 txconf = read_nic_dword(dev,TX_CONF);
1532 txconf = txconf &~ TX_LOOPBACK_MASK;
1533 txconf = txconf | (TX_LOOPBACK_NONE <<TX_LOOPBACK_SHIFT);
1534 write_nic_dword(dev,TX_CONF,txconf);
1538 void rtl8180_tx_enable(struct net_device *dev)
1544 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1545 txconf= read_nic_dword(dev,TX_CONF);
1548 if(priv->card_8185){
1551 byte = read_nic_byte(dev,CW_CONF);
1552 byte &= ~(1<<CW_CONF_PERPACKET_CW_SHIFT);
1553 byte &= ~(1<<CW_CONF_PERPACKET_RETRY_SHIFT);
1554 write_nic_byte(dev, CW_CONF, byte);
1556 tx_agc_ctl = read_nic_byte(dev, TX_AGC_CTL);
1557 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_GAIN_SHIFT);
1558 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT);
1559 tx_agc_ctl |=(1<<TX_AGC_CTL_FEEDBACK_ANT);
1560 write_nic_byte(dev, TX_AGC_CTL, tx_agc_ctl);
1562 write_nic_word(dev, 0x5e, 0x01);
1563 force_pci_posting(dev);
1565 write_nic_word(dev, 0xfe, 0x10);
1566 force_pci_posting(dev);
1568 write_nic_word(dev, 0x5e, 0x00);
1569 force_pci_posting(dev);
1572 write_nic_byte(dev, 0xec, 0x3f); /* Disable early TX */
1575 if(priv->card_8185){
1577 txconf = txconf &~ (1<<TCR_PROBE_NOTIMESTAMP_SHIFT);
1582 txconf= txconf &~ (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
1584 txconf= txconf | (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
1587 txconf = txconf &~ TX_LOOPBACK_MASK;
1588 txconf = txconf | (TX_LOOPBACK_NONE <<TX_LOOPBACK_SHIFT);
1589 txconf = txconf &~ TCR_DPRETRY_MASK;
1590 txconf = txconf &~ TCR_RTSRETRY_MASK;
1591 txconf = txconf | (priv->retry_data<<TX_DPRETRY_SHIFT);
1592 txconf = txconf | (priv->retry_rts<<TX_RTSRETRY_SHIFT);
1593 txconf = txconf &~ (1<<TX_NOCRC_SHIFT);
1595 if(priv->card_8185){
1596 if(priv->hw_plcp_len)
1597 txconf = txconf &~ TCR_PLCP_LEN;
1599 txconf = txconf | TCR_PLCP_LEN;
1601 txconf = txconf &~ TCR_SAT;
1603 txconf = txconf &~ TCR_MXDMA_MASK;
1604 txconf = txconf | (TCR_MXDMA_2048<<TCR_MXDMA_SHIFT);
1605 txconf = txconf | TCR_CWMIN;
1606 txconf = txconf | TCR_DISCW;
1608 // if(priv->ieee80211->hw_wep)
1609 // txconf=txconf &~ (1<<TX_NOICV_SHIFT);
1611 txconf=txconf | (1<<TX_NOICV_SHIFT);
1613 write_nic_dword(dev,TX_CONF,txconf);
1619 DMESG("txconf: %x %x",txconf,read_nic_dword(dev,TX_CONF));
1622 cmd=read_nic_byte(dev,CMD);
1623 write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));
1626 write_nic_dword(dev,TX_CONF,txconf);
1629 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1630 write_nic_byte(dev, TX_DMA_POLLING, priv->dma_poll_mask);
1631 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1636 void rtl8180_beacon_tx_enable(struct net_device *dev)
1638 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1640 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1641 #ifdef CONFIG_RTL8185B
1642 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_BQ);
1643 write_nic_byte(dev,TPPollStop, priv->dma_poll_mask);
1645 priv->dma_poll_mask &=~(1<<TX_DMA_STOP_BEACON_SHIFT);
1646 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1648 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1652 void rtl8180_beacon_tx_disable(struct net_device *dev)
1654 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1656 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1657 #ifdef CONFIG_RTL8185B
1658 priv->dma_poll_stop_mask |= TPPOLLSTOP_BQ;
1659 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
1661 priv->dma_poll_mask |= (1<<TX_DMA_STOP_BEACON_SHIFT);
1662 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1664 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1669 void rtl8180_rtx_disable(struct net_device *dev)
1672 struct r8180_priv *priv = ieee80211_priv(dev);
1674 cmd=read_nic_byte(dev,CMD);
1675 write_nic_byte(dev, CMD, cmd &~ \
1676 ((1<<CMD_RX_ENABLE_SHIFT)|(1<<CMD_TX_ENABLE_SHIFT)));
1677 force_pci_posting(dev);
1679 /*while (read_nic_byte(dev,CMD) & (1<<CMD_RX_ENABLE_SHIFT))
1683 if(!priv->rx_skb_complete)
1684 dev_kfree_skb_any(priv->rx_skb);
1688 int alloc_tx_beacon_desc_ring(struct net_device *dev, int count)
1692 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1694 priv->txbeaconring = (u32*)pci_alloc_consistent(priv->pdev,
1695 sizeof(u32)*8*count,
1696 &priv->txbeaconringdma);
1697 if (!priv->txbeaconring) return -1;
1698 for (tmp=priv->txbeaconring,i=0;i<count;i++){
1699 *tmp = *tmp &~ (1<<31); // descriptor empty, owned by the drv
1701 *(tmp+2) = (u32)dma_tmp;
1705 *(tmp+4) = (u32)priv->txbeaconringdma+((i+1)*8*4);
1707 *(tmp+4) = (u32)priv->txbeaconringdma;
1715 short alloc_tx_desc_ring(struct net_device *dev, int bufsize, int count,
1721 dma_addr_t dma_desc, dma_tmp;
1722 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1723 struct pci_dev *pdev = priv->pdev;
1726 if((bufsize & 0xfff) != bufsize) {
1727 DMESGE ("TX buffer allocation too large");
1730 desc = (u32*)pci_alloc_consistent(pdev,
1731 sizeof(u32)*8*count+256, &dma_desc);
1732 if(desc==NULL) return -1;
1733 if(dma_desc & 0xff){
1736 * descriptor's buffer must be 256 byte aligned
1737 * we shouldn't be here, since we set DMA mask !
1739 DMESGW("Fixing TX alignment");
1740 desc = (u32*)((u8*)desc + 256);
1741 #if (defined(CONFIG_HIGHMEM64G) || defined(CONFIG_64BIT_PHYS_ADDR))
1742 desc = (u32*)((u64)desc &~ 0xff);
1743 dma_desc = (dma_addr_t)((u8*)dma_desc + 256);
1744 dma_desc = (dma_addr_t)((u64)dma_desc &~ 0xff);
1746 desc = (u32*)((u32)desc &~ 0xff);
1747 dma_desc = (dma_addr_t)((u8*)dma_desc + 256);
1748 dma_desc = (dma_addr_t)((u32)dma_desc &~ 0xff);
1752 for (i=0;i<count;i++)
1754 buf = (void*)pci_alloc_consistent(pdev,bufsize,&dma_tmp);
1755 if (buf == NULL) return -ENOMEM;
1759 case TX_NORMPRIORITY_RING_ADDR:
1760 if(-1 == buffer_add(&(priv->txnpbufs),buf,dma_tmp,NULL)){
1761 DMESGE("Unable to allocate mem for buffer NP");
1766 case TX_LOWPRIORITY_RING_ADDR:
1767 if(-1 == buffer_add(&(priv->txlpbufs),buf,dma_tmp,NULL)){
1768 DMESGE("Unable to allocate mem for buffer LP");
1773 case TX_HIGHPRIORITY_RING_ADDR:
1774 if(-1 == buffer_add(&(priv->txhpbufs),buf,dma_tmp,NULL)){
1775 DMESGE("Unable to allocate mem for buffer HP");
1780 case TX_MANAGEPRIORITY_RING_ADDR:
1781 if(-1 == buffer_add(&(priv->txmapbufs),buf,dma_tmp,NULL)){
1782 DMESGE("Unable to allocate mem for buffer NP");
1787 case TX_BKPRIORITY_RING_ADDR:
1788 if(-1 == buffer_add(&(priv->txbkpbufs),buf,dma_tmp,NULL)){
1789 DMESGE("Unable to allocate mem for buffer LP");
1793 case TX_BEPRIORITY_RING_ADDR:
1794 if(-1 == buffer_add(&(priv->txbepbufs),buf,dma_tmp,NULL)){
1795 DMESGE("Unable to allocate mem for buffer NP");
1800 case TX_VIPRIORITY_RING_ADDR:
1801 if(-1 == buffer_add(&(priv->txvipbufs),buf,dma_tmp,NULL)){
1802 DMESGE("Unable to allocate mem for buffer LP");
1806 case TX_VOPRIORITY_RING_ADDR:
1807 if(-1 == buffer_add(&(priv->txvopbufs),buf,dma_tmp,NULL)){
1808 DMESGE("Unable to allocate mem for buffer NP");
1813 case TX_HIGHPRIORITY_RING_ADDR:
1814 if(-1 == buffer_add(&(priv->txhpbufs),buf,dma_tmp,NULL)){
1815 DMESGE("Unable to allocate mem for buffer HP");
1819 case TX_BEACON_RING_ADDR:
1820 if(-1 == buffer_add(&(priv->txbeaconbufs),buf,dma_tmp,NULL)){
1821 DMESGE("Unable to allocate mem for buffer BP");
1826 *tmp = *tmp &~ (1<<31); // descriptor empty, owned by the drv
1827 *(tmp+2) = (u32)dma_tmp;
1831 *(tmp+4) = (u32)dma_desc+((i+1)*8*4);
1833 *(tmp+4) = (u32)dma_desc;
1839 case TX_MANAGEPRIORITY_RING_ADDR:
1840 priv->txmapringdma=dma_desc;
1841 priv->txmapring=desc;
1844 case TX_BKPRIORITY_RING_ADDR:
1845 priv->txbkpringdma=dma_desc;
1846 priv->txbkpring=desc;
1849 case TX_BEPRIORITY_RING_ADDR:
1850 priv->txbepringdma=dma_desc;
1851 priv->txbepring=desc;
1854 case TX_VIPRIORITY_RING_ADDR:
1855 priv->txvipringdma=dma_desc;
1856 priv->txvipring=desc;
1859 case TX_VOPRIORITY_RING_ADDR:
1860 priv->txvopringdma=dma_desc;
1861 priv->txvopring=desc;
1864 case TX_HIGHPRIORITY_RING_ADDR:
1865 priv->txhpringdma=dma_desc;
1866 priv->txhpring=desc;
1869 case TX_BEACON_RING_ADDR:
1870 priv->txbeaconringdma=dma_desc;
1871 priv->txbeaconring=desc;
1877 DMESG("Tx dma physical address: %x",dma_desc);
1884 void free_tx_desc_rings(struct net_device *dev)
1887 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1888 struct pci_dev *pdev=priv->pdev;
1889 int count = priv->txringcount;
1891 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1892 priv->txmapring, priv->txmapringdma);
1893 buffer_free(dev,&(priv->txmapbufs),priv->txbuffsize,1);
1895 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1896 priv->txbkpring, priv->txbkpringdma);
1897 buffer_free(dev,&(priv->txbkpbufs),priv->txbuffsize,1);
1899 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1900 priv->txbepring, priv->txbepringdma);
1901 buffer_free(dev,&(priv->txbepbufs),priv->txbuffsize,1);
1903 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1904 priv->txvipring, priv->txvipringdma);
1905 buffer_free(dev,&(priv->txvipbufs),priv->txbuffsize,1);
1907 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1908 priv->txvopring, priv->txvopringdma);
1909 buffer_free(dev,&(priv->txvopbufs),priv->txbuffsize,1);
1911 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1912 priv->txhpring, priv->txhpringdma);
1913 buffer_free(dev,&(priv->txhpbufs),priv->txbuffsize,1);
1915 count = priv->txbeaconcount;
1916 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1917 priv->txbeaconring, priv->txbeaconringdma);
1918 buffer_free(dev,&(priv->txbeaconbufs),priv->txbuffsize,1);
1922 void free_beacon_desc_ring(struct net_device *dev,int count)
1925 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1926 struct pci_dev *pdev=priv->pdev;
1928 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1929 priv->txbeaconring, priv->txbeaconringdma);
1931 if (priv->beacon_buf)
1932 pci_free_consistent(priv->pdev,
1933 priv->master_beaconsize,priv->beacon_buf,priv->beacondmabuf);
1937 void free_rx_desc_ring(struct net_device *dev)
1939 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1940 struct pci_dev *pdev = priv->pdev;
1942 int count = priv->rxringcount;
1944 #ifdef CONFIG_RTL8185B
1945 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1946 priv->rxring, priv->rxringdma);
1948 pci_free_consistent(pdev, sizeof(u32)*4*count+256,
1949 priv->rxring, priv->rxringdma);
1952 buffer_free(dev,&(priv->rxbuffer),priv->rxbuffersize,0);
1956 short alloc_rx_desc_ring(struct net_device *dev, u16 bufsize, int count)
1961 dma_addr_t dma_desc,dma_tmp;
1962 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1963 struct pci_dev *pdev=priv->pdev;
1967 #ifdef CONFIG_RTL8185B
1968 rx_desc_size = 8; // 4*8 = 32 bytes
1973 if((bufsize & 0xfff) != bufsize){
1974 DMESGE ("RX buffer allocation too large");
1978 desc = (u32*)pci_alloc_consistent(pdev,sizeof(u32)*rx_desc_size*count+256,
1981 if(dma_desc & 0xff){
1984 * descriptor's buffer must be 256 byte aligned
1985 * should never happen since we specify the DMA mask
1988 DMESGW("Fixing RX alignment");
1989 desc = (u32*)((u8*)desc + 256);
1990 #if (defined(CONFIG_HIGHMEM64G) || defined(CONFIG_64BIT_PHYS_ADDR))
1991 desc = (u32*)((u64)desc &~ 0xff);
1992 dma_desc = (dma_addr_t)((u8*)dma_desc + 256);
1993 dma_desc = (dma_addr_t)((u64)dma_desc &~ 0xff);
1995 desc = (u32*)((u32)desc &~ 0xff);
1996 dma_desc = (dma_addr_t)((u8*)dma_desc + 256);
1997 dma_desc = (dma_addr_t)((u32)dma_desc &~ 0xff);
2002 priv->rxringdma=dma_desc;
2005 for (i=0;i<count;i++){
2007 if ((buf= kmalloc(bufsize * sizeof(u8),GFP_ATOMIC)) == NULL){
2008 DMESGE("Failed to kmalloc RX buffer");
2012 dma_tmp = pci_map_single(pdev,buf,bufsize * sizeof(u8),
2013 PCI_DMA_FROMDEVICE);
2015 #ifdef DEBUG_ZERO_RX
2017 for(j=0;j<bufsize;j++) ((u8*)buf)[i] = 0;
2020 //buf = (void*)pci_alloc_consistent(pdev,bufsize,&dma_tmp);
2021 if(-1 == buffer_add(&(priv->rxbuffer), buf,dma_tmp,
2022 &(priv->rxbufferhead))){
2023 DMESGE("Unable to allocate mem RX buf");
2026 *tmp = 0; //zero pads the header of the descriptor
2027 *tmp = *tmp |( bufsize&0xfff);
2028 *(tmp+2) = (u32)dma_tmp;
2029 *tmp = *tmp |(1<<31); // descriptor void, owned by the NIC
2031 #ifdef DEBUG_RXALLOC
2032 DMESG("Alloc %x size buffer, DMA mem @ %x, virtual mem @ %x",
2033 (u32)(bufsize&0xfff), (u32)dma_tmp, (u32)buf);
2036 tmp=tmp+rx_desc_size;
2039 *(tmp-rx_desc_size) = *(tmp-rx_desc_size) | (1<<30); // this is the last descriptor
2042 #ifdef DEBUG_RXALLOC
2043 DMESG("RX DMA physical address: %x",dma_desc);
2050 void set_nic_rxring(struct net_device *dev)
2053 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2055 //rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
2057 pgreg=read_nic_byte(dev, PGSELECT);
2058 write_nic_byte(dev, PGSELECT, pgreg &~ (1<<PGSELECT_PG_SHIFT));
2060 //rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2062 write_nic_dword(dev, RXRING_ADDR,priv->rxringdma);
2066 void rtl8180_reset(struct net_device *dev)
2068 //u32 txconf = 0x80e00707; //FIXME: Make me understandable
2071 //write_nic_dword(dev,TX_CONF,txconf);
2073 rtl8180_irq_disable(dev);
2075 cr=read_nic_byte(dev,CMD);
2077 cr = cr | (1<<CMD_RST_SHIFT);
2078 write_nic_byte(dev,CMD,cr);
2080 force_pci_posting(dev);
2084 if(read_nic_byte(dev,CMD) & (1<<CMD_RST_SHIFT))
2085 DMESGW("Card reset timeout!");
2087 DMESG("Card successfully reset");
2089 //#ifndef CONFIG_RTL8185B
2090 rtl8180_set_mode(dev,EPROM_CMD_LOAD);
2091 force_pci_posting(dev);
2096 inline u16 ieeerate2rtlrate(int rate)
2129 static u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540,720};
2130 inline u16 rtl8180_rate2rate(short rate)
2132 if (rate >12) return 10;
2133 return rtl_rate[rate];
2135 inline u8 rtl8180_IsWirelessBMode(u16 rate)
2137 if( ((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220) )
2141 u16 N_DBPSOfRate(u16 DataRate);
2145 u8 bManagementFrame,
2153 if( rtl8180_IsWirelessBMode(DataRate) )
2155 if( bManagementFrame || !bShortPreamble || DataRate == 10 )
2157 FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
2161 FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
2163 if( ( FrameLength*8 % (DataRate/10) ) != 0 ) //Get the Ceilling
2165 } else { //802.11g DSSS-OFDM PLCP length field calculation.
2166 N_DBPS = N_DBPSOfRate(DataRate);
2167 Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
2168 + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
2169 FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
2173 u16 N_DBPSOfRate(u16 DataRate)
2221 // For Netgear case, they want good-looking singal strength.
2222 // 2004.12.05, by rcnjko.
2225 NetgearSignalStrengthTranslate(
2232 // Step 1. Scale mapping.
2233 if(CurrSS >= 71 && CurrSS <= 100)
2235 RetSS = 90 + ((CurrSS - 70) / 3);
2237 else if(CurrSS >= 41 && CurrSS <= 70)
2239 RetSS = 78 + ((CurrSS - 40) / 3);
2241 else if(CurrSS >= 31 && CurrSS <= 40)
2243 RetSS = 66 + (CurrSS - 30);
2245 else if(CurrSS >= 21 && CurrSS <= 30)
2247 RetSS = 54 + (CurrSS - 20);
2249 else if(CurrSS >= 5 && CurrSS <= 20)
2251 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2253 else if(CurrSS == 4)
2257 else if(CurrSS == 3)
2261 else if(CurrSS == 2)
2265 else if(CurrSS == 1)
2273 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2275 // Step 2. Smoothing.
2278 RetSS = ((LastSS * 5) + (RetSS)+ 5) / 6;
2280 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2286 // Translate 0-100 signal strength index into dBm.
2290 u8 SignalStrengthIndex // 0-100 index.
2293 long SignalPower; // in dBm.
2295 // Translate to dBm (x=0.5y-95).
2296 SignalPower = (long)((SignalStrengthIndex + 1) >> 1);
2303 // Perform signal smoothing for dynamic mechanism.
2304 // This is different with PerformSignalSmoothing8185 in smoothing fomula.
2305 // No dramatic adjustion is apply because dynamic mechanism need some degree
2306 // of correctness. Ported from 8187B.
2307 // 2007-02-26, by Bruce.
2310 PerformUndecoratedSignalSmoothing8185(
2311 struct r8180_priv *priv,
2317 // Determin the current packet is CCK rate.
2318 priv->bCurCCKPkt = bCckRate;
2320 if(priv->UndecoratedSmoothedSS >= 0)
2322 priv->UndecoratedSmoothedSS = ( (priv->UndecoratedSmoothedSS * 5) + (priv->SignalStrength * 10) ) / 6;
2326 priv->UndecoratedSmoothedSS = priv->SignalStrength * 10;
2329 priv->UndercorateSmoothedRxPower = ( (priv->UndercorateSmoothedRxPower * 50) + (priv->RxPower* 11)) / 60;
2331 // printk("Sommthing SignalSterngth (%d) => UndecoratedSmoothedSS (%d)\n", priv->SignalStrength, priv->UndecoratedSmoothedSS);
2332 // printk("Sommthing RxPower (%d) => UndecoratedRxPower (%d)\n", priv->RxPower, priv->UndercorateSmoothedRxPower);
2334 //if(priv->CurCCKRSSI >= 0 && bCckRate)
2337 priv->CurCCKRSSI = priv->RSSI;
2341 priv->CurCCKRSSI = 0;
2344 // Boundary checking.
2345 // TODO: The overflow condition does happen, if we want to fix,
2346 // we shall recalculate thresholds first.
2347 if(priv->UndecoratedSmoothedSS > 100)
2349 // printk("UndecoratedSmoothedSS(%d) overflow, SignalStrength(%d)\n", priv->UndecoratedSmoothedSS, priv->SignalStrength);
2351 if(priv->UndecoratedSmoothedSS < 0)
2353 // printk("UndecoratedSmoothedSS(%d) underflow, SignalStrength(%d)\n", priv->UndecoratedSmoothedSS, priv->SignalStrength);
2360 /* This is rough RX isr handling routine*/
2361 void rtl8180_rx(struct net_device *dev)
2363 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2364 struct sk_buff *tmp_skb;
2366 //struct sk_buff *skb;
2370 unsigned char quality, signal;
2381 u8 LNA_gain[4]={02, 17, 29, 39};
2383 struct ieee80211_hdr *hdr;//by amy
2385 u8 bHwError = 0,bCRC = 0,bICV = 0;
2389 bool bCckRate = false;
2391 long SignalStrengthIndex = 0;//+by amy 080312
2392 // u8 SignalStrength = 0;
2393 struct ieee80211_rx_stats stats = {
2397 // .mac_time = jiffies,
2398 .freq = IEEE80211_24GHZ_BAND,
2401 #ifdef CONFIG_RTL8185B
2402 stats.nic_type = NIC_8185B;
2406 stats.nic_type = NIC_8185;
2409 //printk("receive frame!%d\n",count++);
2410 //if (!priv->rxbuffer) DMESG ("EE: NIC RX ack, but RX queue corrupted!");
2413 if ((*(priv->rxringtail)) & (1<<31)) {
2415 /* we have got an RX int, but the descriptor
2416 * we are pointing is empty*/
2418 priv->stats.rxnodata++;
2419 priv->ieee80211->stats.rx_errors++;
2421 /* if (! *(priv->rxring) & (1<<31)) {
2423 priv->stats.rxreset++;
2424 priv->rxringtail=priv->rxring;
2425 priv->rxbuffer=priv->rxbufferhead;
2430 /* Maybe it is possible that the NIC has skipped some descriptors or
2431 * it has reset its internal pointer to the beginning of the ring
2432 * we search for the first filled descriptor in the ring, or we break
2433 * putting again the pointer in the old location if we do not found any.
2434 * This is quite dangerous, what does happen if the nic writes
2435 * two descriptor (say A and B) when we have just checked the descriptor
2436 * A and we are going to check the descriptor B..This might happen if the
2437 * interrupt was dummy, there was not really filled descriptors and
2438 * the NIC didn't lose pointer
2441 //priv->stats.rxwrkaround++;
2443 tmp = priv->rxringtail;
2444 while (*(priv->rxringtail) & (1<<31)){
2446 priv->rxringtail+=4;
2448 if(priv->rxringtail >=
2449 (priv->rxring)+(priv->rxringcount )*4)
2450 priv->rxringtail=priv->rxring;
2452 priv->rxbuffer=(priv->rxbuffer->next);
2454 if(priv->rxringtail == tmp ){
2455 //DMESG("EE: Could not find RX pointer");
2456 priv->stats.rxnopointer++;
2463 tmp = priv->rxringtail;
2465 if(tmp == priv->rxring)
2466 //tmp = priv->rxring + (priv->rxringcount )*rx_desc_size; xiong-2006-11-15
2467 tmp = priv->rxring + (priv->rxringcount - 1)*rx_desc_size;
2469 tmp -= rx_desc_size;
2471 if(! (*tmp & (1<<31)))
2473 }while(tmp != priv->rxring);
2475 if(tmp2) priv->rxringtail = tmp2;
2480 /* while there are filled descriptors */
2481 while(!(*(priv->rxringtail) & (1<<31))){
2482 if(*(priv->rxringtail) & (1<<26))
2483 DMESGW("RX buffer overflow");
2484 if(*(priv->rxringtail) & (1<<12))
2485 priv->stats.rxicverr++;
2487 if(*(priv->rxringtail) & (1<<27)){
2488 priv->stats.rxdmafail++;
2489 //DMESG("EE: RX DMA FAILED at buffer pointed by descriptor %x",(u32)priv->rxringtail);
2493 pci_dma_sync_single_for_cpu(priv->pdev,
2494 priv->rxbuffer->dma,
2495 priv->rxbuffersize * \
2497 PCI_DMA_FROMDEVICE);
2499 first = *(priv->rxringtail) & (1<<29) ? 1:0;
2500 if(first) priv->rx_prevlen=0;
2502 last = *(priv->rxringtail) & (1<<28) ? 1:0;
2504 lastlen=((*priv->rxringtail) &0xfff);
2506 /* if the last descriptor (that should
2507 * tell us the total packet len) tell
2508 * us something less than the descriptors
2509 * len we had until now, then there is some
2511 * workaround to prevent kernel panic
2513 if(lastlen < priv->rx_prevlen)
2516 len=lastlen-priv->rx_prevlen;
2518 if(*(priv->rxringtail) & (1<<13)) {
2519 //lastlen=((*priv->rxringtail) &0xfff);
2520 if ((*(priv->rxringtail) & 0xfff) <500)
2521 priv->stats.rxcrcerrmin++;
2522 else if ((*(priv->rxringtail) & 0x0fff) >1000)
2523 priv->stats.rxcrcerrmax++;
2525 priv->stats.rxcrcerrmid++;
2530 len = priv->rxbuffersize;
2533 #ifdef CONFIG_RTL8185B
2535 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
2537 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
2544 #ifdef CONFIG_RTL818X_S
2548 priv->rx_prevlen+=len;
2550 if(priv->rx_prevlen > MAX_FRAG_THRESHOLD + 100){
2551 /* HW is probably passing several buggy frames
2552 * without FD or LD flag set.
2553 * Throw this garbage away to prevent skb
2556 if(!priv->rx_skb_complete)
2557 dev_kfree_skb_any(priv->rx_skb);
2558 priv->rx_skb_complete = 1;
2561 #ifdef DEBUG_RX_FRAG
2562 DMESG("Iteration.. len %x",len);
2563 if(first) DMESG ("First descriptor");
2564 if(last) DMESG("Last descriptor");
2567 #ifdef DEBUG_RX_VERBOSE
2568 print_buffer( priv->rxbuffer->buf, len);
2571 #ifdef CONFIG_RTL8185B
2572 signal=(unsigned char)(((*(priv->rxringtail+3))& (0x00ff0000))>>16);
2573 signal=(signal&0xfe)>>1; // Modify by hikaru 6.6
2575 quality=(unsigned char)((*(priv->rxringtail+3)) & (0xff));
2577 stats.mac_time[0] = *(priv->rxringtail+1);
2578 stats.mac_time[1] = *(priv->rxringtail+2);
2579 rxpower =((char)(((*(priv->rxringtail+4))& (0x00ff0000))>>16))/2 - 42;
2580 RSSI = ((u8)(((*(priv->rxringtail+3)) & (0x0000ff00))>> 8)) & (0x7f);
2583 signal=((*(priv->rxringtail+1))& (0xff0000))>>16;
2584 signal=(signal&0xfe)>>1; // Modify by hikaru 6.6
2586 quality=((*(priv->rxringtail+1)) & (0xff));
2588 stats.mac_time[0] = *(priv->rxringtail+2);
2589 stats.mac_time[1] = *(priv->rxringtail+3);
2591 rate=((*(priv->rxringtail)) &
2592 ((1<<23)|(1<<22)|(1<<21)|(1<<20)))>>20;
2594 stats.rate = rtl8180_rate2rate(rate);
2596 Antenna = (((*(priv->rxringtail +3))& (0x00008000)) == 0 )? 0:1 ;
2597 // printk("in rtl8180_rx():Antenna is %d\n",Antenna);
2598 //by amy for antenna
2599 if(!rtl8180_IsWirelessBMode(stats.rate))
2602 RxAGC_dBm = rxpower+1; //bias
2606 RxAGC_dBm = signal;//bit 0 discard
2608 LNA = (u8) (RxAGC_dBm & 0x60 ) >> 5 ; //bit 6~ bit 5
2609 BB = (u8) (RxAGC_dBm & 0x1F); // bit 4 ~ bit 0
2611 RxAGC_dBm = -( LNA_gain[LNA] + (BB *2) ); //Pin_11b=-(LNA_gain+BB_gain) (dBm)
2613 RxAGC_dBm +=4; //bias
2616 if(RxAGC_dBm & 0x80) //absolute value
2617 RXAGC= ~(RxAGC_dBm)+1;
2618 bCckRate = rtl8180_IsWirelessBMode(stats.rate);
2619 // Translate RXAGC into 1-100.
2620 if(!rtl8180_IsWirelessBMode(stats.rate))
2626 RXAGC=(90-RXAGC)*100/65;
2634 RXAGC=(95-RXAGC)*100/65;
2636 priv->SignalStrength = (u8)RXAGC;
2637 priv->RecvSignalPower = RxAGC_dBm ; // It can use directly by SD3 CMLin
2638 priv->RxPower = rxpower;
2641 // SQ translation formular is provided by SD3 DZ. 2006.06.27, by rcnjko.
2643 quality = 1;//0; //0 will cause epc to show signal zero , walk aroud now;
2644 else if(quality < 27)
2647 quality = 127 - quality;
2648 priv->SignalQuality = quality;
2649 if(!priv->card_8185)
2650 printk("check your card type\n");
2652 stats.signal = (u8)quality;//priv->wstats.qual.level = priv->SignalStrength;
2653 stats.signalstrength = RXAGC;
2654 if(stats.signalstrength > 100)
2655 stats.signalstrength = 100;
2656 stats.signalstrength = (stats.signalstrength * 70)/100 + 30;
2657 // printk("==========================>rx : RXAGC is %d,signalstrength is %d\n",RXAGC,stats.signalstrength);
2658 stats.rssi = priv->wstats.qual.qual = priv->SignalQuality;
2659 stats.noise = priv->wstats.qual.noise = 100 - priv ->wstats.qual.qual;
2661 bHwError = (((*(priv->rxringtail))& (0x00000fff)) == 4080)| (((*(priv->rxringtail))& (0x04000000)) != 0 )
2662 | (((*(priv->rxringtail))& (0x08000000)) != 0 )| (((~(*(priv->rxringtail)))& (0x10000000)) != 0 )| (((~(*(priv->rxringtail)))& (0x20000000)) != 0 );
2663 bCRC = ((*(priv->rxringtail)) & (0x00002000)) >> 13;
2664 bICV = ((*(priv->rxringtail)) & (0x00001000)) >> 12;
2665 hdr = (struct ieee80211_hdr *)priv->rxbuffer->buf;
2666 fc = le16_to_cpu(hdr->frame_ctl);
2667 type = WLAN_FC_GET_TYPE(fc);
2669 if((IEEE80211_FTYPE_CTL != type) &&
2670 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3))
2671 && (!bHwError) && (!bCRC)&& (!bICV))
2674 // Perform signal smoothing for dynamic mechanism on demand.
2675 // This is different with PerformSignalSmoothing8185 in smoothing fomula.
2676 // No dramatic adjustion is apply because dynamic mechanism need some degree
2677 // of correctness. 2007.01.23, by shien chang.
2678 PerformUndecoratedSignalSmoothing8185(priv,bCckRate);
2680 // For good-looking singal strength.
2682 SignalStrengthIndex = NetgearSignalStrengthTranslate(
2683 priv->LastSignalStrengthInPercent,
2684 priv->SignalStrength);
2686 priv->LastSignalStrengthInPercent = SignalStrengthIndex;
2687 priv->Stats_SignalStrength = TranslateToDbm8185((u8)SignalStrengthIndex);
2689 // We need more correct power of received packets and the "SignalStrength" of RxStats is beautified,
2690 // so we record the correct power here.
2692 priv->Stats_SignalQuality =(long) (priv->Stats_SignalQuality * 5 + (long)priv->SignalQuality + 5) / 6;
2693 priv->Stats_RecvSignalPower = (long)(priv->Stats_RecvSignalPower * 5 + priv->RecvSignalPower -1) / 6;
2695 // Figure out which antenna that received the lasted packet.
2696 priv->LastRxPktAntenna = Antenna ? 1 : 0; // 0: aux, 1: main.
2698 SwAntennaDiversityRxOk8185(dev, priv->SignalStrength);
2701 //by amy for antenna
2710 if(!priv->rx_skb_complete){
2711 /* seems that HW sometimes fails to reiceve and
2712 doesn't provide the last descriptor */
2714 DMESG("going to free incomplete skb");
2716 dev_kfree_skb_any(priv->rx_skb);
2717 priv->stats.rxnolast++;
2719 DMESG("free incomplete skb OK");
2722 /* support for prism header has been originally added by Christian */
2723 if(priv->prism_hdr && priv->ieee80211->iw_mode == IW_MODE_MONITOR){
2726 priv->rx_skb = dev_alloc_skb(len+2+PRISM_HDR_SIZE);
2727 if(! priv->rx_skb) goto drop;
2729 prism_hdr = (u32*) skb_put(priv->rx_skb,PRISM_HDR_SIZE);
2730 prism_hdr[0]=htonl(0x80211001); //version
2731 prism_hdr[1]=htonl(0x40); //length
2732 prism_hdr[2]=htonl(stats.mac_time[1]); //mactime (HIGH)
2733 prism_hdr[3]=htonl(stats.mac_time[0]); //mactime (LOW)
2734 rdtsc(prism_hdr[5], prism_hdr[4]); //hostime (LOW+HIGH)
2735 prism_hdr[4]=htonl(prism_hdr[4]); //Byte-Order aendern
2736 prism_hdr[5]=htonl(prism_hdr[5]); //Byte-Order aendern
2737 prism_hdr[6]=0x00; //phytype
2738 prism_hdr[7]=htonl(priv->chan); //channel
2739 prism_hdr[8]=htonl(stats.rate); //datarate
2740 prism_hdr[9]=0x00; //antenna
2741 prism_hdr[10]=0x00; //priority
2742 prism_hdr[11]=0x00; //ssi_type
2743 prism_hdr[12]=htonl(stats.signal); //ssi_signal
2744 prism_hdr[13]=htonl(stats.noise); //ssi_noise
2745 prism_hdr[14]=0x00; //preamble
2746 prism_hdr[15]=0x00; //encoding
2750 priv->rx_skb = dev_alloc_skb(len+2);
2751 if( !priv->rx_skb) goto drop;
2753 DMESG("Alloc initial skb %x",len+2);
2757 priv->rx_skb_complete=0;
2758 priv->rx_skb->dev=dev;
2760 /* if we are here we should have already RXed
2762 * If we get here and the skb is not allocated then
2763 * we have just throw out garbage (skb not allocated)
2764 * and we are still rxing garbage....
2766 if(!priv->rx_skb_complete){
2768 tmp_skb= dev_alloc_skb(priv->rx_skb->len +len+2);
2770 if(!tmp_skb) goto drop;
2774 DMESG("Realloc skb %x",len+2);
2778 DMESG("going copy prev frag %x",priv->rx_skb->len);
2780 memcpy(skb_put(tmp_skb,priv->rx_skb->len),
2784 DMESG("skb copy prev frag complete");
2787 dev_kfree_skb_any(priv->rx_skb);
2789 DMESG("prev skb free ok");
2792 priv->rx_skb=tmp_skb;
2796 DMESG("going to copy current payload %x",len);
2798 if(!priv->rx_skb_complete) {
2799 #ifdef CONFIG_RTL8185B
2801 memcpy(skb_put(priv->rx_skb,len),
2802 (((unsigned char *)priv->rxbuffer->buf) + 2),len);
2805 memcpy(skb_put(priv->rx_skb,len),
2806 priv->rxbuffer->buf,len);
2807 #ifdef CONFIG_RTL8185B
2812 DMESG("current fragment skb copy complete");
2815 if(last && !priv->rx_skb_complete){
2818 DMESG("Got last fragment");
2821 if(priv->rx_skb->len > 4)
2822 skb_trim(priv->rx_skb,priv->rx_skb->len-4);
2824 DMESG("yanked out crc, passing to the upper layer");
2827 #ifndef RX_DONT_PASS_UL
2828 if(!ieee80211_rx(priv->ieee80211,
2829 priv->rx_skb, &stats)){
2831 DMESGW("Packet not consumed");
2833 #endif // RX_DONT_PASS_UL
2835 dev_kfree_skb_any(priv->rx_skb);
2836 #ifndef RX_DONT_PASS_UL
2844 priv->rx_skb_complete=1;
2849 pci_dma_sync_single_for_device(priv->pdev,
2850 priv->rxbuffer->dma,
2851 priv->rxbuffersize * \
2853 PCI_DMA_FROMDEVICE);
2856 drop: // this is used when we have not enought mem
2858 /* restore the descriptor */
2859 *(priv->rxringtail+2)=priv->rxbuffer->dma;
2860 *(priv->rxringtail)=*(priv->rxringtail) &~ 0xfff;
2861 *(priv->rxringtail)=
2862 *(priv->rxringtail) | priv->rxbuffersize;
2864 *(priv->rxringtail)=
2865 *(priv->rxringtail) | (1<<31);
2871 DMESG("Current descriptor: %x",(u32)priv->rxringtail);
2873 //unsigned long flags;
2874 //spin_lock_irqsave(&priv->irq_lock,flags);
2876 priv->rxringtail+=rx_desc_size;
2877 if(priv->rxringtail >=
2878 (priv->rxring)+(priv->rxringcount )*rx_desc_size)
2879 priv->rxringtail=priv->rxring;
2881 //spin_unlock_irqrestore(&priv->irq_lock,flags);
2884 priv->rxbuffer=(priv->rxbuffer->next);
2890 // if(get_curr_tx_free_desc(dev,priority))
2891 // ieee80211_sta_ps_sleep(priv->ieee80211, &tmp, &tmp2);
2898 void rtl8180_dma_kick(struct net_device *dev, int priority)
2900 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2902 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2909 write_nic_byte(dev,TX_DMA_POLLING,
2910 (1<< TX_DMA_POLLING_LOWPRIORITY_SHIFT) |
2911 priv->dma_poll_mask);
2916 write_nic_byte(dev,TX_DMA_POLLING,
2917 (1<< TX_DMA_POLLING_NORMPRIORITY_SHIFT) |
2918 priv->dma_poll_mask);
2923 write_nic_byte(dev,TX_DMA_POLLING,
2924 (1<< TX_DMA_POLLING_HIPRIORITY_SHIFT) |
2925 priv->dma_poll_mask);
2930 write_nic_byte(dev, TX_DMA_POLLING,
2931 (1 << (priority + 1)) | priv->dma_poll_mask);
2932 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2934 force_pci_posting(dev);
2938 void rtl8180_tx_queues_stop(struct net_device *dev)
2940 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2941 u8 dma_poll_mask = (1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
2942 dma_poll_mask |= (1<<TX_DMA_STOP_HIPRIORITY_SHIFT);
2943 dma_poll_mask |= (1<<TX_DMA_STOP_NORMPRIORITY_SHIFT);
2944 dma_poll_mask |= (1<<TX_DMA_STOP_BEACON_SHIFT);
2946 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2947 write_nic_byte(dev,TX_DMA_POLLING,dma_poll_mask);
2948 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2952 void rtl8180_data_hard_stop(struct net_device *dev)
2954 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2956 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2957 #ifdef CONFIG_RTL8185B
2958 priv->dma_poll_stop_mask |= TPPOLLSTOP_AC_VIQ;
2959 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
2961 priv->dma_poll_mask |= (1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
2962 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
2964 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2968 void rtl8180_data_hard_resume(struct net_device *dev)
2970 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2972 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2973 #ifdef CONFIG_RTL8185B
2974 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_AC_VIQ);
2975 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
2977 priv->dma_poll_mask &= ~(1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
2978 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
2980 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2984 /* this function TX data frames when the ieee80211 stack requires this.
2985 * It checks also if we need to stop the ieee tx queue, eventually do it
2987 void rtl8180_hard_data_xmit(struct sk_buff *skb,struct net_device *dev, int
2990 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2992 struct ieee80211_hdr_3addr *h = (struct ieee80211_hdr_3addr *) skb->data;
2993 short morefrag = (h->frame_ctl) & IEEE80211_FCTL_MOREFRAGS;
2994 unsigned long flags;
2996 //static int count = 0;
2998 mode = priv->ieee80211->iw_mode;
3000 rate = ieeerate2rtlrate(rate);
3002 * This function doesn't require lock because we make
3003 * sure it's called with the tx_lock already acquired.
3004 * this come from the kernel's hard_xmit callback (trought
3005 * the ieee stack, or from the try_wake_queue (again trought
3008 #ifdef CONFIG_RTL8185B
3009 priority = AC2Q(skb->priority);
3011 priority = LOW_PRIORITY;
3013 spin_lock_irqsave(&priv->tx_lock,flags);
3015 if(priv->ieee80211->bHwRadioOff)
3017 spin_unlock_irqrestore(&priv->tx_lock,flags);
3022 //printk(KERN_WARNING "priority = %d@%d\n", priority, count++);
3023 if (!check_nic_enought_desc(dev, priority)){
3024 //DMESG("Error: no descriptor left by previous TX (avail %d) ",
3025 // get_curr_tx_free_desc(dev, priority));
3026 DMESGW("Error: no descriptor left by previous TX (avail %d) ",
3027 get_curr_tx_free_desc(dev, priority));
3028 //printk(KERN_WARNING "==============================================================> \n");
3029 ieee80211_stop_queue(priv->ieee80211);
3031 rtl8180_tx(dev, skb->data, skb->len, priority, morefrag,0,rate);
3032 if (!check_nic_enought_desc(dev, priority))
3033 ieee80211_stop_queue(priv->ieee80211);
3035 //dev_kfree_skb_any(skb);
3036 spin_unlock_irqrestore(&priv->tx_lock,flags);
3040 /* This is a rough attempt to TX a frame
3041 * This is called by the ieee 80211 stack to TX management frames.
3042 * If the ring is full packet are dropped (for data frame the queue
3043 * is stopped before this can happen). For this reason it is better
3044 * if the descriptors are larger than the largest management frame
3045 * we intend to TX: i'm unsure what the HW does if it will not found
3046 * the last fragment of a frame because it has been dropped...
3047 * Since queues for Management and Data frames are different we
3048 * might use a different lock than tx_lock (for example mgmt_tx_lock)
3050 /* these function may loops if invoked with 0 descriptors or 0 len buffer*/
3051 int rtl8180_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
3053 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3055 unsigned long flags;
3059 #ifdef CONFIG_RTL8185B
3060 priority = MANAGE_PRIORITY;
3062 priority = NORM_PRIORITY;
3065 spin_lock_irqsave(&priv->tx_lock,flags);
3067 if(priv->ieee80211->bHwRadioOff)
3069 spin_unlock_irqrestore(&priv->tx_lock,flags);
3071 dev_kfree_skb_any(skb);
3075 rtl8180_tx(dev, skb->data, skb->len, priority,
3076 0, 0,ieeerate2rtlrate(priv->ieee80211->basic_rate));
3078 priv->ieee80211->stats.tx_bytes+=skb->len;
3079 priv->ieee80211->stats.tx_packets++;
3080 spin_unlock_irqrestore(&priv->tx_lock,flags);
3082 dev_kfree_skb_any(skb);
3086 // longpre 144+48 shortpre 72+24
3087 u16 rtl8180_len2duration(u32 len, short rate,short* ext)
3096 duration = ((len+4)<<4) /0x2;
3097 drift = ((len+4)<<4) % 0x2;
3098 if(drift ==0 ) break;
3104 duration = ((len+4)<<4) /0x4;
3105 drift = ((len+4)<<4) % 0x4;
3106 if(drift ==0 ) break;
3112 duration = ((len+4)<<4) /0xb;
3113 drift = ((len+4)<<4) % 0xb;
3122 duration = ((len+4)<<4) /0x16;
3123 drift = ((len+4)<<4) % 0x16;
3137 void rtl8180_prepare_beacon(struct net_device *dev)
3140 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3142 struct sk_buff *skb;
3144 u16 word = read_nic_word(dev, BcnItv);
3145 word &= ~BcnItv_BcnItv; // clear Bcn_Itv
3146 word |= cpu_to_le16(priv->ieee80211->current_network.beacon_interval);//0x64;
3147 write_nic_word(dev, BcnItv, word);
3150 skb = ieee80211_get_beacon(priv->ieee80211);
3152 rtl8180_tx(dev,skb->data,skb->len,BEACON_PRIORITY,
3153 0,0,ieeerate2rtlrate(priv->ieee80211->basic_rate));
3154 dev_kfree_skb_any(skb);
3157 //DMESG("size %x",len);
3158 if(*tail & (1<<31)){
3160 //DMESG("No more beacon TX desc");
3164 //while(! *tail & (1<<31)){
3165 *tail= 0; // zeroes header
3167 *tail = *tail| (1<<29) ; //fist segment of the packet
3168 *tail = (*tail) | (1<<28); // last segment
3169 // *tail = *tail | (1<<18); // this is a beacon frame
3170 *(tail+3)=*(tail+3) &~ 0xfff;
3171 *(tail+3)=*(tail+3) | len; // buffer lenght
3173 // zeroes the second 32-bits dword of the descriptor
3175 *tail = *tail | (rate << 24);
3177 duration = rtl8180_len2duration(len,rate,&ext);
3179 *(tail+1) = *(tail+1) | ((duration & 0x7fff)<<16);
3181 *tail = *tail | (1<<31);
3182 //^ descriptor ready to be txed
3183 if((tail - begin)/8 == priv->txbeaconcount-1)
3191 /* This function do the real dirty work: it enqueues a TX command
3192 * descriptor in the ring buffer, copyes the frame in a TX buffer
3193 * and kicks the NIC to ensure it does the DMA transfer.
3195 short rtl8180_tx(struct net_device *dev, u8* txbuf, int len, int priority,
3196 short morefrag, short descfrag, int rate)
3198 struct r8180_priv *priv = ieee80211_priv(dev);
3199 u32 *tail,*temp_tail;
3210 struct buffer* buflist;
3211 //unsigned long flags;
3212 #ifdef CONFIG_RTL8185B
3213 struct ieee80211_hdr_3addr *frag_hdr = (struct ieee80211_hdr_3addr *)txbuf;
3215 u8 bUseShortPreamble = 0;
3219 //u8 RetryLimit = 0;
3222 u16 ThisFrameTime = 0;
3223 u16 TxDescDuration = 0;
3224 u8 ownbit_flag = false; //added by david woo for sync Tx, 2007.12.14
3228 case MANAGE_PRIORITY:
3229 tail=priv->txmapringtail;
3230 begin=priv->txmapring;
3231 buflist = priv->txmapbufstail;
3232 count = priv->txringcount;
3236 tail=priv->txbkpringtail;
3237 begin=priv->txbkpring;
3238 buflist = priv->txbkpbufstail;
3239 count = priv->txringcount;
3243 tail=priv->txbepringtail;
3244 begin=priv->txbepring;
3245 buflist = priv->txbepbufstail;
3246 count = priv->txringcount;
3250 tail=priv->txvipringtail;
3251 begin=priv->txvipring;
3252 buflist = priv->txvipbufstail;
3253 count = priv->txringcount;
3257 tail=priv->txvopringtail;
3258 begin=priv->txvopring;
3259 buflist = priv->txvopbufstail;
3260 count = priv->txringcount;
3264 tail=priv->txhpringtail;
3265 begin=priv->txhpring;
3266 buflist = priv->txhpbufstail;
3267 count = priv->txringcount;
3270 case BEACON_PRIORITY:
3271 tail=priv->txbeaconringtail;
3272 begin=priv->txbeaconring;
3273 buflist = priv->txbeaconbufstail;
3274 count = priv->txbeaconcount;
3282 //printk("in rtl8180_tx(): rate is %d\n",priv->ieee80211->rate);
3284 memcpy(&dest, frag_hdr->addr1, ETH_ALEN);
3285 if (is_multicast_ether_addr(dest) ||
3286 is_broadcast_ether_addr(dest))
3293 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate), 0, bUseShortPreamble);
3294 TxDescDuration = ThisFrameTime;
3295 } else {// Unicast packet
3299 //YJ,add,080828,for Keep alive
3300 priv->NumTxUnicast++;
3302 // Figure out ACK rate according to BSS basic rate and Tx rate, 2006.03.08 by rcnjko.
3303 //AckRate = ComputeAckRate( pMgntInfo->mBrates, (u1Byte)(pTcb->DataRate) );
3304 // Figure out ACK time according to the AckRate and assume long preamble is used on receiver, 2006.03.08, by rcnjko.
3305 //AckTime = ComputeTxTime( sAckCtsLng/8, AckRate, FALSE, FALSE);
3306 //For simplicity, just use the 1M basic rate
3307 //AckTime = ComputeTxTime(14, 540,0, 0); // AckCTSLng = 14 use 1M bps send
3308 AckTime = ComputeTxTime(14, 10,0, 0); // AckCTSLng = 14 use 1M bps send
3309 //AckTime = ComputeTxTime(14, 2,false, false); // AckCTSLng = 14 use 1M bps send
3311 if ( ((len + sCrcLng) > priv->rts) && priv->rts )
3313 u16 RtsTime, CtsTime;
3318 // Rate and time required for RTS.
3319 RtsTime = ComputeTxTime( sAckCtsLng/8,priv->ieee80211->basic_rate, 0, 0);
3320 // Rate and time required for CTS.
3321 CtsTime = ComputeTxTime(14, 10,0, 0); // AckCTSLng = 14 use 1M bps send
3323 // Figure out time required to transmit this frame.
3324 ThisFrameTime = ComputeTxTime(len + sCrcLng,
3325 rtl8180_rate2rate(rate),
3329 // RTS-CTS-ThisFrame-ACK.
3330 RtsDur = CtsTime + ThisFrameTime + AckTime + 3*aSifsTime;
3332 TxDescDuration = RtsTime + RtsDur;
3334 else {// Normal case.
3339 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate), 0, bUseShortPreamble);
3340 TxDescDuration = ThisFrameTime + aSifsTime + AckTime;
3343 if(!(frag_hdr->frame_ctl & IEEE80211_FCTL_MOREFRAGS)) { //no more fragment
3345 Duration = aSifsTime + AckTime;
3346 } else { // One or more fragments remained.
3348 NextFragTime = ComputeTxTime( len + sCrcLng, //pretend following packet length equal current packet
3349 rtl8180_rate2rate(rate),
3351 bUseShortPreamble );
3353 //ThisFrag-ACk-NextFrag-ACK.
3354 Duration = NextFragTime + 3*aSifsTime + 2*AckTime;
3357 } // End of Unicast packet
3359 frag_hdr->duration_id = Duration;
3362 buflen=priv->txbuffsize;
3365 //printk("================================>buflen = %d, remain = %d!\n", buflen,remain);
3367 #ifdef DEBUG_TX_FRAG
3368 DMESG("TX iteration");
3371 DMESG("TX: filling descriptor %x",(u32)tail);
3375 DMESGE("TX buffer error, cannot TX frames. pri %d.", priority);
3376 //spin_unlock_irqrestore(&priv->tx_lock,flags);
3381 if( (*tail & (1<<31)) && (priority != BEACON_PRIORITY)){
3383 DMESGW("No more TX desc, returning %x of %x",
3385 priv->stats.txrdu++;
3386 #ifdef DEBUG_TX_DESC
3387 check_tx_ring(dev,priority);
3388 // netif_stop_queue(dev);
3389 // netif_carrier_off(dev);
3391 // spin_unlock_irqrestore(&priv->tx_lock,flags);
3397 *tail= 0; // zeroes header
3404 if(priv->card_8185){
3405 //FIXME: this should be triggered by HW encryption parameters.
3406 *tail |= (1<<15); //no encrypt
3407 // *tail |= (1<<30); //raise int when completed
3409 // *tail = *tail | (1<<16);
3410 if(remain==len && !descfrag) {
3411 ownbit_flag = false; //added by david woo,2007.12.14
3412 #ifdef DEBUG_TX_FRAG
3413 DMESG("First descriptor");
3415 *tail = *tail| (1<<29) ; //fist segment of the packet
3416 *tail = *tail |(len);
3421 for(i=0;i<buflen&& remain >0;i++,remain--){
3422 ((u8*)buf)[i]=txbuf[i]; //copy data into descriptor pointed DMAble buffer
3423 if(remain == 4 && i+4 >= buflen) break;
3424 /* ensure the last desc has at least 4 bytes payload */
3428 *(tail+3)=*(tail+3) &~ 0xfff;
3429 *(tail+3)=*(tail+3) | i; // buffer lenght
3430 // Use short preamble or not
3431 if (priv->ieee80211->current_network.capability&WLAN_CAPABILITY_SHORT_PREAMBLE)
3432 if (priv->plcp_preamble_mode==1 && rate!=0) // short mode now, not long!
3433 // *tail |= (1<<16); // enable short preamble mode.
3435 #ifdef CONFIG_RTL8185B
3440 if(bRTSEnable) //rts enable
3442 *tail |= ((ieeerate2rtlrate(priv->ieee80211->basic_rate))<<19);//RTS RATE
3443 *tail |= (1<<23);//rts enable
3444 *(tail+1) |=(RtsDur&0xffff);//RTS Duration
3446 *(tail+3) |= ((TxDescDuration&0xffff)<<16); //DURATION
3447 // *(tail+3) |= (0xe6<<16);
3448 *(tail+5) |= (11<<8);//(priv->retry_data<<8); //retry lim ;
3451 #ifdef CONFIG_RTL8187B
3452 if ( (len>priv->rts) && priv->rts && priority!=MANAGE_PRIORITY){
3454 if ( (len>priv->rts) && priv->rts && priority==LOW_PRIORITY){
3456 *tail |= (1<<23); //enalbe RTS function
3457 *tail |= (0<<19); //use 1M bps send RTS packet
3458 AckCtsTime = ComputeTxTime(14, 10,0, 0); // AckCTSLng = 14 use 1M bps send
3459 FrameTime = ComputeTxTime(len + 4, rtl8180_rate2rate(rate), 0, *tail&(1<<16));
3460 // RTS/CTS time is calculate as follow
3461 duration = FrameTime + 3*10 + 2*AckCtsTime; //10us is the SifsTime;
3462 *(tail+1) |= duration; //Need to edit here! ----hikaru
3464 *(tail+1)= 0; // zeroes the second 32-bits dword of the descriptor
3468 *tail = *tail | ((rate&0xf) << 24);
3469 //DMESG("rate %d",rate);
3471 if(priv->card_8185){
3474 *(tail+5)&= ~(1<<24); /* tx ant 0 */
3476 *(tail+5) &= ~(1<<23); /* random tx agc 23-16 */
3477 *(tail+5) |= (1<<22)|(1<<21)|(1<<20)|(1<<19)|(1<<18)|(1<<17)|(1<<16);
3480 ~((1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(1<<10)|(1<<9)|(1<<8));
3481 *(tail+5) |= (7<<8); // Max retry limit
3483 *(tail+5) &= ~((1<<7)|(1<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0));
3484 *(tail+5) |= (8<<4); // Max contention window
3485 *(tail+6) |= 4; // Min contention window
3490 /* hw_plcp_len is not used for rtl8180 chip */
3492 if(priv->card_8185 == 0 || !priv->hw_plcp_len){
3494 duration = rtl8180_len2duration(len,
3499 DMESG("PLCP duration %d",duration );
3500 //DMESG("drift %d",drift);
3501 DMESG("extension %s", (ext==1) ? "on":"off");
3503 *(tail+1) = *(tail+1) | ((duration & 0x7fff)<<16);
3504 if(ext) *(tail+1) = *(tail+1) |(1<<31); //plcp length extension
3507 if(morefrag) *tail = (*tail) | (1<<17); // more fragment
3508 if(!remain) *tail = (*tail) | (1<<28); // last segment of frame
3510 #ifdef DEBUG_TX_FRAG
3511 if(!remain)DMESG("Last descriptor");
3512 if(morefrag)DMESG("More frag");
3514 *(tail+5) = *(tail+5)|(2<<27);
3515 *(tail+7) = *(tail+7)|(1<<4);
3520 *tail = *tail | (1<<31); // descriptor ready to be txed
3523 #ifdef DEBUG_TX_DESC2
3524 printk("tx desc is:\n");
3525 DMESG("%8x %8x %8x %8x %8x %8x %8x %8x", tail[0], tail[1], tail[2], tail[3],
3526 tail[4], tail[5], tail[6], tail[7]);
3529 if((tail - begin)/8 == count-1)
3535 buflist=buflist->next;
3540 case MANAGE_PRIORITY:
3541 priv->txmapringtail=tail;
3542 priv->txmapbufstail=buflist;
3546 priv->txbkpringtail=tail;
3547 priv->txbkpbufstail=buflist;
3551 priv->txbepringtail=tail;
3552 priv->txbepbufstail=buflist;
3556 priv->txvipringtail=tail;
3557 priv->txvipbufstail=buflist;
3561 priv->txvopringtail=tail;
3562 priv->txvopbufstail=buflist;
3566 priv->txhpringtail=tail;
3567 priv->txhpbufstail = buflist;
3570 case BEACON_PRIORITY:
3571 /* the HW seems to be happy with the 1st
3572 * descriptor filled and the 2nd empty...
3573 * So always update descriptor 1 and never
3576 // priv->txbeaconringtail=tail;
3577 // priv->txbeaconbufstail=buflist;
3583 //rtl8180_dma_kick(dev,priority);
3585 *temp_tail = *temp_tail | (1<<31); // descriptor ready to be txed
3586 rtl8180_dma_kick(dev,priority);
3587 //spin_unlock_irqrestore(&priv->tx_lock,flags);
3594 void rtl8180_irq_rx_tasklet(struct r8180_priv * priv);
3597 void rtl8180_link_change(struct net_device *dev)
3599 struct r8180_priv *priv = ieee80211_priv(dev);
3600 u16 beacon_interval;
3602 struct ieee80211_network *net = &priv->ieee80211->current_network;
3603 // rtl8180_adapter_start(dev);
3604 rtl8180_update_msr(dev);
3607 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
3609 write_nic_dword(dev,BSSID,((u32*)net->bssid)[0]);
3610 write_nic_word(dev,BSSID+4,((u16*)net->bssid)[2]);
3613 beacon_interval = read_nic_dword(dev,BEACON_INTERVAL);
3614 beacon_interval &= ~ BEACON_INTERVAL_MASK;
3615 beacon_interval |= net->beacon_interval;
3616 write_nic_dword(dev, BEACON_INTERVAL, beacon_interval);
3618 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
3622 u16 atim = read_nic_dword(dev,ATIM);
3623 u16 = u16 &~ ATIM_MASK;
3624 u16 = u16 | beacon->atim;
3627 if (net->capability & WLAN_CAPABILITY_PRIVACY) {
3629 DMESG("Enabling hardware WEP support");
3630 rtl8180_set_hw_wep(dev);
3631 priv->ieee80211->host_encrypt=0;
3632 priv->ieee80211->host_decrypt=0;
3634 #ifndef CONFIG_IEEE80211_NOWEP
3636 priv->ieee80211->host_encrypt=1;
3637 priv->ieee80211->host_decrypt=1;
3641 #ifndef CONFIG_IEEE80211_NOWEP
3643 priv->ieee80211->host_encrypt=0;
3644 priv->ieee80211->host_decrypt=0;
3651 rtl8180_set_chan(dev, priv->chan);
3656 void rtl8180_rq_tx_ack(struct net_device *dev){
3658 struct r8180_priv *priv = ieee80211_priv(dev);
3659 // printk("====================>%s\n",__func__);
3660 write_nic_byte(dev,CONFIG4,read_nic_byte(dev,CONFIG4)|CONFIG4_PWRMGT);
3661 priv->ack_tx_to_ieee = 1;
3664 short rtl8180_is_tx_queue_empty(struct net_device *dev){
3666 struct r8180_priv *priv = ieee80211_priv(dev);
3669 for (d = priv->txmapring;
3670 d < priv->txmapring + priv->txringcount;d+=8)
3671 if(*d & (1<<31)) return 0;
3673 for (d = priv->txbkpring;
3674 d < priv->txbkpring + priv->txringcount;d+=8)
3675 if(*d & (1<<31)) return 0;
3677 for (d = priv->txbepring;
3678 d < priv->txbepring + priv->txringcount;d+=8)
3679 if(*d & (1<<31)) return 0;
3681 for (d = priv->txvipring;
3682 d < priv->txvipring + priv->txringcount;d+=8)
3683 if(*d & (1<<31)) return 0;
3685 for (d = priv->txvopring;
3686 d < priv->txvopring + priv->txringcount;d+=8)
3687 if(*d & (1<<31)) return 0;
3689 for (d = priv->txhpring;
3690 d < priv->txhpring + priv->txringcount;d+=8)
3691 if(*d & (1<<31)) return 0;
3694 /* FIXME FIXME 5msecs is random */
3695 #define HW_WAKE_DELAY 5
3697 void rtl8180_hw_wakeup(struct net_device *dev)
3699 unsigned long flags;
3701 struct r8180_priv *priv = ieee80211_priv(dev);
3703 spin_lock_irqsave(&priv->ps_lock,flags);
3704 //DMESG("Waken up!");
3705 write_nic_byte(dev,CONFIG4,read_nic_byte(dev,CONFIG4)&~CONFIG4_PWRMGT);
3708 priv->rf_wakeup(dev);
3709 // mdelay(HW_WAKE_DELAY);
3710 spin_unlock_irqrestore(&priv->ps_lock,flags);
3713 void rtl8180_hw_sleep_down(struct net_device *dev)
3715 unsigned long flags;
3717 struct r8180_priv *priv = ieee80211_priv(dev);
3719 spin_lock_irqsave(&priv->ps_lock,flags);
3723 priv->rf_sleep(dev);
3724 spin_unlock_irqrestore(&priv->ps_lock,flags);
3728 void rtl8180_hw_sleep(struct net_device *dev, u32 th, u32 tl)
3731 struct r8180_priv *priv = ieee80211_priv(dev);
3734 unsigned long flags;
3736 spin_lock_irqsave(&priv->ps_lock,flags);
3738 /* Writing HW register with 0 equals to disable
3739 * the timer, that is not really what we want
3741 tl -= MSECS(4+16+7);
3743 //if(tl == 0) tl = 1;
3745 /* FIXME HACK FIXME HACK */
3746 // force_pci_posting(dev);
3749 // rb = read_nic_dword(dev, TSFTR);
3751 /* If the interval in witch we are requested to sleep is too
3752 * short then give up and remain awake
3754 if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME))
3755 ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
3756 spin_unlock_irqrestore(&priv->ps_lock,flags);
3757 printk("too short to sleep\n");
3761 // write_nic_dword(dev, TimerInt, tl);
3762 // rb = read_nic_dword(dev, TSFTR);
3764 u32 tmp = (tl>rb)?(tl-rb):(rb-tl);
3768 priv->DozePeriodInPast2Sec += jiffies_to_msecs(tmp);
3770 queue_delayed_work(priv->ieee80211->wq, &priv->ieee80211->hw_wakeup_wq, tmp); //as tl may be less than rb
3772 /* if we suspect the TimerInt is gone beyond tl
3773 * while setting it, then give up
3776 if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))||
3777 ((tl < rb) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))) {
3778 spin_unlock_irqrestore(&priv->ps_lock,flags);
3782 // if(priv->rf_sleep)
3783 // priv->rf_sleep(dev);
3785 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_sleep_wq);
3786 spin_unlock_irqrestore(&priv->ps_lock,flags);
3790 //void rtl8180_wmm_param_update(struct net_device *dev,u8 *ac_param)
3791 #if LINUX_VERSION_CODE >=KERNEL_VERSION(2,6,20)
3792 void rtl8180_wmm_param_update(struct work_struct * work)
3794 struct ieee80211_device * ieee = container_of(work, struct ieee80211_device,wmm_param_update_wq);
3795 //struct r8180_priv *priv = (struct r8180_priv*)(ieee->priv);
3796 struct net_device *dev = ieee->dev;
3798 void rtl8180_wmm_param_update(struct ieee80211_device *ieee)
3800 struct net_device *dev = ieee->dev;
3801 struct r8180_priv *priv = ieee80211_priv(dev);
3803 u8 *ac_param = (u8 *)(ieee->current_network.wmm_param);
3804 u8 mode = ieee->current_network.mode;
3810 #ifndef CONFIG_RTL8185B
3811 //for legacy 8185 keep the PARAM unchange.
3814 if(!ieee->current_network.QoS_Enable){
3815 //legacy ac_xx_param update
3816 AcParam.longData = 0;
3817 AcParam.f.AciAifsn.f.AIFSN = 2; // Follow 802.11 DIFS.
3818 AcParam.f.AciAifsn.f.ACM = 0;
3819 AcParam.f.Ecw.f.ECWmin = 3; // Follow 802.11 CWmin.
3820 AcParam.f.Ecw.f.ECWmax = 7; // Follow 802.11 CWmax.
3821 AcParam.f.TXOPLimit = 0;
3822 for(eACI = 0; eACI < AC_MAX; eACI++){
3823 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
3827 pAcParam = (PAC_PARAM)(&AcParam);
3828 // Retrive paramters to udpate.
3829 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN *(((mode&IEEE_G) == IEEE_G)?9:20) + aSifsTime;
3830 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit))<<AC_PARAM_TXOP_LIMIT_OFFSET)|
3831 (((u32)(pAcParam->f.Ecw.f.ECWmax))<<AC_PARAM_ECW_MAX_OFFSET)|
3832 (((u32)(pAcParam->f.Ecw.f.ECWmin))<<AC_PARAM_ECW_MIN_OFFSET)|
3833 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
3836 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
3840 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
3844 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
3848 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
3852 printk(KERN_WARNING "SetHwReg8185():invalid ACI: %d!\n", eACI);
3860 for(i = 0; i < AC_MAX; i++){
3861 //AcParam.longData = 0;
3862 pAcParam = (AC_PARAM * )ac_param;
3868 // Retrive paramters to udpate.
3869 eACI = pAcParam->f.AciAifsn.f.ACI;
3870 //Mode G/A: slotTimeTimer = 9; Mode B: 20
3871 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G)?9:20) + aSifsTime;
3872 u4bAcParam = ( (((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
3873 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
3874 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
3875 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
3879 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
3883 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
3887 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
3891 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
3895 printk(KERN_WARNING "SetHwReg8185(): invalid ACI: %d !\n", eACI);
3899 ac_param += (sizeof(AC_PARAM));
3904 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3905 void rtl8180_tx_irq_wq(struct work_struct *work);
3907 void rtl8180_tx_irq_wq(struct net_device *dev);
3913 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3914 void rtl8180_restart_wq(struct work_struct *work);
3915 //void rtl8180_rq_tx_ack(struct work_struct *work);
3917 void rtl8180_restart_wq(struct net_device *dev);
3918 //void rtl8180_rq_tx_ack(struct net_device *dev);
3920 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3921 void rtl8180_watch_dog_wq(struct work_struct *work);
3923 void rtl8180_watch_dog_wq(struct net_device *dev);
3925 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3926 void rtl8180_hw_wakeup_wq(struct work_struct *work);
3928 void rtl8180_hw_wakeup_wq(struct net_device *dev);
3931 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3932 void rtl8180_hw_sleep_wq(struct work_struct *work);
3934 void rtl8180_hw_sleep_wq(struct net_device *dev);
3939 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3940 void rtl8180_sw_antenna_wq(struct work_struct *work);
3942 void rtl8180_sw_antenna_wq(struct net_device *dev);
3944 void rtl8180_watch_dog(struct net_device *dev);
3945 void watch_dog_adaptive(unsigned long data)
3947 struct r8180_priv* priv = ieee80211_priv((struct net_device *)data);
3948 // DMESG("---->watch_dog_adaptive()\n");
3951 DMESG("<----watch_dog_adaptive():driver is not up!\n");
3955 // queue_work(priv->ieee80211->wq,&priv->ieee80211->watch_dog_wq);
3958 // Tx High Power Mechanism.
3960 if(CheckHighPower((struct net_device *)data))
3962 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->tx_pw_wq);
3966 #ifdef CONFIG_RTL818X_S
3967 // Tx Power Tracking on 87SE.
3969 //if( priv->bTxPowerTrack ) //lzm mod 080826
3970 if( CheckTxPwrTracking((struct net_device *)data));
3971 TxPwrTracking87SE((struct net_device *)data);
3975 // Perform DIG immediately.
3977 if(CheckDig((struct net_device *)data) == true)
3979 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_dig_wq);
3984 rtl8180_watch_dog((struct net_device *)data);
3987 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->GPIOChangeRFWorkItem);
3989 priv->watch_dog_timer.expires = jiffies + MSECS(IEEE80211_WATCH_DOG_TIME);
3990 add_timer(&priv->watch_dog_timer);
3991 // DMESG("<----watch_dog_adaptive()\n");
3994 #ifdef ENABLE_DOT11D
3996 static CHANNEL_LIST ChannelPlan[] = {
3997 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64},19}, //FCC
3998 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
3999 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
4000 {{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.
4001 {{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.
4002 {{14,36,40,44,48,52,56,60,64},9}, //MKK
4003 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14, 36,40,44,48,52,56,60,64},22},//MKK1
4004 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //Israel.
4005 {{1,2,3,4,5,6,7,8,9,10,11,12,13,34,38,42,46},17}, // For 11a , TELEC
4006 {{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
4007 {{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
4010 static void rtl8180_set_channel_map(u8 channel_plan, struct ieee80211_device *ieee)
4015 ieee->MinPassiveChnlNum=MAX_CHANNEL_NUMBER+1;
4016 ieee->IbssStartChnl=0;
4018 switch (channel_plan)
4020 case COUNTRY_CODE_FCC:
4021 case COUNTRY_CODE_IC:
4022 case COUNTRY_CODE_ETSI:
4023 case COUNTRY_CODE_SPAIN:
4024 case COUNTRY_CODE_FRANCE:
4025 case COUNTRY_CODE_MKK:
4026 case COUNTRY_CODE_MKK1:
4027 case COUNTRY_CODE_ISRAEL:
4028 case COUNTRY_CODE_TELEC:
4031 ieee->bGlobalDomain = false;
4032 if (ChannelPlan[channel_plan].Len != 0){
4033 // Clear old channel map
4034 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
4035 // Set new channel map
4036 for (i=0;i<ChannelPlan[channel_plan].Len;i++)
4038 if(ChannelPlan[channel_plan].Channel[i] <= 14)
4039 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
4044 case COUNTRY_CODE_GLOBAL_DOMAIN:
4046 GET_DOT11D_INFO(ieee)->bEnabled = 0;
4048 ieee->bGlobalDomain = true;
4051 case COUNTRY_CODE_WORLD_WIDE_13_INDEX://lzm add 080826
4053 ieee->MinPassiveChnlNum=12;
4054 ieee->IbssStartChnl= 10;
4060 ieee->bGlobalDomain = false;
4061 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
4064 GET_DOT11D_INFO(ieee)->channel_map[i] = 1;
4072 //Add for RF power on power off by lizhaoming 080512
4073 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
4074 void GPIOChangeRFWorkItemCallBack(struct work_struct *work);
4076 void GPIOChangeRFWorkItemCallBack(struct ieee80211_device *ieee);
4080 static void rtl8180_statistics_init(struct Stats *pstats)
4082 memset(pstats, 0, sizeof(struct Stats));
4084 static void rtl8180_link_detect_init(plink_detect_t plink_detect)
4086 memset(plink_detect, 0, sizeof(link_detect_t));
4087 plink_detect->SlotNum = DEFAULT_SLOT_NUM;
4091 short rtl8180_init(struct net_device *dev)
4093 struct r8180_priv *priv = ieee80211_priv(dev);
4102 #ifdef ENABLE_DOT11D
4104 for(i=0;i<0xFF;i++) {
4106 printk("\n[%x]: ", i/16);
4107 printk("\t%4.4x", eprom_read(dev,i));
4110 priv->channel_plan = eprom_read(dev, EEPROM_COUNTRY_CODE>>1) & 0xFF;
4111 if(priv->channel_plan > COUNTRY_CODE_GLOBAL_DOMAIN){
4112 printk("rtl8180_init:Error channel plan! Set to default.\n");
4113 priv->channel_plan = 0;
4115 //priv->channel_plan = 9; //Global Domain
4117 DMESG("Channel plan is %d\n",priv->channel_plan);
4118 rtl8180_set_channel_map(priv->channel_plan, priv->ieee80211);
4121 //Set Default Channel Plan
4123 DMESG("No channels, aborting");
4127 priv->channel_plan = 0;//hikaru
4128 // set channels 1..14 allowed in given locale
4129 for (i=1; i<=14; i++) {
4130 (priv->ieee80211->channel_map)[i] = (u8)(ch & 0x01);
4135 //memcpy(priv->stats,0,sizeof(struct Stats));
4137 //FIXME: these constants are placed in a bad pleace.
4138 priv->txbuffsize = 2048;//1024;
4139 priv->txringcount = 32;//32;
4140 priv->rxbuffersize = 2048;//1024;
4141 priv->rxringcount = 64;//32;
4142 priv->txbeaconcount = 2;
4143 priv->rx_skb_complete = 1;
4144 //priv->txnp_pending.ispending=0;
4145 /* ^^ the SKB does not containt a partial RXed
4149 #ifdef CONFIG_RTL8185B
4150 #ifdef CONFIG_RTL818X_S
4151 priv->RegThreeWireMode = HW_THREE_WIRE_SI;
4153 priv->RegThreeWireMode = SW_THREE_WIRE;
4157 //Add for RF power on power off by lizhaoming 080512
4158 priv->RFChangeInProgress = false;
4159 priv->SetRFPowerStateInProgress = false;
4160 priv->RFProgType = 0;
4161 priv->bInHctTest = false;
4163 priv->irq_enabled=0;
4165 //YJ,modified,080828
4167 priv->stats.rxdmafail=0;
4168 priv->stats.txrdu=0;
4169 priv->stats.rxrdu=0;
4170 priv->stats.rxnolast=0;
4171 priv->stats.rxnodata=0;
4172 //priv->stats.rxreset=0;
4173 //priv->stats.rxwrkaround=0;
4174 priv->stats.rxnopointer=0;
4175 priv->stats.txnperr=0;
4176 priv->stats.txresumed=0;
4177 priv->stats.rxerr=0;
4178 priv->stats.rxoverflow=0;
4179 priv->stats.rxint=0;
4180 priv->stats.txnpokint=0;
4181 priv->stats.txhpokint=0;
4182 priv->stats.txhperr=0;
4184 priv->stats.shints=0;
4185 priv->stats.txoverflow=0;
4186 priv->stats.txbeacon=0;
4187 priv->stats.txbeaconerr=0;
4188 priv->stats.txlperr=0;
4189 priv->stats.txlpokint=0;
4190 priv->stats.txretry=0;//tony 20060601
4191 priv->stats.rxcrcerrmin=0;
4192 priv->stats.rxcrcerrmid=0;
4193 priv->stats.rxcrcerrmax=0;
4194 priv->stats.rxicverr=0;
4196 rtl8180_statistics_init(&priv->stats);
4197 rtl8180_link_detect_init(&priv->link_detect);
4199 //YJ,modified,080828,end
4202 priv->ack_tx_to_ieee = 0;
4203 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
4204 priv->ieee80211->iw_mode = IW_MODE_INFRA;
4205 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
4206 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
4207 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;
4208 priv->ieee80211->active_scan = 1;
4209 priv->ieee80211->rate = 110; //11 mbps
4210 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION;
4211 priv->ieee80211->host_encrypt = 1;
4212 priv->ieee80211->host_decrypt = 1;
4213 priv->ieee80211->sta_wake_up = rtl8180_hw_wakeup;
4214 priv->ieee80211->ps_request_tx_ack = rtl8180_rq_tx_ack;
4215 priv->ieee80211->enter_sleep_state = rtl8180_hw_sleep;
4216 priv->ieee80211->ps_is_queue_empty = rtl8180_is_tx_queue_empty;
4218 priv->hw_wep = hwwep;
4221 priv->retry_rts = DEFAULT_RETRY_RTS;
4222 priv->retry_data = DEFAULT_RETRY_DATA;
4223 priv->RFChangeInProgress = false;
4224 priv->SetRFPowerStateInProgress = false;
4225 priv->RFProgType = 0;
4226 priv->bInHctTest = false;
4227 priv->bInactivePs = true;//false;
4228 priv->ieee80211->bInactivePs = priv->bInactivePs;
4229 priv->bSwRfProcessing = false;
4230 priv->eRFPowerState = eRfOff;
4231 priv->RfOffReason = 0;
4232 priv->LedStrategy = SW_LED_MODE0;
4233 //priv->NumRxOkInPeriod = 0; //YJ,del,080828
4234 //priv->NumTxOkInPeriod = 0; //YJ,del,080828
4235 priv->TxPollingTimes = 0;//lzm add 080826
4236 priv->bLeisurePs = true;
4237 priv->dot11PowerSaveMode = eActive;
4238 //by amy for antenna
4239 priv->AdMinCheckPeriod = 5;
4240 priv->AdMaxCheckPeriod = 10;
4241 // Lower signal strength threshold to fit the HW participation in antenna diversity. +by amy 080312
4242 priv->AdMaxRxSsThreshold = 30;//60->30
4243 priv->AdRxSsThreshold = 20;//50->20
4244 priv->AdCheckPeriod = priv->AdMinCheckPeriod;
4245 priv->AdTickCount = 0;
4246 priv->AdRxSignalStrength = -1;
4247 priv->RegSwAntennaDiversityMechanism = 0;
4248 priv->RegDefaultAntenna = 0;
4249 priv->SignalStrength = 0;
4250 priv->AdRxOkCnt = 0;
4251 priv->CurrAntennaIndex = 0;
4252 priv->AdRxSsBeforeSwitched = 0;
4253 init_timer(&priv->SwAntennaDiversityTimer);
4254 priv->SwAntennaDiversityTimer.data = (unsigned long)dev;
4255 priv->SwAntennaDiversityTimer.function = (void *)SwAntennaDiversityTimerCallback;
4256 //by amy for antenna
4258 priv->bDigMechanism = 1;
4259 priv->InitialGain = 6;
4260 priv->bXtalCalibration = false;
4261 priv->XtalCal_Xin = 0;
4262 priv->XtalCal_Xout = 0;
4263 priv->bTxPowerTrack = false;
4264 priv->ThermalMeter = 0;
4265 priv->FalseAlarmRegValue = 0;
4266 priv->RegDigOfdmFaUpTh = 0xc; // Upper threhold of OFDM false alarm, which is used in DIG.
4267 priv->DIG_NumberFallbackVote = 0;
4268 priv->DIG_NumberUpgradeVote = 0;
4269 priv->LastSignalStrengthInPercent = 0;
4270 priv->Stats_SignalStrength = 0;
4271 priv->LastRxPktAntenna = 0;
4272 priv->SignalQuality = 0; // in 0-100 index.
4273 priv->Stats_SignalQuality = 0;
4274 priv->RecvSignalPower = 0; // in dBm.
4275 priv->Stats_RecvSignalPower = 0;
4276 priv->AdMainAntennaRxOkCnt = 0;
4277 priv->AdAuxAntennaRxOkCnt = 0;
4278 priv->bHWAdSwitched = false;
4279 priv->bRegHighPowerMechanism = true;
4280 priv->RegHiPwrUpperTh = 77;
4281 priv->RegHiPwrLowerTh = 75;
4282 priv->RegRSSIHiPwrUpperTh = 70;
4283 priv->RegRSSIHiPwrLowerTh = 20;
4284 priv->bCurCCKPkt = false;
4285 priv->UndecoratedSmoothedSS = -1;
4286 priv->bToUpdateTxPwr = false;
4287 priv->CurCCKRSSI = 0;
4291 priv->NumTxOkTotal = 0;
4292 priv->NumTxUnicast = 0;
4293 priv->keepAliveLevel = DEFAULT_KEEP_ALIVE_LEVEL;
4294 priv->PowerProfile = POWER_PROFILE_AC;
4296 //by amy for rate adaptive
4297 priv->CurrRetryCnt=0;
4298 priv->LastRetryCnt=0;
4299 priv->LastTxokCnt=0;
4300 priv->LastRxokCnt=0;
4301 priv->LastRetryRate=0;
4304 priv->CurrRetryRate=0;
4305 priv->TryupingCount=0;
4306 priv->TryupingCountNoData=0;
4307 priv->TryDownCountLowData=0;
4308 priv->LastTxOKBytes=0;
4309 priv->LastFailTxRate=0;
4310 priv->LastFailTxRateSS=0;
4311 priv->FailTxRateCount=0;
4312 priv->LastTxThroughput=0;
4313 priv->NumTxOkBytesTotal=0;
4314 priv->ForcedDataRate = 0;
4315 priv->RegBModeGainStage = 1;
4317 //by amy for rate adaptive
4319 priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
4320 spin_lock_init(&priv->irq_lock);
4321 spin_lock_init(&priv->irq_th_lock);
4322 spin_lock_init(&priv->tx_lock);
4323 spin_lock_init(&priv->ps_lock);
4324 spin_lock_init(&priv->rf_ps_lock);
4325 sema_init(&priv->wx_sem,1);
4326 sema_init(&priv->rf_state,1);
4327 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
4328 INIT_WORK(&priv->reset_wq,(void*) rtl8180_restart_wq);
4329 INIT_WORK(&priv->tx_irq_wq,(void*) rtl8180_tx_irq_wq);
4330 INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8180_hw_wakeup_wq);
4331 INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8180_hw_sleep_wq);
4332 //INIT_DELAYED_WORK(&priv->ieee80211->watch_dog_wq,(void*) rtl8180_watch_dog_wq);
4333 //INIT_DELAYED_WORK(&priv->ieee80211->sw_antenna_wq,(void*) rtl8180_sw_antenna_wq);
4334 INIT_WORK(&priv->ieee80211->wmm_param_update_wq,(void*) rtl8180_wmm_param_update);
4335 INIT_DELAYED_WORK(&priv->ieee80211->rate_adapter_wq,(void*)rtl8180_rate_adapter);//+by amy 080312
4336 INIT_DELAYED_WORK(&priv->ieee80211->hw_dig_wq,(void*)rtl8180_hw_dig_wq);//+by amy 080312
4337 INIT_DELAYED_WORK(&priv->ieee80211->tx_pw_wq,(void*)rtl8180_tx_pw_wq);//+by amy 080312
4339 //add for RF power on power off by lizhaoming 080512
4340 INIT_DELAYED_WORK(&priv->ieee80211->GPIOChangeRFWorkItem,(void*) GPIOChangeRFWorkItemCallBack);
4342 INIT_WORK(&priv->reset_wq,(void*) rtl8180_restart_wq,dev);
4343 INIT_WORK(&priv->tx_irq_wq,(void*) rtl8180_tx_irq_wq,dev);
4344 //INIT_WORK(&priv->ieee80211->watch_dog_wq,(void*) rtl8180_watch_dog_wq,dev);
4345 INIT_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8180_hw_wakeup_wq,dev);
4346 INIT_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8180_hw_sleep_wq,dev);
4347 //INIT_WORK(&priv->ieee80211->sw_antenna_wq,(void*) rtl8180_sw_antenna_wq,dev);
4348 INIT_WORK(&priv->ieee80211->wmm_param_update_wq,(void*) rtl8180_wmm_param_update,priv->ieee80211);
4349 INIT_WORK(&priv->ieee80211->rate_adapter_wq,(void*)rtl8180_rate_adapter,dev);//+by amy 080312
4350 INIT_WORK(&priv->ieee80211->hw_dig_wq,(void*)rtl8180_hw_dig_wq,dev);//+by amy 080312
4351 INIT_WORK(&priv->ieee80211->tx_pw_wq,(void*)rtl8180_tx_pw_wq,dev);//+by amy 080312
4353 //add for RF power on power off by lizhaoming 080512
4354 INIT_WORK(&priv->ieee80211->GPIOChangeRFWorkItem,(void*) GPIOChangeRFWorkItemCallBack, priv->ieee80211);
4356 //INIT_WORK(&priv->reset_wq,(void*) rtl8180_restart_wq,dev);
4358 tasklet_init(&priv->irq_rx_tasklet,
4359 (void(*)(unsigned long)) rtl8180_irq_rx_tasklet,
4360 (unsigned long)priv);
4362 init_timer(&priv->watch_dog_timer);
4363 priv->watch_dog_timer.data = (unsigned long)dev;
4364 priv->watch_dog_timer.function = watch_dog_adaptive;
4368 //by amy for rate adaptive
4369 init_timer(&priv->rateadapter_timer);
4370 priv->rateadapter_timer.data = (unsigned long)dev;
4371 priv->rateadapter_timer.function = timer_rate_adaptive;
4372 priv->RateAdaptivePeriod= RATE_ADAPTIVE_TIMER_PERIOD;
4373 priv->bEnhanceTxPwr=false;
4374 //by amy for rate adaptive
4376 //priv->ieee80211->func =
4377 // kmalloc(sizeof(struct ieee80211_helper_functions),GFP_KERNEL);
4378 //memset(priv->ieee80211->func, 0,
4379 // sizeof(struct ieee80211_helper_functions));
4381 priv->ieee80211->softmac_hard_start_xmit = rtl8180_hard_start_xmit;
4382 priv->ieee80211->set_chan = rtl8180_set_chan;
4383 priv->ieee80211->link_change = rtl8180_link_change;
4384 priv->ieee80211->softmac_data_hard_start_xmit = rtl8180_hard_data_xmit;
4385 priv->ieee80211->data_hard_stop = rtl8180_data_hard_stop;
4386 priv->ieee80211->data_hard_resume = rtl8180_data_hard_resume;
4388 priv->ieee80211->init_wmmparam_flag = 0;
4390 priv->ieee80211->start_send_beacons = rtl8180_start_tx_beacon;
4391 priv->ieee80211->stop_send_beacons = rtl8180_beacon_tx_disable;
4392 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
4394 #ifdef CONFIG_RTL8185B
4395 priv->MWIEnable = 0;
4397 priv->ShortRetryLimit = 7;
4398 priv->LongRetryLimit = 7;
4399 priv->EarlyRxThreshold = 7;
4401 priv->CSMethod = (0x01 << 29);
4403 priv->TransmitConfig =
4404 1<<TCR_DurProcMode_OFFSET | //for RTL8185B, duration setting by HW
4405 (7<<TCR_MXDMA_OFFSET) | // Max DMA Burst Size per Tx DMA Burst, 7: reservied.
4406 (priv->ShortRetryLimit<<TCR_SRL_OFFSET) | // Short retry limit
4407 (priv->LongRetryLimit<<TCR_LRL_OFFSET) | // Long retry limit
4408 (0 ? TCR_SAT : 0); // FALSE: HW provies PLCP length and LENGEXT, TURE: SW proiveds them
4410 priv->ReceiveConfig =
4411 #ifdef CONFIG_RTL818X_S
4416 RCR_AMF | RCR_ADF | //accept management/data
4417 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
4418 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
4419 //RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet
4420 (7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
4421 (priv->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold.
4422 (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT:0);
4424 priv->IntrMask = IMR_TMGDOK | IMR_TBDER | IMR_THPDER |
4425 IMR_THPDER | IMR_THPDOK |
4426 IMR_TVODER | IMR_TVODOK |
4427 IMR_TVIDER | IMR_TVIDOK |
4428 IMR_TBEDER | IMR_TBEDOK |
4429 IMR_TBKDER | IMR_TBKDOK |
4430 IMR_RDU | // To handle the defragmentation not enough Rx descriptors case. Annie, 2006-03-27.
4432 IMR_RQoSOK; // <NOTE> ROK and RQoSOK are mutually exclusive, so, we must handle RQoSOK interrupt to receive QoS frames, 2005.12.09, by rcnjko.
4434 priv->InitialGain = 6;
4437 hw_version =( read_nic_dword(dev, TCR) & TCR_HWVERID_MASK)>>TCR_HWVERID_SHIFT;
4439 switch (hw_version){
4440 #ifdef CONFIG_RTL8185B
4441 case HW_VERID_R8185B_B:
4442 #ifdef CONFIG_RTL818X_S
4443 priv->card_8185 = VERSION_8187S_C;
4444 DMESG("MAC controller is a RTL8187SE b/g");
4448 DMESG("MAC controller is a RTL8185B b/g");
4449 priv->card_8185 = 3;
4454 case HW_VERID_R8185_ABC:
4455 DMESG("MAC controller is a RTL8185 b/g");
4456 priv->card_8185 = 1;
4457 /* you should not find a card with 8225 PHY ver < C*/
4461 case HW_VERID_R8185_D:
4462 DMESG("MAC controller is a RTL8185 b/g (V. D)");
4463 priv->card_8185 = 2;
4464 /* you should not find a card with 8225 PHY ver < C*/
4468 case HW_VERID_R8180_ABCD:
4469 DMESG("MAC controller is a RTL8180");
4470 priv->card_8185 = 0;
4473 case HW_VERID_R8180_F:
4474 DMESG("MAC controller is a RTL8180 (v. F)");
4475 priv->card_8185 = 0;
4479 DMESGW("MAC chip not recognized: version %x. Assuming RTL8180",hw_version);
4480 priv->card_8185 = 0;
4484 if(priv->card_8185){
4485 priv->ieee80211->modulation |= IEEE80211_OFDM_MODULATION;
4486 priv->ieee80211->short_slot = 1;
4488 /* you should not found any 8185 Ver B Card */
4489 priv->card_8185_Bversion = 0;
4491 #ifdef CONFIG_RTL8185B
4492 #ifdef CONFIG_RTL818X_S
4494 priv->card_type = PCI;
4495 DMESG("This is a PCI NIC");
4497 config3 = read_nic_byte(dev, CONFIG3);
4499 priv->card_type = CARDBUS;
4500 DMESG("This is a CARDBUS NIC");
4502 else if( config3 & 0x4){
4503 priv->card_type = MINIPCI;
4504 DMESG("This is a MINI-PCI NIC");
4506 priv->card_type = PCI;
4507 DMESG("This is a PCI NIC");
4511 priv->enable_gpio0 = 0;
4513 //by amy for antenna
4514 #ifdef CONFIG_RTL8185B
4515 usValue = eprom_read(dev, EEPROM_SW_REVD_OFFSET);
4516 DMESG("usValue is 0x%x\n",usValue);
4517 #ifdef CONFIG_RTL818X_S
4518 //3Read AntennaDiversity
4519 // SW Antenna Diversity.
4520 if( (usValue & EEPROM_SW_AD_MASK) != EEPROM_SW_AD_ENABLE )
4522 priv->EEPROMSwAntennaDiversity = false;
4523 //printk("EEPROM Disable SW Antenna Diversity\n");
4527 priv->EEPROMSwAntennaDiversity = true;
4528 //printk("EEPROM Enable SW Antenna Diversity\n");
4530 // Default Antenna to use.
4531 if( (usValue & EEPROM_DEF_ANT_MASK) != EEPROM_DEF_ANT_1 )
4533 priv->EEPROMDefaultAntenna1 = false;
4534 //printk("EEPROM Default Antenna 0\n");
4538 priv->EEPROMDefaultAntenna1 = true;
4539 //printk("EEPROM Default Antenna 1\n");
4543 // Antenna diversity mechanism. Added by Roger, 2007.11.05.
4545 if( priv->RegSwAntennaDiversityMechanism == 0 ) // Auto
4546 {// 0: default from EEPROM.
4547 priv->bSwAntennaDiverity = priv->EEPROMSwAntennaDiversity;
4550 {// 1:disable antenna diversity, 2: enable antenna diversity.
4551 priv->bSwAntennaDiverity = ((priv->RegSwAntennaDiversityMechanism == 1)? false : true);
4553 //printk("bSwAntennaDiverity = %d\n", priv->bSwAntennaDiverity);
4557 // Default antenna settings. Added by Roger, 2007.11.05.
4559 if( priv->RegDefaultAntenna == 0)
4560 {// 0: default from EEPROM.
4561 priv->bDefaultAntenna1 = priv->EEPROMDefaultAntenna1;
4564 {// 1: main, 2: aux.
4565 priv->bDefaultAntenna1 = ((priv->RegDefaultAntenna== 2) ? true : false);
4567 //printk("bDefaultAntenna1 = %d\n", priv->bDefaultAntenna1);
4570 //by amy for antenna
4571 /* rtl8185 can calc plcp len in HW.*/
4572 priv->hw_plcp_len = 1;
4574 priv->plcp_preamble_mode = 2;
4575 /*the eeprom type is stored in RCR register bit #6 */
4576 if (RCR_9356SEL & read_nic_dword(dev, RCR)){
4577 priv->epromtype=EPROM_93c56;
4578 //DMESG("Reported EEPROM chip is a 93c56 (2Kbit)");
4580 priv->epromtype=EPROM_93c46;
4581 //DMESG("Reported EEPROM chip is a 93c46 (1Kbit)");
4584 dev->get_stats = rtl8180_stats;
4586 dev->dev_addr[0]=eprom_read(dev,MAC_ADR) & 0xff;
4587 dev->dev_addr[1]=(eprom_read(dev,MAC_ADR) & 0xff00)>>8;
4588 dev->dev_addr[2]=eprom_read(dev,MAC_ADR+1) & 0xff;
4589 dev->dev_addr[3]=(eprom_read(dev,MAC_ADR+1) & 0xff00)>>8;
4590 dev->dev_addr[4]=eprom_read(dev,MAC_ADR+2) & 0xff;
4591 dev->dev_addr[5]=(eprom_read(dev,MAC_ADR+2) & 0xff00)>>8;
4592 //DMESG("Card MAC address is "MAC_FMT, MAC_ARG(dev->dev_addr));
4595 for(i=1,j=0; i<14; i+=2,j++){
4597 word = eprom_read(dev,EPROM_TXPW_CH1_2 + j);
4598 priv->chtxpwr[i]=word & 0xff;
4599 priv->chtxpwr[i+1]=(word & 0xff00)>>8;
4601 DMESG("tx word %x:%x",j,word);
4602 DMESG("ch %d pwr %x",i,priv->chtxpwr[i]);
4603 DMESG("ch %d pwr %x",i+1,priv->chtxpwr[i+1]);
4606 if(priv->card_8185){
4607 for(i=1,j=0; i<14; i+=2,j++){
4609 word = eprom_read(dev,EPROM_TXPW_OFDM_CH1_2 + j);
4610 priv->chtxpwr_ofdm[i]=word & 0xff;
4611 priv->chtxpwr_ofdm[i+1]=(word & 0xff00)>>8;
4613 DMESG("ofdm tx word %x:%x",j,word);
4614 DMESG("ofdm ch %d pwr %x",i,priv->chtxpwr_ofdm[i]);
4615 DMESG("ofdm ch %d pwr %x",i+1,priv->chtxpwr_ofdm[i+1]);
4620 //3Read crystal calibtration and thermal meter indication on 87SE.
4622 // By SD3 SY's request. Added by Roger, 2007.12.11.
4624 tmpu16 = eprom_read(dev, EEPROM_RSV>>1);
4626 //printk("ReadAdapterInfo8185(): EEPROM_RSV(%04x)\n", tmpu16);
4628 // Crystal calibration for Xin and Xout resp.
4629 priv->XtalCal_Xout = tmpu16 & EEPROM_XTAL_CAL_XOUT_MASK; // 0~7.5pF
4630 priv->XtalCal_Xin = (tmpu16 & EEPROM_XTAL_CAL_XIN_MASK)>>4; // 0~7.5pF
4631 if((tmpu16 & EEPROM_XTAL_CAL_ENABLE)>>12)
4632 priv->bXtalCalibration = true;
4634 // Thermal meter reference indication.
4635 priv->ThermalMeter = (u8)((tmpu16 & EEPROM_THERMAL_METER_MASK)>>8);
4636 if((tmpu16 & EEPROM_THERMAL_METER_ENABLE)>>13)
4637 priv->bTxPowerTrack = true;
4640 #ifdef CONFIG_RTL8185B
4641 word = eprom_read(dev,EPROM_TXPW_BASE);
4642 priv->cck_txpwr_base = word & 0xf;
4643 priv->ofdm_txpwr_base = (word>>4) & 0xf;
4646 version = eprom_read(dev,EPROM_VERSION);
4647 DMESG("EEPROM version %x",version);
4648 if( (!priv->card_8185) && version < 0x0101){
4649 DMESG ("EEPROM version too old, assuming defaults");
4650 DMESG ("If you see this message *plase* send your \
4651 DMESG output to andreamrl@tiscali.it THANKS");
4655 priv->cs_treshold=0xc;
4657 priv->rf_chip=RFCHIPID_PHILIPS;
4659 if(!priv->card_8185){
4660 u8 rfparam = eprom_read(dev,RF_PARAM);
4661 DMESG("RfParam: %x",rfparam);
4663 priv->digphy = rfparam & (1<<RF_PARAM_DIGPHY_SHIFT) ? 0:1;
4664 priv->antb = rfparam & (1<<RF_PARAM_ANTBDEFAULT_SHIFT) ? 1:0;
4666 priv->rcr_csense = (rfparam & RF_PARAM_CARRIERSENSE_MASK) >>
4667 RF_PARAM_CARRIERSENSE_SHIFT;
4670 (read_nic_byte(dev,CONFIG2)&(1<<CONFIG2_ANTENNA_SHIFT)) ? 1:0;
4672 priv->rcr_csense = 3;
4675 priv->cs_treshold = (eprom_read(dev,ENERGY_TRESHOLD)&0xff00) >>8;
4677 priv->rf_chip = 0xff & eprom_read(dev,RFCHIPID);
4680 #ifdef CONFIG_RTL8185B
4681 #ifdef CONFIG_RTL818X_S
4682 priv->rf_chip = RF_ZEBRA4;
4683 priv->rf_sleep = rtl8225z4_rf_sleep;
4684 priv->rf_wakeup = rtl8225z4_rf_wakeup;
4686 priv->rf_chip = RF_ZEBRA2;
4688 //DMESG("Card reports RF frontend Realtek 8225z2");
4689 //DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4690 //DMESGW("use it with care and at your own risk and");
4691 DMESGW("**PLEASE** REPORT SUCCESSFUL/UNSUCCESSFUL TO Realtek!");
4693 priv->rf_close = rtl8225z2_rf_close;
4694 priv->rf_init = rtl8225z2_rf_init;
4695 priv->rf_set_chan = rtl8225z2_rf_set_chan;
4696 priv->rf_set_sens = NULL;
4697 //priv->rf_sleep = rtl8225_rf_sleep;
4698 //priv->rf_wakeup = rtl8225_rf_wakeup;
4701 /* check RF frontend chipset */
4702 switch (priv->rf_chip) {
4704 case RFCHIPID_RTL8225:
4706 if(priv->card_8185){
4707 DMESG("Card reports RF frontend Realtek 8225");
4708 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4709 DMESGW("use it with care and at your own risk and");
4710 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4712 priv->rf_close = rtl8225_rf_close;
4713 priv->rf_init = rtl8225_rf_init;
4714 priv->rf_set_chan = rtl8225_rf_set_chan;
4715 priv->rf_set_sens = NULL;
4716 priv->rf_sleep = rtl8225_rf_sleep;
4717 priv->rf_wakeup = rtl8225_rf_wakeup;
4720 DMESGW("Detected RTL8225 radio on a card recognized as RTL8180");
4721 DMESGW("This could not be... something went wrong....");
4726 case RFCHIPID_RTL8255:
4727 if(priv->card_8185){
4728 DMESG("Card reports RF frontend Realtek 8255");
4729 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4730 DMESGW("use it with care and at your own risk and");
4731 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4733 priv->rf_close = rtl8255_rf_close;
4734 priv->rf_init = rtl8255_rf_init;
4735 priv->rf_set_chan = rtl8255_rf_set_chan;
4736 priv->rf_set_sens = NULL;
4737 priv->rf_sleep = NULL;
4738 priv->rf_wakeup = NULL;
4741 DMESGW("Detected RTL8255 radio on a card recognized as RTL8180");
4742 DMESGW("This could not be... something went wrong....");
4748 case RFCHIPID_INTERSIL:
4749 DMESGW("Card reports RF frontend by Intersil.");
4750 DMESGW("This driver has NO support for this chipset.");
4755 DMESGW("Card reports RF frontend by RFMD.");
4756 DMESGW("This driver has NO support for this chipset.");
4761 DMESGW("Card reports RF frontend by GCT.");
4762 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4763 DMESGW("use it with care and at your own risk and");
4764 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4765 priv->rf_close = gct_rf_close;
4766 priv->rf_init = gct_rf_init;
4767 priv->rf_set_chan = gct_rf_set_chan;
4768 priv->rf_set_sens = NULL;
4769 priv->rf_sleep = NULL;
4770 priv->rf_wakeup = NULL;
4773 case RFCHIPID_MAXIM:
4774 DMESGW("Card reports RF frontend by MAXIM.");
4775 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4776 DMESGW("use it with care and at your own risk and");
4777 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4778 priv->rf_close = maxim_rf_close;
4779 priv->rf_init = maxim_rf_init;
4780 priv->rf_set_chan = maxim_rf_set_chan;
4781 priv->rf_set_sens = NULL;
4782 priv->rf_sleep = NULL;
4783 priv->rf_wakeup = NULL;
4786 case RFCHIPID_PHILIPS:
4787 DMESG("Card reports RF frontend by Philips.");
4788 DMESG("OK! Philips SA2400 radio chipset is supported.");
4789 priv->rf_close = sa2400_rf_close;
4790 priv->rf_init = sa2400_rf_init;
4791 priv->rf_set_chan = sa2400_rf_set_chan;
4792 priv->rf_set_sens = sa2400_rf_set_sens;
4793 priv->sens = SA2400_RF_DEF_SENS; /* default sensitivity */
4794 priv->max_sens = SA2400_RF_MAX_SENS; /* maximum sensitivity */
4795 priv->rf_sleep = NULL;
4796 priv->rf_wakeup = NULL;
4799 DMESGW("Digital PHY found");
4800 DMESGW("Philips DIGITAL PHY is untested! *Please*\
4801 report success/failure to <andreamrl@tiscali.it>");
4803 DMESG ("Analog PHY found");
4809 DMESGW("Unknown RF module %x",priv->rf_chip);
4810 DMESGW("Exiting...");
4817 if(!priv->card_8185){
4819 DMESG ("Antenna B is default antenna");
4821 DMESG ("Antenna A is default antenna");
4824 DMESG ("Antenna diversity is enabled");
4826 DMESG("Antenna diversity is disabled");
4828 DMESG("Carrier sense %d",priv->rcr_csense);
4831 if (0!=alloc_rx_desc_ring(dev, priv->rxbuffersize, priv->rxringcount))
4834 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4835 TX_MANAGEPRIORITY_RING_ADDR))
4838 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4839 TX_BKPRIORITY_RING_ADDR))
4842 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4843 TX_BEPRIORITY_RING_ADDR))
4846 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4847 TX_VIPRIORITY_RING_ADDR))
4850 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4851 TX_VOPRIORITY_RING_ADDR))
4854 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4855 TX_HIGHPRIORITY_RING_ADDR))
4858 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txbeaconcount,
4859 TX_BEACON_RING_ADDR))
4863 //priv->beacon_buf=NULL;
4865 if(!priv->card_8185){
4867 if(read_nic_byte(dev, CONFIG0) & (1<<CONFIG0_WEP40_SHIFT))
4868 DMESG ("40-bit WEP is supported in hardware");
4870 DMESG ("40-bit WEP is NOT supported in hardware");
4872 if(read_nic_byte(dev,CONFIG0) & (1<<CONFIG0_WEP104_SHIFT))
4873 DMESG ("104-bit WEP is supported in hardware");
4875 DMESG ("104-bit WEP is NOT supported in hardware");
4877 #if !defined(SA_SHIRQ)
4878 if(request_irq(dev->irq, (void *)rtl8180_interrupt, IRQF_SHARED, dev->name, dev)){
4880 if(request_irq(dev->irq, (void *)rtl8180_interrupt, SA_SHIRQ, dev->name, dev)){
4882 DMESGE("Error allocating IRQ %d",dev->irq);
4886 DMESG("IRQ %d",dev->irq);
4898 void rtl8180_no_hw_wep(struct net_device *dev)
4900 struct r8180_priv *priv = ieee80211_priv(dev);
4902 if(!priv->card_8185)
4906 security = read_nic_byte(dev, SECURITY);
4907 security &=~(1<<SECURITY_WEP_TX_ENABLE_SHIFT);
4908 security &=~(1<<SECURITY_WEP_RX_ENABLE_SHIFT);
4910 write_nic_byte(dev, SECURITY, security);
4917 write_nic_dword(dev,TX_CONF,read_nic_dword(dev,TX_CONF) |
4918 (1<<TX_NOICV_SHIFT) );
4920 // priv->ieee80211->hw_wep=0;
4924 void rtl8180_set_hw_wep(struct net_device *dev)
4926 struct r8180_priv *priv = ieee80211_priv(dev);
4931 pgreg=read_nic_byte(dev, PGSELECT);
4932 write_nic_byte(dev, PGSELECT, pgreg &~ (1<<PGSELECT_PG_SHIFT));
4934 key0_word4 = read_nic_dword(dev, KEY0+4+4+4);
4935 key0_word4 &= ~ 0xff;
4936 key0_word4 |= priv->key0[3]& 0xff;
4937 write_nic_dword(dev,KEY0,(priv->key0[0]));
4938 write_nic_dword(dev,KEY0+4,(priv->key0[1]));
4939 write_nic_dword(dev,KEY0+4+4,(priv->key0[2]));
4940 write_nic_dword(dev,KEY0+4+4+4,(key0_word4));
4943 TX_CONF,read_nic_dword(dev,TX_CONF) &~(1<<TX_NOICV_SHIFT));
4946 security = read_nic_byte(dev,SECURITY);
4947 security |= (1<<SECURITY_WEP_TX_ENABLE_SHIFT);
4948 security |= (1<<SECURITY_WEP_RX_ENABLE_SHIFT);
4949 security &= ~ SECURITY_ENCRYP_MASK;
4950 security |= (SECURITY_ENCRYP_104<<SECURITY_ENCRYP_SHIFT);
4952 write_nic_byte(dev, SECURITY, security);
4954 DMESG("key %x %x %x %x",read_nic_dword(dev,KEY0+4+4+4),
4955 read_nic_dword(dev,KEY0+4+4),read_nic_dword(dev,KEY0+4),
4956 read_nic_dword(dev,KEY0));
4958 //priv->ieee80211->hw_wep=1;
4962 void rtl8185_rf_pins_enable(struct net_device *dev)
4965 // tmp = read_nic_word(dev, RFPinsEnable);
4966 write_nic_word(dev, RFPinsEnable, 0x1fff);// | tmp);
4967 // write_nic_word(dev, RFPinsEnable,7 | tmp);
4971 void rtl8185_set_anaparam2(struct net_device *dev, u32 a)
4975 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
4977 conf3 = read_nic_byte(dev, CONFIG3);
4978 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
4979 write_nic_dword(dev, ANAPARAM2, a);
4981 conf3 = read_nic_byte(dev, CONFIG3);
4982 write_nic_byte(dev, CONFIG3, conf3 &~(1<<CONFIG3_ANAPARAM_W_SHIFT));
4983 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
4988 void rtl8180_set_anaparam(struct net_device *dev, u32 a)
4992 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
4994 conf3 = read_nic_byte(dev, CONFIG3);
4995 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
4996 write_nic_dword(dev, ANAPARAM, a);
4998 conf3 = read_nic_byte(dev, CONFIG3);
4999 write_nic_byte(dev, CONFIG3, conf3 &~(1<<CONFIG3_ANAPARAM_W_SHIFT));
5000 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5004 void rtl8185_tx_antenna(struct net_device *dev, u8 ant)
5006 write_nic_byte(dev, TX_ANTENNA, ant);
5007 force_pci_posting(dev);
5012 void rtl8185_write_phy(struct net_device *dev, u8 adr, u32 data)
5020 phyw= ((data<<8) | adr);
5023 write_nic_dword(dev, PHY_ADR, phyw);
5025 //read_nic_dword(dev, PHY_ADR);
5027 write_nic_dword(dev, PHY_ADR, 0xffffff7f & phyw);
5028 phyr = read_nic_byte(dev, PHY_READ);
5029 if(phyr == (data&0xff)) break;
5033 // Note that, we must write 0xff7c after 0x7d-0x7f to write BB register.
5034 write_nic_byte(dev, 0x7f, ((phyw & 0xff000000) >> 24));
5035 write_nic_byte(dev, 0x7e, ((phyw & 0x00ff0000) >> 16));
5036 write_nic_byte(dev, 0x7d, ((phyw & 0x0000ff00) >> 8));
5037 write_nic_byte(dev, 0x7c, ((phyw & 0x000000ff) ));
5039 /* this is ok to fail when we write AGC table. check for AGC table might be
5040 * done by masking with 0x7f instead of 0xff
5042 //if(phyr != (data&0xff)) DMESGW("Phy write timeout %x %x %x", phyr, data,adr);
5046 inline void write_phy_ofdm (struct net_device *dev, u8 adr, u32 data)
5049 rtl8185_write_phy(dev, adr, data);
5053 void write_phy_cck (struct net_device *dev, u8 adr, u32 data)
5056 rtl8185_write_phy(dev, adr, data | 0x10000);
5061 * I hope this is enougth
5064 void write_phy(struct net_device *dev, u8 adr, u8 data)
5071 phy |= 0x80; /* this should enable writing */
5074 //PHY_ADR, PHY_R and PHY_W are contig and treated as one dword
5075 write_nic_dword(dev,PHY_ADR, phy);
5080 write_nic_dword(dev,PHY_ADR, phy);
5081 for(i=0;i<MAX_PHY;i++){
5082 phy=read_nic_dword(dev,PHY_ADR);
5083 phy= phy & 0xff0000;
5085 if(phy == data){ //SUCCESS!
5086 force_pci_posting(dev);
5087 mdelay(3); //random value
5089 DMESG("Phy wr %x,%x",adr,data);
5093 force_pci_posting(dev);
5094 mdelay(3); //random value
5097 DMESGW ("Phy writing %x %x failed!", adr,data);
5100 void rtl8185_set_rate(struct net_device *dev)
5104 int basic_rate,min_rr_rate,max_rr_rate;
5106 // struct r8180_priv *priv = ieee80211_priv(dev);
5108 //if (ieee80211_is_54g(priv->ieee80211->current_network) &&
5109 // priv->ieee80211->state == IEEE80211_LINKED){
5110 basic_rate = ieeerate2rtlrate(240);
5111 min_rr_rate = ieeerate2rtlrate(60);
5112 max_rr_rate = ieeerate2rtlrate(240);
5116 // basic_rate = ieeerate2rtlrate(20);
5117 // min_rr_rate = ieeerate2rtlrate(10);
5118 // max_rr_rate = ieeerate2rtlrate(110);
5121 write_nic_byte(dev, RESP_RATE,
5122 max_rr_rate<<MAX_RESP_RATE_SHIFT| min_rr_rate<<MIN_RESP_RATE_SHIFT);
5124 word = read_nic_word(dev, BRSR);
5125 word &= ~BRSR_MBR_8185;
5128 for(i=0;i<=basic_rate;i++)
5131 write_nic_word(dev, BRSR, word);
5132 //DMESG("RR:%x BRSR: %x", read_nic_byte(dev,RESP_RATE),read_nic_word(dev,BRSR));
5137 void rtl8180_adapter_start(struct net_device *dev)
5139 struct r8180_priv *priv = ieee80211_priv(dev);
5145 rtl8180_rtx_disable(dev);
5148 /* seems that 0xffff or 0xafff will cause
5149 * HW interrupt line crash
5152 //priv->irq_mask = 0xafff;
5153 // priv->irq_mask = 0x4fcf;
5155 /* enable beacon timeout, beacon TX ok and err
5156 * LP tx ok and err, HP TX ok and err, NP TX ok and err,
5157 * RX ok and ERR, and GP timer */
5158 priv->irq_mask = 0x6fcf;
5160 priv->dma_poll_mask = 0;
5162 rtl8180_beacon_tx_disable(dev);
5164 if(priv->card_type == CARDBUS ){
5165 config3=read_nic_byte(dev, CONFIG3);
5166 write_nic_byte(dev,CONFIG3,config3 | CONFIG3_FuncRegEn);
5167 write_nic_word(dev,FEMR, FEMR_INTR | FEMR_WKUP | FEMR_GWAKE |
5168 read_nic_word(dev, FEMR));
5170 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5171 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
5172 write_nic_word(dev, MAC4, ((u32*)dev->dev_addr)[1] & 0xffff );
5173 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5175 rtl8180_update_msr(dev);
5177 if(!priv->card_8185){
5178 anaparam = eprom_read(dev,EPROM_ANAPARAM_ADDRLWORD);
5179 anaparam |= eprom_read(dev,EPROM_ANAPARAM_ADDRHWORD)<<16;
5181 rtl8180_set_anaparam(dev,anaparam);
5183 /* These might be unnecessary since we do in rx_enable / tx_enable */
5186 /*set_nic_rxring(dev);
5187 set_nic_txring(dev);*/
5189 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5192 The following is very strange. seems to be that 1 means test mode,
5193 but we need to acknolwledges the nic when a packet is ready
5194 altought we set it to 0
5198 CONFIG2, read_nic_byte(dev,CONFIG2) &~\
5199 (1<<CONFIG2_DMA_POLLING_MODE_SHIFT));
5200 //^the nic isn't in test mode
5203 CONFIG2, read_nic_byte(dev,CONFIG2)|(1<<4));
5205 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
5207 write_nic_dword(dev,INT_TIMEOUT,0);
5208 #ifdef DEBUG_REGISTERS
5209 rtl8180_dump_reg(dev);
5212 if(!priv->card_8185)
5215 experimental - this might be needed to calibrate AGC,
5216 anyway it shouldn't hurt
5218 write_nic_byte(dev, CONFIG5,
5219 read_nic_byte(dev, CONFIG5) | (1<<AGCRESET_SHIFT));
5220 read_nic_byte(dev, CONFIG5);
5222 write_nic_byte(dev, CONFIG5,
5223 read_nic_byte(dev, CONFIG5) &~ (1<<AGCRESET_SHIFT));
5226 write_nic_byte(dev, WPA_CONFIG, 0);
5227 //write_nic_byte(dev, TESTR, 0xd);
5230 rtl8180_no_hw_wep(dev);
5232 if(priv->card_8185){
5233 rtl8185_set_rate(dev);
5234 write_nic_byte(dev, RATE_FALLBACK, 0x81);
5235 // write_nic_byte(dev, 0xdf, 0x15);
5237 word = read_nic_word(dev, BRSR);
5239 word &= ~BRSR_BPLCP;
5240 word |= ieeerate2rtlrate(priv->ieee80211->basic_rate);
5244 write_nic_word(dev, BRSR, word);
5248 if(priv->card_8185){
5249 write_nic_byte(dev, GP_ENABLE,read_nic_byte(dev, GP_ENABLE) & ~(1<<6));
5251 //FIXME cfg 3 ClkRun enable - isn't it ReadOnly ?
5252 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5253 write_nic_byte(dev,CONFIG3, read_nic_byte(dev, CONFIG3)
5254 |(1<<CONFIG3_CLKRUN_SHIFT));
5255 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5261 if(priv->rf_set_sens != NULL)
5262 priv->rf_set_sens(dev,priv->sens);
5263 rtl8180_irq_enable(dev);
5265 netif_start_queue(dev);
5266 /*DMESG ("lfree %d",get_curr_tx_free_desc(dev,LOW_PRIORITY));
5268 DMESG ("nfree %d",get_curr_tx_free_desc(dev,NORM_PRIORITY));
5270 DMESG ("hfree %d",get_curr_tx_free_desc(dev,HI_PRIORITY));
5271 if(check_nic_enought_desc(dev,NORM_PRIORITY)) DMESG("NORM OK");
5272 if(check_nic_enought_desc(dev,HI_PRIORITY)) DMESG("HI OK");
5273 if(check_nic_enought_desc(dev,LOW_PRIORITY)) DMESG("LOW OK");*/
5278 /* this configures registers for beacon tx and enables it via
5279 * rtl8180_beacon_tx_enable(). rtl8180_beacon_tx_disable() might
5280 * be used to stop beacon transmission
5282 void rtl8180_start_tx_beacon(struct net_device *dev)
5284 // struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
5286 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
5288 DMESG("Enabling beacon TX");
5289 //write_nic_byte(dev, 0x42,0xe6);// TCR
5290 // set_nic_txring(dev);
5291 // fix_tx_fifo(dev);
5292 rtl8180_prepare_beacon(dev);
5293 rtl8180_irq_disable(dev);
5294 rtl8180_beacon_tx_enable(dev);
5296 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
5297 //write_nic_byte(dev,0x9d,0x20); //DMA Poll
5298 //write_nic_word(dev,0x7a,0);
5299 //write_nic_word(dev,0x7a,0x8000);
5302 word = read_nic_word(dev, BcnItv);
5303 word &= ~BcnItv_BcnItv; // clear Bcn_Itv
5304 word |= priv->ieee80211->current_network.beacon_interval;//0x64;
5305 write_nic_word(dev, BcnItv, word);
5308 word = read_nic_word(dev, AtimWnd) &~ AtimWnd_AtimWnd;
5309 write_nic_word(dev, AtimWnd,word);// word |=
5310 //priv->ieee80211->current_network.atim_window);
5312 word = read_nic_word(dev, BintrItv);
5313 word &= ~BintrItv_BintrItv;
5314 word |= 1000;/*priv->ieee80211->current_network.beacon_interval *
5315 ((priv->txbeaconcount > 1)?(priv->txbeaconcount-1):1);
5316 // FIXME: check if correct ^^ worked with 0x3e8;
5318 write_nic_word(dev, BintrItv, word);
5321 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5323 // rtl8180_beacon_tx_enable(dev);
5324 #ifdef CONFIG_RTL8185B
5325 rtl8185b_irq_enable(dev);
5327 rtl8180_irq_enable(dev);
5329 /* VV !!!!!!!!!! VV*/
5331 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
5332 write_nic_byte(dev,0x9d,0x00);
5333 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
5335 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
5341 /***************************************************************************
5342 -------------------------------NET STUFF---------------------------
5343 ***************************************************************************/
5344 static struct net_device_stats *rtl8180_stats(struct net_device *dev)
5346 struct r8180_priv *priv = ieee80211_priv(dev);
5348 return &priv->ieee80211->stats;
5351 // Change current and default preamble mode.
5352 // 2005.01.06, by rcnjko.
5355 MgntActSet_802_11_PowerSaveMode(
5356 struct r8180_priv *priv,
5361 // Currently, we do not change power save mode on IBSS mode.
5362 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
5368 // <RJ_NOTE> If we make HW to fill up the PwrMgt bit for us,
5369 // some AP will not response to our mgnt frames with PwrMgt bit set,
5370 // e.g. cannot associate the AP.
5371 // So I commented out it. 2005.02.16, by rcnjko.
5373 // // Change device's power save mode.
5374 // Adapter->HalFunc.SetPSModeHandler( Adapter, rtPsMode );
5376 // Update power save mode configured.
5377 // priv->dot11PowerSaveMode = rtPsMode;
5378 priv->ieee80211->ps = rtPsMode;
5379 // Determine ListenInterval.
5381 if(priv->dot11PowerSaveMode == eMaxPs)
5383 priv->ieee80211->ListenInterval = 10;
5387 priv->ieee80211->ListenInterval = 2;
5393 //================================================================================
5394 // Leisure Power Save in linked state.
5395 //================================================================================
5399 // Enter the leisure power save mode.
5403 struct r8180_priv *priv
5406 if (priv->bLeisurePs)
5408 if (priv->ieee80211->ps == IEEE80211_PS_DISABLED)
5410 //printk("----Enter PS\n");
5411 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST);//IEEE80211_PS_ENABLE
5419 // Leave the leisure power save mode.
5423 struct r8180_priv *priv
5426 if (priv->bLeisurePs)
5428 if (priv->ieee80211->ps != IEEE80211_PS_DISABLED)
5430 //printk("----Leave PS\n");
5431 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_DISABLED);
5435 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5436 void rtl8180_hw_wakeup_wq (struct work_struct *work)
5438 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
5439 // struct ieee80211_device * ieee = (struct ieee80211_device*)
5440 // container_of(work, struct ieee80211_device, watch_dog_wq);
5441 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
5442 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq);
5443 struct net_device *dev = ieee->dev;
5445 void rtl8180_hw_wakeup_wq(struct net_device *dev)
5447 struct r8180_priv *priv = ieee80211_priv(dev);
5450 // printk("dev is %d\n",dev);
5451 // printk("&*&(^*(&(&=========>%s()\n", __func__);
5452 rtl8180_hw_wakeup(dev);
5456 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5457 void rtl8180_hw_sleep_wq (struct work_struct *work)
5459 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
5460 // struct ieee80211_device * ieee = (struct ieee80211_device*)
5461 // container_of(work, struct ieee80211_device, watch_dog_wq);
5462 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
5463 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq);
5464 struct net_device *dev = ieee->dev;
5466 void rtl8180_hw_sleep_wq(struct net_device *dev)
5468 struct r8180_priv *priv = ieee80211_priv(dev);
5471 rtl8180_hw_sleep_down(dev);
5474 //YJ,add,080828,for KeepAlive
5475 static void MgntLinkKeepAlive(struct r8180_priv *priv )
5477 if (priv->keepAliveLevel == 0)
5480 if(priv->ieee80211->state == IEEE80211_LINKED)
5485 //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);
5487 if ( (priv->keepAliveLevel== 2) ||
5488 (priv->link_detect.LastNumTxUnicast == priv->NumTxUnicast &&
5489 priv->link_detect.LastNumRxUnicast == priv->ieee80211->NumRxUnicast )
5492 priv->link_detect.IdleCount++;
5495 // Send a Keep-Alive packet packet to AP if we had been idle for a while.
5497 if(priv->link_detect.IdleCount >= ((KEEP_ALIVE_INTERVAL / CHECK_FOR_HANG_PERIOD)-1) )
5499 priv->link_detect.IdleCount = 0;
5500 ieee80211_sta_ps_send_null_frame(priv->ieee80211, false);
5505 priv->link_detect.IdleCount = 0;
5507 priv->link_detect.LastNumTxUnicast = priv->NumTxUnicast;
5508 priv->link_detect.LastNumRxUnicast = priv->ieee80211->NumRxUnicast;
5511 //YJ,add,080828,for KeepAlive,end
5513 static u8 read_acadapter_file(char *filename);
5514 void rtl8180_watch_dog(struct net_device *dev)
5516 struct r8180_priv *priv = ieee80211_priv(dev);
5517 bool bEnterPS = false;
5518 bool bBusyTraffic = false;
5523 if(priv->ieee80211->actscanning == false){
5524 if((priv->ieee80211->iw_mode != IW_MODE_ADHOC) && (priv->ieee80211->state == IEEE80211_NOLINK) && (priv->ieee80211->beinretry == false) && (priv->eRFPowerState == eRfOn)){
5529 //YJ,add,080828,for link state check
5530 if((priv->ieee80211->state == IEEE80211_LINKED) && (priv->ieee80211->iw_mode == IW_MODE_INFRA)){
5531 SlotIndex = (priv->link_detect.SlotIndex++) % priv->link_detect.SlotNum;
5532 priv->link_detect.RxFrameNum[SlotIndex] = priv->ieee80211->NumRxDataInPeriod + priv->ieee80211->NumRxBcnInPeriod;
5533 for( i=0; i<priv->link_detect.SlotNum; i++ )
5534 TotalRxNum+= priv->link_detect.RxFrameNum[i];
5535 //printk("&&&&&=== TotalRxNum = %d\n", TotalRxNum);
5536 if(TotalRxNum == 0){
5537 priv->ieee80211->state = IEEE80211_ASSOCIATING;
5538 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
5542 //YJ,add,080828,for KeepAlive
5543 MgntLinkKeepAlive(priv);
5545 //YJ,add,080828,for LPS
5547 if(priv->PowerProfile == POWER_PROFILE_BATTERY )
5549 //Turn on LeisurePS on battery power
5550 //printk("!!!!!On battery power\n");
5551 priv->bLeisurePs = true;
5553 else if(priv->PowerProfile == POWER_PROFILE_AC )
5555 // Turn off LeisurePS on AC power
5556 //printk("----On AC power\n");
5557 LeisurePSLeave(priv);
5558 priv->bLeisurePs= false;
5564 if(priv->ieee80211->state == IEEE80211_LINKED){
5565 if( priv->NumRxOkInPeriod> 666 ||
5566 priv->NumTxOkInPeriod > 666 ) {
5567 bBusyTraffic = true;
5569 if((priv->ieee80211->NumRxData + priv->NumTxOkInPeriod)<8) {
5573 LeisurePSEnter(priv);
5576 LeisurePSLeave(priv);
5580 LeisurePSLeave(priv);
5583 priv->NumRxOkInPeriod = 0;
5584 priv->NumTxOkInPeriod = 0;
5585 priv->ieee80211->NumRxData = 0;
5588 if(priv->ieee80211->state == IEEE80211_LINKED){
5589 priv->link_detect.NumRxOkInPeriod = priv->ieee80211->NumRxDataInPeriod;
5590 //printk("TxOk=%d RxOk=%d\n", priv->link_detect.NumTxOkInPeriod, priv->link_detect.NumRxOkInPeriod);
5591 if( priv->link_detect.NumRxOkInPeriod> 666 ||
5592 priv->link_detect.NumTxOkInPeriod> 666 ) {
5593 bBusyTraffic = true;
5595 if(((priv->link_detect.NumRxOkInPeriod + priv->link_detect.NumTxOkInPeriod) > 8)
5596 || (priv->link_detect.NumRxOkInPeriod > 2)) {
5604 LeisurePSEnter(priv);
5607 LeisurePSLeave(priv);
5611 LeisurePSLeave(priv);
5614 priv->link_detect.bBusyTraffic = bBusyTraffic;
5615 priv->link_detect.NumRxOkInPeriod = 0;
5616 priv->link_detect.NumTxOkInPeriod = 0;
5617 priv->ieee80211->NumRxDataInPeriod = 0;
5618 priv->ieee80211->NumRxBcnInPeriod = 0;
5621 int _rtl8180_up(struct net_device *dev)
5623 struct r8180_priv *priv = ieee80211_priv(dev);
5628 DMESG("Bringing up iface");
5629 #ifdef CONFIG_RTL8185B
5630 rtl8185b_adapter_start(dev);
5631 rtl8185b_rx_enable(dev);
5632 rtl8185b_tx_enable(dev);
5634 rtl8180_adapter_start(dev);
5635 rtl8180_rx_enable(dev);
5636 rtl8180_tx_enable(dev);
5639 if(priv->bInactivePs){
5640 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
5646 timer_rate_adaptive((unsigned long)dev);
5649 watch_dog_adaptive((unsigned long)dev);
5651 if(priv->bSwAntennaDiverity)
5652 SwAntennaDiversityTimerCallback(dev);
5655 ieee80211_softmac_start_protocol(priv->ieee80211);
5657 //Add for RF power on power off by lizhaoming 080512
5658 // priv->eRFPowerState = eRfOn;
5659 // printk("\n--------Start queue_work:GPIOChangeRFWorkItem");
5660 // queue_delayed_work(priv->ieee80211->wq,&priv->ieee80211->GPIOChangeRFWorkItem,1000);
5666 int rtl8180_open(struct net_device *dev)
5668 struct r8180_priv *priv = ieee80211_priv(dev);
5671 down(&priv->wx_sem);
5672 ret = rtl8180_up(dev);
5679 int rtl8180_up(struct net_device *dev)
5681 struct r8180_priv *priv = ieee80211_priv(dev);
5683 if (priv->up == 1) return -1;
5685 return _rtl8180_up(dev);
5689 int rtl8180_close(struct net_device *dev)
5691 struct r8180_priv *priv = ieee80211_priv(dev);
5694 down(&priv->wx_sem);
5695 ret = rtl8180_down(dev);
5702 int rtl8180_down(struct net_device *dev)
5704 struct r8180_priv *priv = ieee80211_priv(dev);
5706 if (priv->up == 0) return -1;
5710 ieee80211_softmac_stop_protocol(priv->ieee80211);
5712 if (!netif_queue_stopped(dev))
5713 netif_stop_queue(dev);
5714 rtl8180_rtx_disable(dev);
5715 rtl8180_irq_disable(dev);
5716 del_timer_sync(&priv->watch_dog_timer);
5717 //cancel_delayed_work(&priv->ieee80211->watch_dog_wq);
5719 del_timer_sync(&priv->rateadapter_timer);
5720 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
5722 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
5723 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
5724 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
5725 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
5726 del_timer_sync(&priv->SwAntennaDiversityTimer);
5727 SetZebraRFPowerState8185(dev,eRfOff);
5728 //ieee80211_softmac_stop_protocol(priv->ieee80211);
5729 memset(&(priv->ieee80211->current_network),0,sizeof(struct ieee80211_network));
5730 priv->ieee80211->state = IEEE80211_NOLINK;
5734 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5735 void rtl8180_restart_wq(struct work_struct *work)
5737 struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
5738 struct net_device *dev = priv->dev;
5740 void rtl8180_restart_wq(struct net_device *dev)
5742 struct r8180_priv *priv = ieee80211_priv(dev);
5744 down(&priv->wx_sem);
5746 rtl8180_commit(dev);
5751 void rtl8180_restart(struct net_device *dev)
5753 struct r8180_priv *priv = ieee80211_priv(dev);
5754 //rtl8180_commit(dev);
5755 schedule_work(&priv->reset_wq);
5756 //DMESG("TXTIMEOUT");
5760 void rtl8180_commit(struct net_device *dev)
5762 struct r8180_priv *priv = ieee80211_priv(dev);
5764 if (priv->up == 0) return ;
5766 del_timer_sync(&priv->watch_dog_timer);
5767 //cancel_delayed_work(&priv->ieee80211->watch_dog_wq);
5769 //by amy for rate adaptive
5770 del_timer_sync(&priv->rateadapter_timer);
5771 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
5772 //by amy for rate adaptive
5774 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
5775 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
5776 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
5777 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
5778 del_timer_sync(&priv->SwAntennaDiversityTimer);
5779 ieee80211_softmac_stop_protocol(priv->ieee80211);
5780 rtl8180_irq_disable(dev);
5781 rtl8180_rtx_disable(dev);
5786 static void r8180_set_multicast(struct net_device *dev)
5788 struct r8180_priv *priv = ieee80211_priv(dev);
5791 //down(&priv->wx_sem);
5793 promisc = (dev->flags & IFF_PROMISC) ? 1:0;
5795 if (promisc != priv->promisc)
5796 rtl8180_restart(dev);
5798 priv->promisc = promisc;
5800 //up(&priv->wx_sem);
5804 /* this is called by the kernel when it needs to TX a 802.3 encapsulated frame*/
5805 int rtl8180_8023_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
5807 struct r8180_priv *priv = ieee80211_priv(dev);
5809 unsigned long flags;
5811 spin_lock_irqsave(&priv->tx_lock,flags);
5812 ret = ieee80211_r8180_8023_hardstartxmit(skb,priv->ieee80211);
5813 spin_unlock_irqrestore(&priv->tx_lock,flags);
5818 int r8180_set_mac_adr(struct net_device *dev, void *mac)
5820 struct r8180_priv *priv = ieee80211_priv(dev);
5821 struct sockaddr *addr = mac;
5823 down(&priv->wx_sem);
5825 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
5827 if(priv->ieee80211->iw_mode == IW_MODE_MASTER)
5828 memcpy(priv->ieee80211->current_network.bssid, dev->dev_addr, ETH_ALEN);
5840 /* based on ipw2200 driver */
5841 int rtl8180_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5843 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
5845 struct iwreq *wrq = (struct iwreq *) rq;
5848 case RTL_IOCTL_WPA_SUPPLICANT:
5849 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
5861 /****************************************************************************
5862 -----------------------------PCI STUFF---------------------------
5863 *****************************************************************************/
5866 static int __devinit rtl8180_pci_probe(struct pci_dev *pdev,
5867 const struct pci_device_id *id)
5869 unsigned long ioaddr = 0;
5870 struct net_device *dev = NULL;
5871 struct r8180_priv *priv= NULL;
5875 #ifdef CONFIG_RTL8180_IO_MAP
5876 unsigned long pio_start, pio_len, pio_flags;
5878 unsigned long pmem_start, pmem_len, pmem_flags;
5879 #endif //end #ifdef RTL_IO_MAP
5881 DMESG("Configuring chip resources");
5883 if( pci_enable_device (pdev) ){
5884 DMESG("Failed to enable PCI device");
5888 pci_set_master(pdev);
5889 //pci_set_wmi(pdev);
5890 pci_set_dma_mask(pdev, 0xffffff00ULL);
5891 pci_set_consistent_dma_mask(pdev,0xffffff00ULL);
5892 dev = alloc_ieee80211(sizeof(struct r8180_priv));
5895 priv = ieee80211_priv(dev);
5896 priv->ieee80211 = netdev_priv(dev);
5898 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
5899 SET_MODULE_OWNER(dev);
5901 pci_set_drvdata(pdev, dev);
5902 SET_NETDEV_DEV(dev, &pdev->dev);
5904 priv = ieee80211_priv(dev);
5905 // memset(priv,0,sizeof(struct r8180_priv));
5909 #ifdef CONFIG_RTL8180_IO_MAP
5911 pio_start = (unsigned long)pci_resource_start (pdev, 0);
5912 pio_len = (unsigned long)pci_resource_len (pdev, 0);
5913 pio_flags = (unsigned long)pci_resource_flags (pdev, 0);
5915 if (!(pio_flags & IORESOURCE_IO)) {
5916 DMESG("region #0 not a PIO resource, aborting");
5920 //DMESG("IO space @ 0x%08lx", pio_start );
5921 if( ! request_region( pio_start, pio_len, RTL8180_MODULE_NAME ) ){
5922 DMESG("request_region failed!");
5927 dev->base_addr = ioaddr; // device I/O address
5931 pmem_start = pci_resource_start(pdev, 1);
5932 pmem_len = pci_resource_len(pdev, 1);
5933 pmem_flags = pci_resource_flags (pdev, 1);
5935 if (!(pmem_flags & IORESOURCE_MEM)) {
5936 DMESG("region #1 not a MMIO resource, aborting");
5940 //DMESG("Memory mapped space @ 0x%08lx ", pmem_start);
5941 if( ! request_mem_region(pmem_start, pmem_len, RTL8180_MODULE_NAME)) {
5942 DMESG("request_mem_region failed!");
5947 ioaddr = (unsigned long)ioremap_nocache( pmem_start, pmem_len);
5948 if( ioaddr == (unsigned long)NULL ){
5949 DMESG("ioremap failed!");
5950 // release_mem_region( pmem_start, pmem_len );
5954 dev->mem_start = ioaddr; // shared mem start
5955 dev->mem_end = ioaddr + pci_resource_len(pdev, 0); // shared mem end
5957 #endif //end #ifdef RTL_IO_MAP
5959 #ifdef CONFIG_RTL8185B
5960 //pci_read_config_byte(pdev, 0x05, ptr);
5961 //pci_write_config_byte(pdev, 0x05, (*ptr) & (~0x04));
5962 pci_read_config_byte(pdev, 0x05, &unit);
5963 pci_write_config_byte(pdev, 0x05, unit & (~0x04));
5966 dev->irq = pdev->irq;
5969 dev->open = rtl8180_open;
5970 dev->stop = rtl8180_close;
5971 //dev->hard_start_xmit = ieee80211_xmit;
5972 dev->tx_timeout = rtl8180_restart;
5973 dev->wireless_handlers = &r8180_wx_handlers_def;
5974 dev->do_ioctl = rtl8180_ioctl;
5975 dev->set_multicast_list = r8180_set_multicast;
5976 dev->set_mac_address = r8180_set_mac_adr;
5978 #if WIRELESS_EXT >= 12
5979 #if WIRELESS_EXT < 17
5980 dev->get_wireless_stats = r8180_get_wireless_stats;
5982 dev->wireless_handlers = (struct iw_handler_def *) &r8180_wx_handlers_def;
5985 dev->type=ARPHRD_ETHER;
5986 dev->watchdog_timeo = HZ*3; //added by david woo, 2007.12.13
5988 if (dev_alloc_name(dev, ifname) < 0){
5989 DMESG("Oops: devname already taken! Trying wlan%%d...\n");
5991 // ifname = "ath%d";
5992 dev_alloc_name(dev, ifname);
5996 if(rtl8180_init(dev)!=0){
5997 DMESG("Initialization failed");
6001 netif_carrier_off(dev);
6003 register_netdev(dev);
6005 rtl8180_proc_init_one(dev);
6007 DMESG("Driver probe completed\n");
6012 #ifdef CONFIG_RTL8180_IO_MAP
6014 if( dev->base_addr != 0 ){
6016 release_region(dev->base_addr,
6017 pci_resource_len(pdev, 0) );
6020 if( dev->mem_start != (unsigned long)NULL ){
6021 iounmap( (void *)dev->mem_start );
6022 release_mem_region( pci_resource_start(pdev, 1),
6023 pci_resource_len(pdev, 1) );
6025 #endif //end #ifdef RTL_IO_MAP
6032 free_irq(dev->irq, dev);
6035 free_ieee80211(dev);
6038 pci_disable_device(pdev);
6040 DMESG("wlan driver load failed\n");
6041 pci_set_drvdata(pdev, NULL);
6047 static void __devexit rtl8180_pci_remove(struct pci_dev *pdev)
6049 struct r8180_priv *priv;
6050 struct net_device *dev = pci_get_drvdata(pdev);
6053 unregister_netdev(dev);
6055 priv=ieee80211_priv(dev);
6057 rtl8180_proc_remove_one(dev);
6059 priv->rf_close(dev);
6061 //rtl8180_rtx_disable(dev);
6062 //rtl8180_irq_disable(dev);
6064 //write_nic_word(dev,INTA,read_nic_word(dev,INTA));
6065 //force_pci_posting(dev);
6070 DMESG("Freeing irq %d",dev->irq);
6071 free_irq(dev->irq, dev);
6076 free_rx_desc_ring(dev);
6077 free_tx_desc_rings(dev);
6078 // free_beacon_desc_ring(dev,priv->txbeaconcount);
6080 #ifdef CONFIG_RTL8180_IO_MAP
6082 if( dev->base_addr != 0 ){
6084 release_region(dev->base_addr,
6085 pci_resource_len(pdev, 0) );
6088 if( dev->mem_start != (unsigned long)NULL ){
6089 iounmap( (void *)dev->mem_start );
6090 release_mem_region( pci_resource_start(pdev, 1),
6091 pci_resource_len(pdev, 1) );
6093 #endif /*end #ifdef RTL_IO_MAP*/
6095 free_ieee80211(dev);
6097 pci_disable_device(pdev);
6099 DMESG("wlan driver removed\n");
6103 /* fun with the built-in ieee80211 stack... */
6104 extern int ieee80211_crypto_init(void);
6105 extern void ieee80211_crypto_deinit(void);
6106 extern int ieee80211_crypto_tkip_init(void);
6107 extern void ieee80211_crypto_tkip_exit(void);
6108 extern int ieee80211_crypto_ccmp_init(void);
6109 extern void ieee80211_crypto_ccmp_exit(void);
6110 extern int ieee80211_crypto_wep_init(void);
6111 extern void ieee80211_crypto_wep_exit(void);
6113 static int __init rtl8180_pci_module_init(void)
6117 ret = ieee80211_crypto_init();
6119 printk(KERN_ERR "ieee80211_crypto_init() failed %d\n", ret);
6122 ret = ieee80211_crypto_tkip_init();
6124 printk(KERN_ERR "ieee80211_crypto_tkip_init() failed %d\n", ret);
6127 ret = ieee80211_crypto_ccmp_init();
6129 printk(KERN_ERR "ieee80211_crypto_ccmp_init() failed %d\n", ret);
6132 ret = ieee80211_crypto_wep_init();
6134 printk(KERN_ERR "ieee80211_crypto_wep_init() failed %d\n", ret);
6138 printk(KERN_INFO "\nLinux kernel driver for RTL8180 \
6139 / RTL8185 based WLAN cards\n");
6140 printk(KERN_INFO "Copyright (c) 2004-2005, Andrea Merello\n");
6141 DMESG("Initializing module");
6142 DMESG("Wireless extensions version %d", WIRELESS_EXT);
6143 rtl8180_proc_module_init();
6145 #if(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
6146 if(0!=pci_module_init(&rtl8180_pci_driver))
6148 if(0!=pci_register_driver(&rtl8180_pci_driver))
6150 //if(0!=pci_module_init(&rtl8180_pci_driver))
6152 DMESG("No device found");
6153 /*pci_unregister_driver (&rtl8180_pci_driver);*/
6160 static void __exit rtl8180_pci_module_exit(void)
6162 pci_unregister_driver (&rtl8180_pci_driver);
6163 rtl8180_proc_module_remove();
6164 ieee80211_crypto_tkip_exit();
6165 ieee80211_crypto_ccmp_exit();
6166 ieee80211_crypto_wep_exit();
6167 ieee80211_crypto_deinit();
6172 void rtl8180_try_wake_queue(struct net_device *dev, int pri)
6174 unsigned long flags;
6176 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
6178 spin_lock_irqsave(&priv->tx_lock,flags);
6179 enough_desc = check_nic_enought_desc(dev,pri);
6180 spin_unlock_irqrestore(&priv->tx_lock,flags);
6183 ieee80211_wake_queue(priv->ieee80211);
6186 /*****************************************************************************
6187 -----------------------------IRQ STUFF---------------------------
6188 ******************************************************************************/
6190 void rtl8180_tx_isr(struct net_device *dev, int pri,short error)
6192 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
6194 u32 *tail; //tail virtual addr
6195 u32 *head; //head virtual addr
6196 u32 *begin;//start of ring virtual addr
6197 u32 *nicv; //nic pointer virtual addr
6198 // u32 *txdv; //packet just TXed
6199 u32 nic; //nic pointer physical addr
6200 u32 nicbegin;// start of ring physical addr
6203 /* physical addr are ok on 32 bits since we set DMA mask*/
6208 if (error) priv->stats.txretry++; //tony 20060601
6209 spin_lock_irqsave(&priv->tx_lock,flag);
6211 case MANAGE_PRIORITY:
6212 tail = priv->txmapringtail;
6213 begin = priv->txmapring;
6214 head = priv->txmapringhead;
6215 nic = read_nic_dword(dev,TX_MANAGEPRIORITY_RING_ADDR);
6216 nicbegin = priv->txmapringdma;
6220 tail = priv->txbkpringtail;
6221 begin = priv->txbkpring;
6222 head = priv->txbkpringhead;
6223 nic = read_nic_dword(dev,TX_BKPRIORITY_RING_ADDR);
6224 nicbegin = priv->txbkpringdma;
6228 tail = priv->txbepringtail;
6229 begin = priv->txbepring;
6230 head = priv->txbepringhead;
6231 nic = read_nic_dword(dev,TX_BEPRIORITY_RING_ADDR);
6232 nicbegin = priv->txbepringdma;
6236 tail = priv->txvipringtail;
6237 begin = priv->txvipring;
6238 head = priv->txvipringhead;
6239 nic = read_nic_dword(dev,TX_VIPRIORITY_RING_ADDR);
6240 nicbegin = priv->txvipringdma;
6244 tail = priv->txvopringtail;
6245 begin = priv->txvopring;
6246 head = priv->txvopringhead;
6247 nic = read_nic_dword(dev,TX_VOPRIORITY_RING_ADDR);
6248 nicbegin = priv->txvopringdma;
6252 tail = priv->txhpringtail;
6253 begin = priv->txhpring;
6254 head = priv->txhpringhead;
6255 nic = read_nic_dword(dev,TX_HIGHPRIORITY_RING_ADDR);
6256 nicbegin = priv->txhpringdma;
6260 spin_unlock_irqrestore(&priv->tx_lock,flag);
6263 /* DMESG("%x %s %x %x",((int)nic & 0xfff)/8/4,
6264 *(priv->txnpring + ((int)nic&0xfff)/4/8) & (1<<31) ? "filled" : "empty",
6265 (priv->txnpringtail - priv->txnpring)/8,(priv->txnpringhead -
6268 //nicv = (u32*) ((nic - nicbegin) + (int)begin);
6269 nicv = (u32*) ((nic - nicbegin) + (u8*)begin);
6270 if((head <= tail && (nicv > tail || nicv < head)) ||
6271 (head > tail && (nicv > tail && nicv < head))){
6273 DMESGW("nic has lost pointer");
6274 #ifdef DEBUG_TX_DESC
6275 //check_tx_ring(dev,NORM_PRIORITY);
6276 check_tx_ring(dev,pri);
6278 spin_unlock_irqrestore(&priv->tx_lock,flag);
6279 rtl8180_restart(dev);
6283 /* we check all the descriptors between the head and the nic,
6284 * but not the currenly pointed by the nic (the next to be txed)
6285 * and the previous of the pointed (might be in process ??)
6287 //if (head == nic) return;
6288 //DMESG("%x %x",head,nic);
6289 offs = (nic - nicbegin);
6290 //DMESG("%x %x %x",nic ,(u32)nicbegin, (int)nic -nicbegin);
6294 hd = (head - begin) /8;
6299 j = offs + (priv->txringcount -1 -hd);
6300 // j= priv->txringcount -1- (hd - offs);
6308 // printk("+++++++++++++check status desc\n");
6309 if((*head) & (1<<31))
6311 if(((*head)&(0x10000000)) != 0){
6312 // printk("++++++++++++++last desc,retry count is %d\n",((*head) & (0x000000ff)));
6313 priv->CurrRetryCnt += (u16)((*head) & (0x000000ff));
6317 priv->NumTxOkTotal++;
6318 // printk("NumTxOkTotal is %d\n",priv->NumTxOkTotal++);
6321 // printk("in function %s:curr_retry_count is %d\n",__func__,((*head) & (0x000000ff)));
6324 priv->NumTxOkBytesTotal += (*(head+3)) & (0x00000fff);
6326 // printk("in function %s:curr_txokbyte_count is %d\n",__func__,(*(head+3)) & (0x00000fff));
6327 *head = *head &~ (1<<31);
6329 if((head - begin)/8 == priv->txringcount-1)
6337 txdv = begin + (priv->txringcount -1)*8;
6341 txed = !(txdv[0] &(1<<31));
6344 if(!(txdv[0] & (1<<15))) error = 1;
6345 //if(!(txdv[0] & (1<<30))) error = 1;
6346 if(error)DMESG("%x",txdv[0]);
6349 //DMESG("%x",txdv[0]);
6350 /* the head has been moved to the last certainly TXed
6351 * (or at least processed by the nic) packet.
6352 * The driver take forcefully owning of all these packets
6353 * If the packet previous of the nic pointer has been
6354 * processed this doesn't matter: it will be checked
6355 * here at the next round. Anyway if no more packet are
6356 * TXed no memory leak occour at all.
6360 case MANAGE_PRIORITY:
6361 priv->txmapringhead = head;
6362 //printk("1==========================================> priority check!\n");
6363 if(priv->ack_tx_to_ieee){
6364 // try to implement power-save mode 2008.1.22
6365 // printk("2==========================================> priority check!\n");
6367 if(rtl8180_is_tx_queue_empty(dev)){
6368 // printk("tx queue empty, after send null sleep packet, try to sleep !\n");
6369 priv->ack_tx_to_ieee = 0;
6370 ieee80211_ps_tx_ack(priv->ieee80211,!error);
6377 priv->txbkpringhead = head;
6381 priv->txbepringhead = head;
6385 priv->txvipringhead = head;
6389 priv->txvopringhead = head;
6393 priv->txhpringhead = head;
6397 /*DMESG("%x %x %x", (priv->txnpringhead - priv->txnpring) /8 ,
6398 (priv->txnpringtail - priv->txnpring) /8,
6402 spin_unlock_irqrestore(&priv->tx_lock,flag);
6406 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
6407 void rtl8180_tx_irq_wq(struct work_struct *work)
6409 //struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
6410 struct delayed_work *dwork = container_of(work,struct delayed_work,work);
6411 struct ieee80211_device * ieee = (struct ieee80211_device*)
6412 container_of(dwork, struct ieee80211_device, watch_dog_wq);
6413 struct net_device *dev = ieee->dev;
6415 void rtl8180_tx_irq_wq(struct net_device *dev)
6417 //struct r8180_priv *priv = ieee80211_priv(dev);
6419 rtl8180_tx_isr(dev,MANAGE_PRIORITY,0);
6421 irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs)
6423 struct net_device *dev = (struct net_device *) netdev;
6424 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
6425 unsigned long flags;
6428 /* We should return IRQ_NONE, but for now let me keep this */
6429 if(priv->irq_enabled == 0) return IRQ_HANDLED;
6431 spin_lock_irqsave(&priv->irq_th_lock,flags);
6433 #ifdef CONFIG_RTL8185B
6435 inta = read_nic_dword(dev, ISR);// & priv->IntrMask;
6436 write_nic_dword(dev,ISR,inta); // reset int situation
6438 inta = read_nic_word(dev,INTA) & priv->irq_mask;
6439 write_nic_word(dev,INTA,inta); // reset int situation
6442 priv->stats.shints++;
6444 //DMESG("Enter interrupt, ISR value = 0x%08x", inta);
6447 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6450 most probably we can safely return IRQ_NONE,
6451 but for now is better to avoid problems
6457 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6463 DMESG("NIC irq %x",inta);
6465 //priv->irqpending = inta;
6468 if(!netif_running(dev)) {
6469 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6473 if(inta & ISR_TimeOut){
6474 write_nic_dword(dev, TimerInt, 0);
6475 //DMESG("=================>waking up");
6476 // rtl8180_hw_wakeup(dev);
6479 if(inta & ISR_TBDOK){
6480 priv->stats.txbeacon++;
6483 if(inta & ISR_TBDER){
6484 priv->stats.txbeaconerr++;
6487 if(inta & IMR_TMGDOK ) {
6488 // priv->NumTxOkTotal++;
6489 rtl8180_tx_isr(dev,MANAGE_PRIORITY,0);
6490 // schedule_work(&priv->tx_irq_wq);
6494 if(inta & ISR_THPDER){
6496 DMESG ("TX high priority ERR");
6498 priv->stats.txhperr++;
6499 rtl8180_tx_isr(dev,HI_PRIORITY,1);
6500 priv->ieee80211->stats.tx_errors++;
6503 if(inta & ISR_THPDOK){ //High priority tx ok
6505 DMESG ("TX high priority OK");
6507 // priv->NumTxOkTotal++;
6508 //priv->NumTxOkInPeriod++; //YJ,del,080828
6509 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6510 priv->stats.txhpokint++;
6511 rtl8180_tx_isr(dev,HI_PRIORITY,0);
6514 if(inta & ISR_RER) {
6515 priv->stats.rxerr++;
6517 DMESGW("RX error int");
6520 #ifdef CONFIG_RTL8185B
6521 if(inta & ISR_TBKDER){ //corresponding to BK_PRIORITY
6522 priv->stats.txbkperr++;
6523 priv->ieee80211->stats.tx_errors++;
6525 DMESGW("TX bkp error int");
6527 //tasklet_schedule(&priv->irq_tx_tasklet);
6528 rtl8180_tx_isr(dev,BK_PRIORITY,1);
6529 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6532 if(inta & ISR_TBEDER){ //corresponding to BE_PRIORITY
6533 priv->stats.txbeperr++;
6534 priv->ieee80211->stats.tx_errors++;
6536 DMESGW("TX bep error int");
6538 rtl8180_tx_isr(dev,BE_PRIORITY,1);
6539 //tasklet_schedule(&priv->irq_tx_tasklet);
6540 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6543 if(inta & ISR_TNPDER){ //corresponding to VO_PRIORITY
6544 priv->stats.txnperr++;
6545 priv->ieee80211->stats.tx_errors++;
6547 DMESGW("TX np error int");
6549 //tasklet_schedule(&priv->irq_tx_tasklet);
6550 rtl8180_tx_isr(dev,NORM_PRIORITY,1);
6551 #ifdef CONFIG_RTL8185B
6552 rtl8180_try_wake_queue(dev, NORM_PRIORITY);
6556 if(inta & ISR_TLPDER){ //corresponding to VI_PRIORITY
6557 priv->stats.txlperr++;
6558 priv->ieee80211->stats.tx_errors++;
6560 DMESGW("TX lp error int");
6562 rtl8180_tx_isr(dev,LOW_PRIORITY,1);
6563 //tasklet_schedule(&priv->irq_tx_tasklet);
6564 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
6569 DMESG("Frame arrived !");
6571 //priv->NumRxOkInPeriod++; //YJ,del,080828
6572 priv->stats.rxint++;
6573 tasklet_schedule(&priv->irq_rx_tasklet);
6576 if(inta & ISR_RQoSOK ){
6578 DMESG("QoS Frame arrived !");
6580 //priv->NumRxOkInPeriod++; //YJ,del,080828
6581 priv->stats.rxint++;
6582 tasklet_schedule(&priv->irq_rx_tasklet);
6584 if(inta & ISR_BcnInt) {
6585 //DMESG("Preparing Beacons");
6586 rtl8180_prepare_beacon(dev);
6591 DMESGW("No RX descriptor available");
6592 priv->stats.rxrdu++;
6594 tasklet_schedule(&priv->irq_rx_tasklet);
6595 /*queue_work(priv->workqueue ,&priv->restart_work);*/
6598 if(inta & ISR_RXFOVW){
6600 DMESGW("RX fifo overflow");
6602 priv->stats.rxoverflow++;
6603 tasklet_schedule(&priv->irq_rx_tasklet);
6604 //queue_work(priv->workqueue ,&priv->restart_work);
6607 if(inta & ISR_TXFOVW) priv->stats.txoverflow++;
6609 if(inta & ISR_TNPDOK){ //Normal priority tx ok
6611 DMESG ("TX normal priority OK");
6613 // priv->NumTxOkTotal++;
6614 //priv->NumTxOkInPeriod++; //YJ,del,080828
6615 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6616 // priv->ieee80211->stats.tx_packets++;
6617 priv->stats.txnpokint++;
6618 rtl8180_tx_isr(dev,NORM_PRIORITY,0);
6621 if(inta & ISR_TLPDOK){ //Low priority tx ok
6623 DMESG ("TX low priority OK");
6625 // priv->NumTxOkTotal++;
6626 //priv->NumTxOkInPeriod++; //YJ,del,080828
6627 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6628 // priv->ieee80211->stats.tx_packets++;
6629 priv->stats.txlpokint++;
6630 rtl8180_tx_isr(dev,LOW_PRIORITY,0);
6631 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
6634 #ifdef CONFIG_RTL8185B
6635 if(inta & ISR_TBKDOK){ //corresponding to BK_PRIORITY
6636 priv->stats.txbkpokint++;
6638 DMESGW("TX bk priority ok");
6640 // priv->NumTxOkTotal++;
6641 //priv->NumTxOkInPeriod++; //YJ,del,080828
6642 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6643 rtl8180_tx_isr(dev,BK_PRIORITY,0);
6644 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6647 if(inta & ISR_TBEDOK){ //corresponding to BE_PRIORITY
6648 priv->stats.txbeperr++;
6650 DMESGW("TX be priority ok");
6652 // priv->NumTxOkTotal++;
6653 //priv->NumTxOkInPeriod++; //YJ,del,080828
6654 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6655 rtl8180_tx_isr(dev,BE_PRIORITY,0);
6656 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6659 force_pci_posting(dev);
6660 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6666 void rtl8180_irq_rx_tasklet(struct r8180_priv* priv)
6668 // unsigned long flags;
6670 /* spin_lock_irqsave(&priv->irq_lock, flags);
6671 priv->irq_mask &=~IMR_ROK;
6672 priv->irq_mask &=~IMR_RDU;
6674 rtl8180_irq_enable(priv->dev);
6675 spin_unlock_irqrestore(&priv->irq_lock, flags);
6677 rtl8180_rx(priv->dev);
6679 /* spin_lock_irqsave(&priv->irq_lock, flags);
6680 priv->irq_mask |= IMR_ROK;
6681 priv->irq_mask |= IMR_RDU;
6682 rtl8180_irq_enable(priv->dev);
6683 spin_unlock_irqrestore(&priv->irq_lock, flags);
6687 /****************************************************************************
6688 lizhaoming--------------------------- RF power on/power off -----------------
6689 *****************************************************************************/
6691 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
6692 void GPIOChangeRFWorkItemCallBack(struct work_struct *work)
6694 //struct delayed_work *dwork = container_of(work, struct delayed_work, work);
6695 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, GPIOChangeRFWorkItem.work);
6696 struct net_device *dev = ieee->dev;
6697 struct r8180_priv *priv = ieee80211_priv(dev);
6699 void GPIOChangeRFWorkItemCallBack(struct ieee80211_device *ieee)
6701 struct net_device *dev = ieee->dev;
6702 struct r8180_priv *priv = ieee80211_priv(dev);
6708 RT_RF_POWER_STATE eRfPowerStateToSet;
6709 bool bActuallySet=false;
6712 static char *RadioPowerPath = "/etc/acpi/events/RadioPower.sh";
6713 static char *envp[] = {"HOME=/", "TERM=linux", "PATH=/usr/bin:/bin", NULL};
6714 static int readf_count = 0;
6715 //printk("============>%s in \n", __func__);
6718 if(readf_count % 10 == 0)
6719 priv->PowerProfile = read_acadapter_file("/proc/acpi/ac_adapter/AC0/state");
6721 readf_count = (readf_count+1)%0xffff;
6724 if(priv->up == 0)//driver stopped
6726 printk("\nDo nothing...");
6732 // We should turn off LED before polling FF51[4].
6735 btPSR = read_nic_byte(dev, PSR);
6736 write_nic_byte(dev, PSR, (btPSR & ~BIT3));
6738 //It need to delay 4us suggested by Jong, 2008-01-16
6741 //HW radio On/Off according to the value of FF51[4](config0)
6742 btConfig0 = btPSR = read_nic_byte(dev, CONFIG0);
6745 write_nic_byte(dev, PSR, btPSR| BIT3);
6747 eRfPowerStateToSet = (btConfig0 & BIT4) ? eRfOn : eRfOff;
6749 if((priv->ieee80211->bHwRadioOff == true) && (eRfPowerStateToSet == eRfOn))
6751 priv->ieee80211->bHwRadioOff = false;
6752 bActuallySet = true;
6754 else if((priv->ieee80211->bHwRadioOff == false) && (eRfPowerStateToSet == eRfOff))
6756 priv->ieee80211->bHwRadioOff = true;
6757 bActuallySet = true;
6762 MgntActSet_RF_State(dev, eRfPowerStateToSet, RF_CHANGE_BY_HW);
6764 /* To update the UI status for Power status changed */
6765 if(priv->ieee80211->bHwRadioOff == true)
6768 //if(!priv->RfOffReason)
6771 // argv[1] = "RFOFF";
6773 argv[0] = RadioPowerPath;
6776 call_usermodehelper(RadioPowerPath,argv,envp,1);
6783 static u8 read_acadapter_file(char *filename)
6785 //#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21))
6792 mm_segment_t old_fs = get_fs();
6795 fd = sys_open(filename, O_RDONLY, 0);
6797 while (sys_read(fd, buf, 1) == 1)
6812 // printk("%s \n", ret);
6815 if(strncmp(ret, "off-line",8) == 0)
6823 /***************************************************************************
6824 ------------------- module init / exit stubs ----------------
6825 ****************************************************************************/
6826 module_init(rtl8180_pci_module_init);
6827 module_exit(rtl8180_pci_module_exit);