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 = rtl8180_proc;
644 if (!priv->dir_dev) {
645 DMESGE("Unable to initialize /proc/net/r8180/%s\n",
650 e = create_proc_read_entry("stats-hw", S_IFREG | S_IRUGO,
651 priv->dir_dev, proc_get_stats_hw, dev);
654 DMESGE("Unable to initialize "
655 "/proc/net/r8180/%s/stats-hw\n",
659 e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
660 priv->dir_dev, proc_get_stats_rx, dev);
663 DMESGE("Unable to initialize "
664 "/proc/net/r8180/%s/stats-rx\n",
669 e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
670 priv->dir_dev, proc_get_stats_tx, dev);
673 DMESGE("Unable to initialize "
674 "/proc/net/r8180/%s/stats-tx\n",
678 e = create_proc_read_entry("stats-ieee", S_IFREG | S_IRUGO,
679 priv->dir_dev, proc_get_stats_ieee, dev);
682 DMESGE("Unable to initialize "
683 "/proc/net/rtl8180/%s/stats-ieee\n",
688 e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO,
689 priv->dir_dev, proc_get_stats_ap, dev);
692 DMESGE("Unable to initialize "
693 "/proc/net/rtl8180/%s/stats-ap\n",
698 e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
699 priv->dir_dev, proc_get_registers, dev);
702 DMESGE("Unable to initialize "
703 "/proc/net/r8180/%s/registers\n",
707 /****************************************************************************
708 -----------------------------MISC STUFF-------------------------
709 *****************************************************************************/
711 FIXME: check if we can use some standard already-existent
712 data type+functions in kernel
715 short buffer_add(struct buffer **buffer, u32 *buf, dma_addr_t dma,
716 struct buffer **bufferhead)
719 DMESG("adding buffer to TX/RX struct");
726 *buffer = kmalloc(sizeof(struct buffer),GFP_KERNEL);
728 if (*buffer == NULL) {
729 DMESGE("Failed to kmalloc head of TX/RX struct");
732 (*buffer)->next=*buffer;
735 if(bufferhead !=NULL)
736 (*bufferhead) = (*buffer);
741 while(tmp->next!=(*buffer)) tmp=tmp->next;
742 if ((tmp->next= kmalloc(sizeof(struct buffer),GFP_KERNEL)) == NULL){
743 DMESGE("Failed to kmalloc TX/RX struct");
748 tmp->next->next=*buffer;
754 void buffer_free(struct net_device *dev,struct buffer **buffer,int len,short
758 struct buffer *tmp,*next;
759 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
760 struct pci_dev *pdev=priv->pdev;
763 if(! *buffer) return;
765 /*for(tmp=*buffer; tmp->next != *buffer; tmp=tmp->next)
772 pci_free_consistent(pdev,len,
775 pci_unmap_single(pdev, tmp->dma,
776 len,PCI_DMA_FROMDEVICE);
782 while(next != *buffer);
788 void print_buffer(u32 *buffer, int len)
791 u8 *buf =(u8*)buffer;
793 printk("ASCII BUFFER DUMP (len: %x):\n",len);
798 printk("\nBINARY BUFFER DUMP (len: %x):\n",len);
801 printk("%02x",buf[i]);
807 int get_curr_tx_free_desc(struct net_device *dev, int priority)
809 struct r8180_priv *priv = ieee80211_priv(dev);
815 case MANAGE_PRIORITY:
816 head = priv->txmapringhead;
817 tail = priv->txmapringtail;
820 head = priv->txbkpringhead;
821 tail = priv->txbkpringtail;
824 head = priv->txbepringhead;
825 tail = priv->txbepringtail;
828 head = priv->txvipringhead;
829 tail = priv->txvipringtail;
832 head = priv->txvopringhead;
833 tail = priv->txvopringtail;
836 head = priv->txhpringhead;
837 tail = priv->txhpringtail;
843 //DMESG("%x %x", head, tail);
845 /* FIXME FIXME FIXME FIXME */
848 if( head <= tail ) return priv->txringcount-1 - (tail - head)/8;
849 return (head - tail)/8/4;
852 ret = priv->txringcount - (tail - head)/8;
854 ret = (head - tail)/8;
856 if(ret > priv->txringcount ) DMESG("BUG");
862 short check_nic_enought_desc(struct net_device *dev, int priority)
864 struct r8180_priv *priv = ieee80211_priv(dev);
865 struct ieee80211_device *ieee = netdev_priv(dev);
867 int requiredbyte, required;
868 requiredbyte = priv->ieee80211->fts + sizeof(struct ieee80211_header_data);
870 if(ieee->current_network.QoS_Enable) {
874 required = requiredbyte / (priv->txbuffsize-4);
875 if (requiredbyte % priv->txbuffsize) required++;
876 /* for now we keep two free descriptor as a safety boundary
877 * between the tail and the head
880 return (required+2 < get_curr_tx_free_desc(dev,priority));
884 /* This function is only for debuging purpose */
885 void check_tx_ring(struct net_device *dev, int pri)
887 static int maxlog =3;
888 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
897 struct buffer* buffer;
900 if (maxlog <0 ) return;
903 case MANAGE_PRIORITY:
904 tail = priv->txmapringtail;
905 begin = priv->txmapring;
906 head = priv->txmapringhead;
907 nic = read_nic_dword(dev,TX_MANAGEPRIORITY_RING_ADDR);
908 buffer = priv->txmapbufs;
909 nicbegin = priv->txmapringdma;
914 tail = priv->txbkpringtail;
915 begin = priv->txbkpring;
916 head = priv->txbkpringhead;
917 nic = read_nic_dword(dev,TX_BKPRIORITY_RING_ADDR);
918 buffer = priv->txbkpbufs;
919 nicbegin = priv->txbkpringdma;
923 tail = priv->txbepringtail;
924 begin = priv->txbepring;
925 head = priv->txbepringhead;
926 nic = read_nic_dword(dev,TX_BEPRIORITY_RING_ADDR);
927 buffer = priv->txbepbufs;
928 nicbegin = priv->txbepringdma;
932 tail = priv->txvipringtail;
933 begin = priv->txvipring;
934 head = priv->txvipringhead;
935 nic = read_nic_dword(dev,TX_VIPRIORITY_RING_ADDR);
936 buffer = priv->txvipbufs;
937 nicbegin = priv->txvipringdma;
942 tail = priv->txvopringtail;
943 begin = priv->txvopring;
944 head = priv->txvopringhead;
945 nic = read_nic_dword(dev,TX_VOPRIORITY_RING_ADDR);
946 buffer = priv->txvopbufs;
947 nicbegin = priv->txvopringdma;
951 tail = priv->txhpringtail;
952 begin = priv->txhpring;
953 head = priv->txhpringhead;
954 nic = read_nic_dword(dev,TX_HIGHPRIORITY_RING_ADDR);
955 buffer = priv->txhpbufs;
956 nicbegin = priv->txhpringdma;
965 DMESGE ("NIC TX ack, but TX queue corrupted!");
968 for(i=0,buf=buffer, tmp=begin;
969 tmp<begin+(priv->txringcount)*8;
970 tmp+=8,buf=buf->next,i++)
972 DMESG("BUF%d %s %x %s. Next : %x",i,
973 *tmp & (1<<31) ? "filled" : "empty",
975 *tmp & (1<<15)? "ok": "err", *(tmp+4));
983 /* this function is only for debugging purpose */
984 void check_rxbuf(struct net_device *dev)
986 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
991 #ifdef CONFIG_RTL8185B
998 DMESGE ("NIC RX ack, but RX queue corrupted!");
1002 for(buf=priv->rxbuffer, tmp=priv->rxring;
1003 tmp < priv->rxring+(priv->rxringcount)*rx_desc_size;
1004 tmp+=rx_desc_size, buf=buf->next)
1007 *tmp & (1<<31) ? "empty" : "filled",
1015 void dump_eprom(struct net_device *dev)
1019 DMESG("EEPROM addr %x : %x", i, eprom_read(dev,i));
1023 void rtl8180_dump_reg(struct net_device *dev)
1029 DMESG("Dumping NIC register map");
1033 printk( "\nD: %2x> ", n);
1034 for(i=0;i<16 && n<=max;i++,n++)
1035 printk("%2x ",read_nic_byte(dev,n));
1041 void fix_tx_fifo(struct net_device *dev)
1043 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1046 #ifdef DEBUG_TX_ALLOC
1047 DMESG("FIXING TX FIFOs");
1049 for (tmp=priv->txmapring, i=0;
1050 i < priv->txringcount;
1052 *tmp = *tmp &~ (1<<31);
1055 for (tmp=priv->txbkpring, i=0;
1056 i < priv->txringcount;
1058 *tmp = *tmp &~ (1<<31);
1061 for (tmp=priv->txbepring, i=0;
1062 i < priv->txringcount;
1064 *tmp = *tmp &~ (1<<31);
1066 for (tmp=priv->txvipring, i=0;
1067 i < priv->txringcount;
1069 *tmp = *tmp &~ (1<<31);
1072 for (tmp=priv->txvopring, i=0;
1073 i < priv->txringcount;
1075 *tmp = *tmp &~ (1<<31);
1078 for (tmp=priv->txhpring, i=0;
1079 i < priv->txringcount;
1081 *tmp = *tmp &~ (1<<31);
1084 for (tmp=priv->txbeaconring, i=0;
1085 i < priv->txbeaconcount;
1087 *tmp = *tmp &~ (1<<31);
1089 #ifdef DEBUG_TX_ALLOC
1090 DMESG("TX FIFOs FIXED");
1092 priv->txmapringtail = priv->txmapring;
1093 priv->txmapringhead = priv->txmapring;
1094 priv->txmapbufstail = priv->txmapbufs;
1096 priv->txbkpringtail = priv->txbkpring;
1097 priv->txbkpringhead = priv->txbkpring;
1098 priv->txbkpbufstail = priv->txbkpbufs;
1100 priv->txbepringtail = priv->txbepring;
1101 priv->txbepringhead = priv->txbepring;
1102 priv->txbepbufstail = priv->txbepbufs;
1104 priv->txvipringtail = priv->txvipring;
1105 priv->txvipringhead = priv->txvipring;
1106 priv->txvipbufstail = priv->txvipbufs;
1108 priv->txvopringtail = priv->txvopring;
1109 priv->txvopringhead = priv->txvopring;
1110 priv->txvopbufstail = priv->txvopbufs;
1112 priv->txhpringtail = priv->txhpring;
1113 priv->txhpringhead = priv->txhpring;
1114 priv->txhpbufstail = priv->txhpbufs;
1116 priv->txbeaconringtail = priv->txbeaconring;
1117 priv->txbeaconbufstail = priv->txbeaconbufs;
1118 set_nic_txring(dev);
1120 ieee80211_reset_queue(priv->ieee80211);
1121 priv->ack_tx_to_ieee = 0;
1125 void fix_rx_fifo(struct net_device *dev)
1127 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1129 struct buffer *rxbuf;
1132 #ifdef CONFIG_RTL8185B
1133 rx_desc_size = 8; // 4*8 = 32 bytes
1138 #ifdef DEBUG_RXALLOC
1139 DMESG("FIXING RX FIFO");
1143 for (tmp=priv->rxring, rxbuf=priv->rxbufferhead;
1144 (tmp < (priv->rxring)+(priv->rxringcount)*rx_desc_size);
1145 tmp+=rx_desc_size,rxbuf=rxbuf->next){
1146 *(tmp+2) = rxbuf->dma;
1148 *tmp=*tmp | priv->rxbuffersize;
1152 #ifdef DEBUG_RXALLOC
1153 DMESG("RX FIFO FIXED");
1157 priv->rxringtail=priv->rxring;
1158 priv->rxbuffer=priv->rxbufferhead;
1159 priv->rx_skb_complete=1;
1160 set_nic_rxring(dev);
1164 /****************************************************************************
1165 ------------------------------HW STUFF---------------------------
1166 *****************************************************************************/
1168 unsigned char QUALITY_MAP[] = {
1169 0x64, 0x64, 0x64, 0x63, 0x63, 0x62, 0x62, 0x61,
1170 0x61, 0x60, 0x60, 0x5f, 0x5f, 0x5e, 0x5d, 0x5c,
1171 0x5b, 0x5a, 0x59, 0x57, 0x56, 0x54, 0x52, 0x4f,
1172 0x4c, 0x49, 0x45, 0x41, 0x3c, 0x37, 0x31, 0x29,
1173 0x24, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
1174 0x22, 0x22, 0x21, 0x21, 0x21, 0x21, 0x21, 0x20,
1175 0x20, 0x20, 0x20, 0x1f, 0x1f, 0x1e, 0x1e, 0x1e,
1176 0x1d, 0x1d, 0x1c, 0x1c, 0x1b, 0x1a, 0x19, 0x19,
1177 0x18, 0x17, 0x16, 0x15, 0x14, 0x12, 0x11, 0x0f,
1178 0x0e, 0x0c, 0x0a, 0x08, 0x06, 0x04, 0x01, 0x00
1181 unsigned char STRENGTH_MAP[] = {
1182 0x64, 0x64, 0x63, 0x62, 0x61, 0x60, 0x5f, 0x5e,
1183 0x5d, 0x5c, 0x5b, 0x5a, 0x57, 0x54, 0x52, 0x50,
1184 0x4e, 0x4c, 0x4a, 0x48, 0x46, 0x44, 0x41, 0x3f,
1185 0x3c, 0x3a, 0x37, 0x36, 0x36, 0x1c, 0x1c, 0x1b,
1186 0x1b, 0x1a, 0x1a, 0x19, 0x19, 0x18, 0x18, 0x17,
1187 0x17, 0x16, 0x16, 0x15, 0x15, 0x14, 0x14, 0x13,
1188 0x13, 0x12, 0x12, 0x11, 0x11, 0x10, 0x10, 0x0f,
1189 0x0f, 0x0e, 0x0e, 0x0d, 0x0d, 0x0c, 0x0c, 0x0b,
1190 0x0b, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x07,
1191 0x07, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x00
1194 void rtl8180_RSSI_calc(struct net_device *dev, u8 *rssi, u8 *qual){
1195 //void Mlme_UpdateRssiSQ(struct net_device *dev, u8 *rssi, u8 *qual){
1196 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1207 _rssi = 0; // avoid gcc complains..
1210 temp = QUALITY_MAP[q];
1222 switch(priv->rf_chip){
1226 if ( !lsb || !(temp2 <= 0x3c) ) {
1229 temp2 = 100 * temp2 / 0x3c;
1231 *rssi = temp2 & 0xff;
1232 _rssi = temp2 & 0xff;
1234 case RFCHIPID_INTERSIL:
1236 temp2 &= 0xfffffffe;
1245 if ( temp2 <= 0x3e0000 ) {
1246 if ( temp2 < 0xffef0000 )
1260 temp3 = temp3 / 0x6d;
1262 _rssi = temp3 & 0xff;
1263 *rssi = temp3 & 0xff;
1268 if ( ! lsb || !(temp2 <= 0x3c) ){
1271 temp2 = (100 * temp2) / 0x3c;
1273 *rssi = temp2 & 0xff;
1274 _rssi = temp2 & 0xff;
1276 case RFCHIPID_PHILIPS:
1277 if( orig_qual <= 0x4e ){
1278 _rssi = STRENGTH_MAP[orig_qual];
1293 case RFCHIPID_MAXIM:
1301 *rssi = temp2 & 0xff;
1302 _rssi = temp2 & 0xff;
1306 if ( _rssi < 0x64 ){
1318 void rtl8180_irq_enable(struct net_device *dev)
1320 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1321 priv->irq_enabled = 1;
1323 write_nic_word(dev,INTA_MASK,INTA_RXOK | INTA_RXDESCERR | INTA_RXOVERFLOW |\
1324 INTA_TXOVERFLOW | INTA_HIPRIORITYDESCERR | INTA_HIPRIORITYDESCOK |\
1325 INTA_NORMPRIORITYDESCERR | INTA_NORMPRIORITYDESCOK |\
1326 INTA_LOWPRIORITYDESCERR | INTA_LOWPRIORITYDESCOK | INTA_TIMEOUT);
1328 write_nic_word(dev,INTA_MASK, priv->irq_mask);
1332 void rtl8180_irq_disable(struct net_device *dev)
1334 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1336 #ifdef CONFIG_RTL8185B
1337 write_nic_dword(dev,IMR,0);
1339 write_nic_word(dev,INTA_MASK,0);
1341 force_pci_posting(dev);
1342 priv->irq_enabled = 0;
1346 void rtl8180_set_mode(struct net_device *dev,int mode)
1349 ecmd=read_nic_byte(dev, EPROM_CMD);
1350 ecmd=ecmd &~ EPROM_CMD_OPERATING_MODE_MASK;
1351 ecmd=ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
1352 ecmd=ecmd &~ (1<<EPROM_CS_SHIFT);
1353 ecmd=ecmd &~ (1<<EPROM_CK_SHIFT);
1354 write_nic_byte(dev, EPROM_CMD, ecmd);
1357 void rtl8180_adapter_start(struct net_device *dev);
1358 void rtl8180_beacon_tx_enable(struct net_device *dev);
1360 void rtl8180_update_msr(struct net_device *dev)
1362 struct r8180_priv *priv = ieee80211_priv(dev);
1366 msr = read_nic_byte(dev, MSR);
1367 msr &= ~ MSR_LINK_MASK;
1369 rxconf=read_nic_dword(dev,RX_CONF);
1371 if(priv->ieee80211->state == IEEE80211_LINKED)
1373 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1374 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
1375 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
1376 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
1377 else if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
1378 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
1380 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
1381 rxconf |= (1<<RX_CHECK_BSSID_SHIFT);
1384 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
1385 rxconf &= ~(1<<RX_CHECK_BSSID_SHIFT);
1388 write_nic_byte(dev, MSR, msr);
1389 write_nic_dword(dev, RX_CONF, rxconf);
1395 void rtl8180_set_chan(struct net_device *dev,short ch)
1397 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1399 if((ch > 14) || (ch < 1))
1401 printk("In %s: Invalid chnanel %d\n", __func__, ch);
1406 //printk("in %s:channel is %d\n",__func__,ch);
1407 priv->rf_set_chan(dev,priv->chan);
1412 void rtl8180_rx_enable(struct net_device *dev)
1416 /* for now we accept data, management & ctl frame*/
1417 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1419 rxconf=read_nic_dword(dev,RX_CONF);
1420 rxconf = rxconf &~ MAC_FILTER_MASK;
1421 rxconf = rxconf | (1<<ACCEPT_MNG_FRAME_SHIFT);
1422 rxconf = rxconf | (1<<ACCEPT_DATA_FRAME_SHIFT);
1423 rxconf = rxconf | (1<<ACCEPT_BCAST_FRAME_SHIFT);
1424 rxconf = rxconf | (1<<ACCEPT_MCAST_FRAME_SHIFT);
1425 // rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
1426 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
1428 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
1429 dev->flags & IFF_PROMISC){
1430 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
1432 rxconf = rxconf | (1<<ACCEPT_NICMAC_FRAME_SHIFT);
1433 if(priv->card_8185 == 0)
1434 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
1437 /*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
1438 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
1439 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
1442 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
1443 rxconf = rxconf | (1<<ACCEPT_CTL_FRAME_SHIFT);
1444 rxconf = rxconf | (1<<ACCEPT_ICVERR_FRAME_SHIFT);
1445 rxconf = rxconf | (1<<ACCEPT_PWR_FRAME_SHIFT);
1448 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
1449 rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
1451 //if(!priv->card_8185){
1452 rxconf = rxconf &~ RX_FIFO_THRESHOLD_MASK;
1453 rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
1456 rxconf = rxconf | (1<<RX_AUTORESETPHY_SHIFT);
1457 rxconf = rxconf &~ MAX_RX_DMA_MASK;
1458 rxconf = rxconf | (MAX_RX_DMA_2048<<MAX_RX_DMA_SHIFT);
1460 //if(!priv->card_8185)
1461 rxconf = rxconf | RCR_ONLYERLPKT;
1463 rxconf = rxconf &~ RCR_CS_MASK;
1464 if(!priv->card_8185)
1465 rxconf |= (priv->rcr_csense<<RCR_CS_SHIFT);
1466 // rxconf &=~ 0xfff00000;
1467 // rxconf |= 0x90100000;//9014f76f;
1468 write_nic_dword(dev, RX_CONF, rxconf);
1473 DMESG("rxconf: %x %x",rxconf ,read_nic_dword(dev,RX_CONF));
1475 cmd=read_nic_byte(dev,CMD);
1476 write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
1478 /* In rtl8139 driver seems that DMA threshold has to be written
1479 * after enabling RX, so we rewrite RX_CONFIG register
1482 // write_nic_dword(dev, RX_CONF, rxconf);
1487 void set_nic_txring(struct net_device *dev)
1489 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1490 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1492 write_nic_dword(dev, TX_MANAGEPRIORITY_RING_ADDR, priv->txmapringdma);
1493 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1494 write_nic_dword(dev, TX_BKPRIORITY_RING_ADDR, priv->txbkpringdma);
1495 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1496 write_nic_dword(dev, TX_BEPRIORITY_RING_ADDR, priv->txbepringdma);
1497 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1498 write_nic_dword(dev, TX_VIPRIORITY_RING_ADDR, priv->txvipringdma);
1499 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1500 write_nic_dword(dev, TX_VOPRIORITY_RING_ADDR, priv->txvopringdma);
1501 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1502 write_nic_dword(dev, TX_HIGHPRIORITY_RING_ADDR, priv->txhpringdma);
1503 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1505 write_nic_dword(dev, TX_BEACON_RING_ADDR, priv->txbeaconringdma);
1509 void rtl8180_conttx_enable(struct net_device *dev)
1512 txconf = read_nic_dword(dev,TX_CONF);
1513 txconf = txconf &~ TX_LOOPBACK_MASK;
1514 txconf = txconf | (TX_LOOPBACK_CONTINUE <<TX_LOOPBACK_SHIFT);
1515 write_nic_dword(dev,TX_CONF,txconf);
1519 void rtl8180_conttx_disable(struct net_device *dev)
1522 txconf = read_nic_dword(dev,TX_CONF);
1523 txconf = txconf &~ TX_LOOPBACK_MASK;
1524 txconf = txconf | (TX_LOOPBACK_NONE <<TX_LOOPBACK_SHIFT);
1525 write_nic_dword(dev,TX_CONF,txconf);
1529 void rtl8180_tx_enable(struct net_device *dev)
1535 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1536 txconf= read_nic_dword(dev,TX_CONF);
1539 if(priv->card_8185){
1542 byte = read_nic_byte(dev,CW_CONF);
1543 byte &= ~(1<<CW_CONF_PERPACKET_CW_SHIFT);
1544 byte &= ~(1<<CW_CONF_PERPACKET_RETRY_SHIFT);
1545 write_nic_byte(dev, CW_CONF, byte);
1547 tx_agc_ctl = read_nic_byte(dev, TX_AGC_CTL);
1548 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_GAIN_SHIFT);
1549 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT);
1550 tx_agc_ctl |=(1<<TX_AGC_CTL_FEEDBACK_ANT);
1551 write_nic_byte(dev, TX_AGC_CTL, tx_agc_ctl);
1553 write_nic_word(dev, 0x5e, 0x01);
1554 force_pci_posting(dev);
1556 write_nic_word(dev, 0xfe, 0x10);
1557 force_pci_posting(dev);
1559 write_nic_word(dev, 0x5e, 0x00);
1560 force_pci_posting(dev);
1563 write_nic_byte(dev, 0xec, 0x3f); /* Disable early TX */
1566 if(priv->card_8185){
1568 txconf = txconf &~ (1<<TCR_PROBE_NOTIMESTAMP_SHIFT);
1573 txconf= txconf &~ (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
1575 txconf= txconf | (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
1578 txconf = txconf &~ TX_LOOPBACK_MASK;
1579 txconf = txconf | (TX_LOOPBACK_NONE <<TX_LOOPBACK_SHIFT);
1580 txconf = txconf &~ TCR_DPRETRY_MASK;
1581 txconf = txconf &~ TCR_RTSRETRY_MASK;
1582 txconf = txconf | (priv->retry_data<<TX_DPRETRY_SHIFT);
1583 txconf = txconf | (priv->retry_rts<<TX_RTSRETRY_SHIFT);
1584 txconf = txconf &~ (1<<TX_NOCRC_SHIFT);
1586 if(priv->card_8185){
1587 if(priv->hw_plcp_len)
1588 txconf = txconf &~ TCR_PLCP_LEN;
1590 txconf = txconf | TCR_PLCP_LEN;
1592 txconf = txconf &~ TCR_SAT;
1594 txconf = txconf &~ TCR_MXDMA_MASK;
1595 txconf = txconf | (TCR_MXDMA_2048<<TCR_MXDMA_SHIFT);
1596 txconf = txconf | TCR_CWMIN;
1597 txconf = txconf | TCR_DISCW;
1599 // if(priv->ieee80211->hw_wep)
1600 // txconf=txconf &~ (1<<TX_NOICV_SHIFT);
1602 txconf=txconf | (1<<TX_NOICV_SHIFT);
1604 write_nic_dword(dev,TX_CONF,txconf);
1610 DMESG("txconf: %x %x",txconf,read_nic_dword(dev,TX_CONF));
1613 cmd=read_nic_byte(dev,CMD);
1614 write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));
1617 write_nic_dword(dev,TX_CONF,txconf);
1620 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1621 write_nic_byte(dev, TX_DMA_POLLING, priv->dma_poll_mask);
1622 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1627 void rtl8180_beacon_tx_enable(struct net_device *dev)
1629 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1631 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1632 #ifdef CONFIG_RTL8185B
1633 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_BQ);
1634 write_nic_byte(dev,TPPollStop, priv->dma_poll_mask);
1636 priv->dma_poll_mask &=~(1<<TX_DMA_STOP_BEACON_SHIFT);
1637 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1639 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1643 void rtl8180_beacon_tx_disable(struct net_device *dev)
1645 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1647 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1648 #ifdef CONFIG_RTL8185B
1649 priv->dma_poll_stop_mask |= TPPOLLSTOP_BQ;
1650 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
1652 priv->dma_poll_mask |= (1<<TX_DMA_STOP_BEACON_SHIFT);
1653 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
1655 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1660 void rtl8180_rtx_disable(struct net_device *dev)
1663 struct r8180_priv *priv = ieee80211_priv(dev);
1665 cmd=read_nic_byte(dev,CMD);
1666 write_nic_byte(dev, CMD, cmd &~ \
1667 ((1<<CMD_RX_ENABLE_SHIFT)|(1<<CMD_TX_ENABLE_SHIFT)));
1668 force_pci_posting(dev);
1670 /*while (read_nic_byte(dev,CMD) & (1<<CMD_RX_ENABLE_SHIFT))
1674 if(!priv->rx_skb_complete)
1675 dev_kfree_skb_any(priv->rx_skb);
1679 int alloc_tx_beacon_desc_ring(struct net_device *dev, int count)
1683 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1685 priv->txbeaconring = (u32*)pci_alloc_consistent(priv->pdev,
1686 sizeof(u32)*8*count,
1687 &priv->txbeaconringdma);
1688 if (!priv->txbeaconring) return -1;
1689 for (tmp=priv->txbeaconring,i=0;i<count;i++){
1690 *tmp = *tmp &~ (1<<31); // descriptor empty, owned by the drv
1692 *(tmp+2) = (u32)dma_tmp;
1696 *(tmp+4) = (u32)priv->txbeaconringdma+((i+1)*8*4);
1698 *(tmp+4) = (u32)priv->txbeaconringdma;
1706 short alloc_tx_desc_ring(struct net_device *dev, int bufsize, int count,
1712 dma_addr_t dma_desc, dma_tmp;
1713 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1714 struct pci_dev *pdev = priv->pdev;
1717 if((bufsize & 0xfff) != bufsize) {
1718 DMESGE ("TX buffer allocation too large");
1721 desc = (u32*)pci_alloc_consistent(pdev,
1722 sizeof(u32)*8*count+256, &dma_desc);
1723 if(desc==NULL) return -1;
1724 if(dma_desc & 0xff){
1727 * descriptor's buffer must be 256 byte aligned
1728 * we shouldn't be here, since we set DMA mask !
1730 WARN(1, "DMA buffer is not aligned\n");
1733 for (i=0;i<count;i++)
1735 buf = (void*)pci_alloc_consistent(pdev,bufsize,&dma_tmp);
1736 if (buf == NULL) return -ENOMEM;
1740 case TX_NORMPRIORITY_RING_ADDR:
1741 if(-1 == buffer_add(&(priv->txnpbufs),buf,dma_tmp,NULL)){
1742 DMESGE("Unable to allocate mem for buffer NP");
1747 case TX_LOWPRIORITY_RING_ADDR:
1748 if(-1 == buffer_add(&(priv->txlpbufs),buf,dma_tmp,NULL)){
1749 DMESGE("Unable to allocate mem for buffer LP");
1754 case TX_HIGHPRIORITY_RING_ADDR:
1755 if(-1 == buffer_add(&(priv->txhpbufs),buf,dma_tmp,NULL)){
1756 DMESGE("Unable to allocate mem for buffer HP");
1761 case TX_MANAGEPRIORITY_RING_ADDR:
1762 if(-1 == buffer_add(&(priv->txmapbufs),buf,dma_tmp,NULL)){
1763 DMESGE("Unable to allocate mem for buffer NP");
1768 case TX_BKPRIORITY_RING_ADDR:
1769 if(-1 == buffer_add(&(priv->txbkpbufs),buf,dma_tmp,NULL)){
1770 DMESGE("Unable to allocate mem for buffer LP");
1774 case TX_BEPRIORITY_RING_ADDR:
1775 if(-1 == buffer_add(&(priv->txbepbufs),buf,dma_tmp,NULL)){
1776 DMESGE("Unable to allocate mem for buffer NP");
1781 case TX_VIPRIORITY_RING_ADDR:
1782 if(-1 == buffer_add(&(priv->txvipbufs),buf,dma_tmp,NULL)){
1783 DMESGE("Unable to allocate mem for buffer LP");
1787 case TX_VOPRIORITY_RING_ADDR:
1788 if(-1 == buffer_add(&(priv->txvopbufs),buf,dma_tmp,NULL)){
1789 DMESGE("Unable to allocate mem for buffer NP");
1794 case TX_HIGHPRIORITY_RING_ADDR:
1795 if(-1 == buffer_add(&(priv->txhpbufs),buf,dma_tmp,NULL)){
1796 DMESGE("Unable to allocate mem for buffer HP");
1800 case TX_BEACON_RING_ADDR:
1801 if(-1 == buffer_add(&(priv->txbeaconbufs),buf,dma_tmp,NULL)){
1802 DMESGE("Unable to allocate mem for buffer BP");
1807 *tmp = *tmp &~ (1<<31); // descriptor empty, owned by the drv
1808 *(tmp+2) = (u32)dma_tmp;
1812 *(tmp+4) = (u32)dma_desc+((i+1)*8*4);
1814 *(tmp+4) = (u32)dma_desc;
1820 case TX_MANAGEPRIORITY_RING_ADDR:
1821 priv->txmapringdma=dma_desc;
1822 priv->txmapring=desc;
1825 case TX_BKPRIORITY_RING_ADDR:
1826 priv->txbkpringdma=dma_desc;
1827 priv->txbkpring=desc;
1830 case TX_BEPRIORITY_RING_ADDR:
1831 priv->txbepringdma=dma_desc;
1832 priv->txbepring=desc;
1835 case TX_VIPRIORITY_RING_ADDR:
1836 priv->txvipringdma=dma_desc;
1837 priv->txvipring=desc;
1840 case TX_VOPRIORITY_RING_ADDR:
1841 priv->txvopringdma=dma_desc;
1842 priv->txvopring=desc;
1845 case TX_HIGHPRIORITY_RING_ADDR:
1846 priv->txhpringdma=dma_desc;
1847 priv->txhpring=desc;
1850 case TX_BEACON_RING_ADDR:
1851 priv->txbeaconringdma=dma_desc;
1852 priv->txbeaconring=desc;
1858 DMESG("Tx dma physical address: %x",dma_desc);
1865 void free_tx_desc_rings(struct net_device *dev)
1868 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1869 struct pci_dev *pdev=priv->pdev;
1870 int count = priv->txringcount;
1872 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1873 priv->txmapring, priv->txmapringdma);
1874 buffer_free(dev,&(priv->txmapbufs),priv->txbuffsize,1);
1876 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1877 priv->txbkpring, priv->txbkpringdma);
1878 buffer_free(dev,&(priv->txbkpbufs),priv->txbuffsize,1);
1880 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1881 priv->txbepring, priv->txbepringdma);
1882 buffer_free(dev,&(priv->txbepbufs),priv->txbuffsize,1);
1884 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1885 priv->txvipring, priv->txvipringdma);
1886 buffer_free(dev,&(priv->txvipbufs),priv->txbuffsize,1);
1888 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1889 priv->txvopring, priv->txvopringdma);
1890 buffer_free(dev,&(priv->txvopbufs),priv->txbuffsize,1);
1892 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1893 priv->txhpring, priv->txhpringdma);
1894 buffer_free(dev,&(priv->txhpbufs),priv->txbuffsize,1);
1896 count = priv->txbeaconcount;
1897 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1898 priv->txbeaconring, priv->txbeaconringdma);
1899 buffer_free(dev,&(priv->txbeaconbufs),priv->txbuffsize,1);
1903 void free_beacon_desc_ring(struct net_device *dev,int count)
1906 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1907 struct pci_dev *pdev=priv->pdev;
1909 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1910 priv->txbeaconring, priv->txbeaconringdma);
1912 if (priv->beacon_buf)
1913 pci_free_consistent(priv->pdev,
1914 priv->master_beaconsize,priv->beacon_buf,priv->beacondmabuf);
1918 void free_rx_desc_ring(struct net_device *dev)
1920 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1921 struct pci_dev *pdev = priv->pdev;
1923 int count = priv->rxringcount;
1925 #ifdef CONFIG_RTL8185B
1926 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1927 priv->rxring, priv->rxringdma);
1929 pci_free_consistent(pdev, sizeof(u32)*4*count+256,
1930 priv->rxring, priv->rxringdma);
1933 buffer_free(dev,&(priv->rxbuffer),priv->rxbuffersize,0);
1937 short alloc_rx_desc_ring(struct net_device *dev, u16 bufsize, int count)
1942 dma_addr_t dma_desc,dma_tmp;
1943 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1944 struct pci_dev *pdev=priv->pdev;
1948 #ifdef CONFIG_RTL8185B
1949 rx_desc_size = 8; // 4*8 = 32 bytes
1954 if((bufsize & 0xfff) != bufsize){
1955 DMESGE ("RX buffer allocation too large");
1959 desc = (u32*)pci_alloc_consistent(pdev,sizeof(u32)*rx_desc_size*count+256,
1962 if(dma_desc & 0xff){
1965 * descriptor's buffer must be 256 byte aligned
1966 * should never happen since we specify the DMA mask
1968 WARN(1, "DMA buffer is not aligned\n");
1972 priv->rxringdma=dma_desc;
1975 for (i=0;i<count;i++){
1977 if ((buf= kmalloc(bufsize * sizeof(u8),GFP_ATOMIC)) == NULL){
1978 DMESGE("Failed to kmalloc RX buffer");
1982 dma_tmp = pci_map_single(pdev,buf,bufsize * sizeof(u8),
1983 PCI_DMA_FROMDEVICE);
1985 #ifdef DEBUG_ZERO_RX
1987 for(j=0;j<bufsize;j++) ((u8*)buf)[i] = 0;
1990 //buf = (void*)pci_alloc_consistent(pdev,bufsize,&dma_tmp);
1991 if(-1 == buffer_add(&(priv->rxbuffer), buf,dma_tmp,
1992 &(priv->rxbufferhead))){
1993 DMESGE("Unable to allocate mem RX buf");
1996 *tmp = 0; //zero pads the header of the descriptor
1997 *tmp = *tmp |( bufsize&0xfff);
1998 *(tmp+2) = (u32)dma_tmp;
1999 *tmp = *tmp |(1<<31); // descriptor void, owned by the NIC
2001 #ifdef DEBUG_RXALLOC
2002 DMESG("Alloc %x size buffer, DMA mem @ %x, virtual mem @ %x",
2003 (u32)(bufsize&0xfff), (u32)dma_tmp, (u32)buf);
2006 tmp=tmp+rx_desc_size;
2009 *(tmp-rx_desc_size) = *(tmp-rx_desc_size) | (1<<30); // this is the last descriptor
2012 #ifdef DEBUG_RXALLOC
2013 DMESG("RX DMA physical address: %x",dma_desc);
2020 void set_nic_rxring(struct net_device *dev)
2023 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2025 //rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
2027 pgreg=read_nic_byte(dev, PGSELECT);
2028 write_nic_byte(dev, PGSELECT, pgreg &~ (1<<PGSELECT_PG_SHIFT));
2030 //rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2032 write_nic_dword(dev, RXRING_ADDR,priv->rxringdma);
2036 void rtl8180_reset(struct net_device *dev)
2038 //u32 txconf = 0x80e00707; //FIXME: Make me understandable
2041 //write_nic_dword(dev,TX_CONF,txconf);
2043 rtl8180_irq_disable(dev);
2045 cr=read_nic_byte(dev,CMD);
2047 cr = cr | (1<<CMD_RST_SHIFT);
2048 write_nic_byte(dev,CMD,cr);
2050 force_pci_posting(dev);
2054 if(read_nic_byte(dev,CMD) & (1<<CMD_RST_SHIFT))
2055 DMESGW("Card reset timeout!");
2057 DMESG("Card successfully reset");
2059 //#ifndef CONFIG_RTL8185B
2060 rtl8180_set_mode(dev,EPROM_CMD_LOAD);
2061 force_pci_posting(dev);
2066 inline u16 ieeerate2rtlrate(int rate)
2099 static u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540,720};
2100 inline u16 rtl8180_rate2rate(short rate)
2102 if (rate >12) return 10;
2103 return rtl_rate[rate];
2105 inline u8 rtl8180_IsWirelessBMode(u16 rate)
2107 if( ((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220) )
2111 u16 N_DBPSOfRate(u16 DataRate);
2115 u8 bManagementFrame,
2123 if( rtl8180_IsWirelessBMode(DataRate) )
2125 if( bManagementFrame || !bShortPreamble || DataRate == 10 )
2127 FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
2131 FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
2133 if( ( FrameLength*8 % (DataRate/10) ) != 0 ) //Get the Ceilling
2135 } else { //802.11g DSSS-OFDM PLCP length field calculation.
2136 N_DBPS = N_DBPSOfRate(DataRate);
2137 Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
2138 + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
2139 FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
2143 u16 N_DBPSOfRate(u16 DataRate)
2191 // For Netgear case, they want good-looking singal strength.
2192 // 2004.12.05, by rcnjko.
2195 NetgearSignalStrengthTranslate(
2202 // Step 1. Scale mapping.
2203 if(CurrSS >= 71 && CurrSS <= 100)
2205 RetSS = 90 + ((CurrSS - 70) / 3);
2207 else if(CurrSS >= 41 && CurrSS <= 70)
2209 RetSS = 78 + ((CurrSS - 40) / 3);
2211 else if(CurrSS >= 31 && CurrSS <= 40)
2213 RetSS = 66 + (CurrSS - 30);
2215 else if(CurrSS >= 21 && CurrSS <= 30)
2217 RetSS = 54 + (CurrSS - 20);
2219 else if(CurrSS >= 5 && CurrSS <= 20)
2221 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2223 else if(CurrSS == 4)
2227 else if(CurrSS == 3)
2231 else if(CurrSS == 2)
2235 else if(CurrSS == 1)
2243 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2245 // Step 2. Smoothing.
2248 RetSS = ((LastSS * 5) + (RetSS)+ 5) / 6;
2250 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2256 // Translate 0-100 signal strength index into dBm.
2260 u8 SignalStrengthIndex // 0-100 index.
2263 long SignalPower; // in dBm.
2265 // Translate to dBm (x=0.5y-95).
2266 SignalPower = (long)((SignalStrengthIndex + 1) >> 1);
2273 // Perform signal smoothing for dynamic mechanism.
2274 // This is different with PerformSignalSmoothing8185 in smoothing fomula.
2275 // No dramatic adjustion is apply because dynamic mechanism need some degree
2276 // of correctness. Ported from 8187B.
2277 // 2007-02-26, by Bruce.
2280 PerformUndecoratedSignalSmoothing8185(
2281 struct r8180_priv *priv,
2287 // Determin the current packet is CCK rate.
2288 priv->bCurCCKPkt = bCckRate;
2290 if(priv->UndecoratedSmoothedSS >= 0)
2292 priv->UndecoratedSmoothedSS = ( (priv->UndecoratedSmoothedSS * 5) + (priv->SignalStrength * 10) ) / 6;
2296 priv->UndecoratedSmoothedSS = priv->SignalStrength * 10;
2299 priv->UndercorateSmoothedRxPower = ( (priv->UndercorateSmoothedRxPower * 50) + (priv->RxPower* 11)) / 60;
2301 // printk("Sommthing SignalSterngth (%d) => UndecoratedSmoothedSS (%d)\n", priv->SignalStrength, priv->UndecoratedSmoothedSS);
2302 // printk("Sommthing RxPower (%d) => UndecoratedRxPower (%d)\n", priv->RxPower, priv->UndercorateSmoothedRxPower);
2304 //if(priv->CurCCKRSSI >= 0 && bCckRate)
2307 priv->CurCCKRSSI = priv->RSSI;
2311 priv->CurCCKRSSI = 0;
2314 // Boundary checking.
2315 // TODO: The overflow condition does happen, if we want to fix,
2316 // we shall recalculate thresholds first.
2317 if(priv->UndecoratedSmoothedSS > 100)
2319 // printk("UndecoratedSmoothedSS(%d) overflow, SignalStrength(%d)\n", priv->UndecoratedSmoothedSS, priv->SignalStrength);
2321 if(priv->UndecoratedSmoothedSS < 0)
2323 // printk("UndecoratedSmoothedSS(%d) underflow, SignalStrength(%d)\n", priv->UndecoratedSmoothedSS, priv->SignalStrength);
2330 /* This is rough RX isr handling routine*/
2331 void rtl8180_rx(struct net_device *dev)
2333 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2334 struct sk_buff *tmp_skb;
2336 //struct sk_buff *skb;
2340 unsigned char quality, signal;
2351 u8 LNA_gain[4]={02, 17, 29, 39};
2353 struct ieee80211_hdr *hdr;//by amy
2355 u8 bHwError = 0,bCRC = 0,bICV = 0;
2359 bool bCckRate = false;
2361 long SignalStrengthIndex = 0;//+by amy 080312
2362 // u8 SignalStrength = 0;
2363 struct ieee80211_rx_stats stats = {
2367 // .mac_time = jiffies,
2368 .freq = IEEE80211_24GHZ_BAND,
2371 #ifdef CONFIG_RTL8185B
2372 stats.nic_type = NIC_8185B;
2376 stats.nic_type = NIC_8185;
2379 //printk("receive frame!%d\n",count++);
2380 //if (!priv->rxbuffer) DMESG ("EE: NIC RX ack, but RX queue corrupted!");
2383 if ((*(priv->rxringtail)) & (1<<31)) {
2385 /* we have got an RX int, but the descriptor
2386 * we are pointing is empty*/
2388 priv->stats.rxnodata++;
2389 priv->ieee80211->stats.rx_errors++;
2391 /* if (! *(priv->rxring) & (1<<31)) {
2393 priv->stats.rxreset++;
2394 priv->rxringtail=priv->rxring;
2395 priv->rxbuffer=priv->rxbufferhead;
2400 /* Maybe it is possible that the NIC has skipped some descriptors or
2401 * it has reset its internal pointer to the beginning of the ring
2402 * we search for the first filled descriptor in the ring, or we break
2403 * putting again the pointer in the old location if we do not found any.
2404 * This is quite dangerous, what does happen if the nic writes
2405 * two descriptor (say A and B) when we have just checked the descriptor
2406 * A and we are going to check the descriptor B..This might happen if the
2407 * interrupt was dummy, there was not really filled descriptors and
2408 * the NIC didn't lose pointer
2411 //priv->stats.rxwrkaround++;
2413 tmp = priv->rxringtail;
2414 while (*(priv->rxringtail) & (1<<31)){
2416 priv->rxringtail+=4;
2418 if(priv->rxringtail >=
2419 (priv->rxring)+(priv->rxringcount )*4)
2420 priv->rxringtail=priv->rxring;
2422 priv->rxbuffer=(priv->rxbuffer->next);
2424 if(priv->rxringtail == tmp ){
2425 //DMESG("EE: Could not find RX pointer");
2426 priv->stats.rxnopointer++;
2433 tmp = priv->rxringtail;
2435 if(tmp == priv->rxring)
2436 //tmp = priv->rxring + (priv->rxringcount )*rx_desc_size; xiong-2006-11-15
2437 tmp = priv->rxring + (priv->rxringcount - 1)*rx_desc_size;
2439 tmp -= rx_desc_size;
2441 if(! (*tmp & (1<<31)))
2443 }while(tmp != priv->rxring);
2445 if(tmp2) priv->rxringtail = tmp2;
2450 /* while there are filled descriptors */
2451 while(!(*(priv->rxringtail) & (1<<31))){
2452 if(*(priv->rxringtail) & (1<<26))
2453 DMESGW("RX buffer overflow");
2454 if(*(priv->rxringtail) & (1<<12))
2455 priv->stats.rxicverr++;
2457 if(*(priv->rxringtail) & (1<<27)){
2458 priv->stats.rxdmafail++;
2459 //DMESG("EE: RX DMA FAILED at buffer pointed by descriptor %x",(u32)priv->rxringtail);
2463 pci_dma_sync_single_for_cpu(priv->pdev,
2464 priv->rxbuffer->dma,
2465 priv->rxbuffersize * \
2467 PCI_DMA_FROMDEVICE);
2469 first = *(priv->rxringtail) & (1<<29) ? 1:0;
2470 if(first) priv->rx_prevlen=0;
2472 last = *(priv->rxringtail) & (1<<28) ? 1:0;
2474 lastlen=((*priv->rxringtail) &0xfff);
2476 /* if the last descriptor (that should
2477 * tell us the total packet len) tell
2478 * us something less than the descriptors
2479 * len we had until now, then there is some
2481 * workaround to prevent kernel panic
2483 if(lastlen < priv->rx_prevlen)
2486 len=lastlen-priv->rx_prevlen;
2488 if(*(priv->rxringtail) & (1<<13)) {
2489 //lastlen=((*priv->rxringtail) &0xfff);
2490 if ((*(priv->rxringtail) & 0xfff) <500)
2491 priv->stats.rxcrcerrmin++;
2492 else if ((*(priv->rxringtail) & 0x0fff) >1000)
2493 priv->stats.rxcrcerrmax++;
2495 priv->stats.rxcrcerrmid++;
2500 len = priv->rxbuffersize;
2503 #ifdef CONFIG_RTL8185B
2505 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
2507 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
2514 #ifdef CONFIG_RTL818X_S
2518 priv->rx_prevlen+=len;
2520 if(priv->rx_prevlen > MAX_FRAG_THRESHOLD + 100){
2521 /* HW is probably passing several buggy frames
2522 * without FD or LD flag set.
2523 * Throw this garbage away to prevent skb
2526 if(!priv->rx_skb_complete)
2527 dev_kfree_skb_any(priv->rx_skb);
2528 priv->rx_skb_complete = 1;
2531 #ifdef DEBUG_RX_FRAG
2532 DMESG("Iteration.. len %x",len);
2533 if(first) DMESG ("First descriptor");
2534 if(last) DMESG("Last descriptor");
2537 #ifdef DEBUG_RX_VERBOSE
2538 print_buffer( priv->rxbuffer->buf, len);
2541 #ifdef CONFIG_RTL8185B
2542 signal=(unsigned char)(((*(priv->rxringtail+3))& (0x00ff0000))>>16);
2543 signal=(signal&0xfe)>>1; // Modify by hikaru 6.6
2545 quality=(unsigned char)((*(priv->rxringtail+3)) & (0xff));
2547 stats.mac_time[0] = *(priv->rxringtail+1);
2548 stats.mac_time[1] = *(priv->rxringtail+2);
2549 rxpower =((char)(((*(priv->rxringtail+4))& (0x00ff0000))>>16))/2 - 42;
2550 RSSI = ((u8)(((*(priv->rxringtail+3)) & (0x0000ff00))>> 8)) & (0x7f);
2553 signal=((*(priv->rxringtail+1))& (0xff0000))>>16;
2554 signal=(signal&0xfe)>>1; // Modify by hikaru 6.6
2556 quality=((*(priv->rxringtail+1)) & (0xff));
2558 stats.mac_time[0] = *(priv->rxringtail+2);
2559 stats.mac_time[1] = *(priv->rxringtail+3);
2561 rate=((*(priv->rxringtail)) &
2562 ((1<<23)|(1<<22)|(1<<21)|(1<<20)))>>20;
2564 stats.rate = rtl8180_rate2rate(rate);
2566 Antenna = (((*(priv->rxringtail +3))& (0x00008000)) == 0 )? 0:1 ;
2567 // printk("in rtl8180_rx():Antenna is %d\n",Antenna);
2568 //by amy for antenna
2569 if(!rtl8180_IsWirelessBMode(stats.rate))
2572 RxAGC_dBm = rxpower+1; //bias
2576 RxAGC_dBm = signal;//bit 0 discard
2578 LNA = (u8) (RxAGC_dBm & 0x60 ) >> 5 ; //bit 6~ bit 5
2579 BB = (u8) (RxAGC_dBm & 0x1F); // bit 4 ~ bit 0
2581 RxAGC_dBm = -( LNA_gain[LNA] + (BB *2) ); //Pin_11b=-(LNA_gain+BB_gain) (dBm)
2583 RxAGC_dBm +=4; //bias
2586 if(RxAGC_dBm & 0x80) //absolute value
2587 RXAGC= ~(RxAGC_dBm)+1;
2588 bCckRate = rtl8180_IsWirelessBMode(stats.rate);
2589 // Translate RXAGC into 1-100.
2590 if(!rtl8180_IsWirelessBMode(stats.rate))
2596 RXAGC=(90-RXAGC)*100/65;
2604 RXAGC=(95-RXAGC)*100/65;
2606 priv->SignalStrength = (u8)RXAGC;
2607 priv->RecvSignalPower = RxAGC_dBm ; // It can use directly by SD3 CMLin
2608 priv->RxPower = rxpower;
2611 // SQ translation formular is provided by SD3 DZ. 2006.06.27, by rcnjko.
2613 quality = 1;//0; //0 will cause epc to show signal zero , walk aroud now;
2614 else if(quality < 27)
2617 quality = 127 - quality;
2618 priv->SignalQuality = quality;
2619 if(!priv->card_8185)
2620 printk("check your card type\n");
2622 stats.signal = (u8)quality;//priv->wstats.qual.level = priv->SignalStrength;
2623 stats.signalstrength = RXAGC;
2624 if(stats.signalstrength > 100)
2625 stats.signalstrength = 100;
2626 stats.signalstrength = (stats.signalstrength * 70)/100 + 30;
2627 // printk("==========================>rx : RXAGC is %d,signalstrength is %d\n",RXAGC,stats.signalstrength);
2628 stats.rssi = priv->wstats.qual.qual = priv->SignalQuality;
2629 stats.noise = priv->wstats.qual.noise = 100 - priv ->wstats.qual.qual;
2631 bHwError = (((*(priv->rxringtail))& (0x00000fff)) == 4080)| (((*(priv->rxringtail))& (0x04000000)) != 0 )
2632 | (((*(priv->rxringtail))& (0x08000000)) != 0 )| (((~(*(priv->rxringtail)))& (0x10000000)) != 0 )| (((~(*(priv->rxringtail)))& (0x20000000)) != 0 );
2633 bCRC = ((*(priv->rxringtail)) & (0x00002000)) >> 13;
2634 bICV = ((*(priv->rxringtail)) & (0x00001000)) >> 12;
2635 hdr = (struct ieee80211_hdr *)priv->rxbuffer->buf;
2636 fc = le16_to_cpu(hdr->frame_ctl);
2637 type = WLAN_FC_GET_TYPE(fc);
2639 if((IEEE80211_FTYPE_CTL != type) &&
2640 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3))
2641 && (!bHwError) && (!bCRC)&& (!bICV))
2644 // Perform signal smoothing for dynamic mechanism on demand.
2645 // This is different with PerformSignalSmoothing8185 in smoothing fomula.
2646 // No dramatic adjustion is apply because dynamic mechanism need some degree
2647 // of correctness. 2007.01.23, by shien chang.
2648 PerformUndecoratedSignalSmoothing8185(priv,bCckRate);
2650 // For good-looking singal strength.
2652 SignalStrengthIndex = NetgearSignalStrengthTranslate(
2653 priv->LastSignalStrengthInPercent,
2654 priv->SignalStrength);
2656 priv->LastSignalStrengthInPercent = SignalStrengthIndex;
2657 priv->Stats_SignalStrength = TranslateToDbm8185((u8)SignalStrengthIndex);
2659 // We need more correct power of received packets and the "SignalStrength" of RxStats is beautified,
2660 // so we record the correct power here.
2662 priv->Stats_SignalQuality =(long) (priv->Stats_SignalQuality * 5 + (long)priv->SignalQuality + 5) / 6;
2663 priv->Stats_RecvSignalPower = (long)(priv->Stats_RecvSignalPower * 5 + priv->RecvSignalPower -1) / 6;
2665 // Figure out which antenna that received the lasted packet.
2666 priv->LastRxPktAntenna = Antenna ? 1 : 0; // 0: aux, 1: main.
2668 SwAntennaDiversityRxOk8185(dev, priv->SignalStrength);
2671 //by amy for antenna
2680 if(!priv->rx_skb_complete){
2681 /* seems that HW sometimes fails to reiceve and
2682 doesn't provide the last descriptor */
2684 DMESG("going to free incomplete skb");
2686 dev_kfree_skb_any(priv->rx_skb);
2687 priv->stats.rxnolast++;
2689 DMESG("free incomplete skb OK");
2692 /* support for prism header has been originally added by Christian */
2693 if(priv->prism_hdr && priv->ieee80211->iw_mode == IW_MODE_MONITOR){
2696 priv->rx_skb = dev_alloc_skb(len+2+PRISM_HDR_SIZE);
2697 if(! priv->rx_skb) goto drop;
2699 prism_hdr = (u32*) skb_put(priv->rx_skb,PRISM_HDR_SIZE);
2700 prism_hdr[0]=htonl(0x80211001); //version
2701 prism_hdr[1]=htonl(0x40); //length
2702 prism_hdr[2]=htonl(stats.mac_time[1]); //mactime (HIGH)
2703 prism_hdr[3]=htonl(stats.mac_time[0]); //mactime (LOW)
2704 rdtsc(prism_hdr[5], prism_hdr[4]); //hostime (LOW+HIGH)
2705 prism_hdr[4]=htonl(prism_hdr[4]); //Byte-Order aendern
2706 prism_hdr[5]=htonl(prism_hdr[5]); //Byte-Order aendern
2707 prism_hdr[6]=0x00; //phytype
2708 prism_hdr[7]=htonl(priv->chan); //channel
2709 prism_hdr[8]=htonl(stats.rate); //datarate
2710 prism_hdr[9]=0x00; //antenna
2711 prism_hdr[10]=0x00; //priority
2712 prism_hdr[11]=0x00; //ssi_type
2713 prism_hdr[12]=htonl(stats.signal); //ssi_signal
2714 prism_hdr[13]=htonl(stats.noise); //ssi_noise
2715 prism_hdr[14]=0x00; //preamble
2716 prism_hdr[15]=0x00; //encoding
2720 priv->rx_skb = dev_alloc_skb(len+2);
2721 if( !priv->rx_skb) goto drop;
2723 DMESG("Alloc initial skb %x",len+2);
2727 priv->rx_skb_complete=0;
2728 priv->rx_skb->dev=dev;
2730 /* if we are here we should have already RXed
2732 * If we get here and the skb is not allocated then
2733 * we have just throw out garbage (skb not allocated)
2734 * and we are still rxing garbage....
2736 if(!priv->rx_skb_complete){
2738 tmp_skb= dev_alloc_skb(priv->rx_skb->len +len+2);
2740 if(!tmp_skb) goto drop;
2744 DMESG("Realloc skb %x",len+2);
2748 DMESG("going copy prev frag %x",priv->rx_skb->len);
2750 memcpy(skb_put(tmp_skb,priv->rx_skb->len),
2754 DMESG("skb copy prev frag complete");
2757 dev_kfree_skb_any(priv->rx_skb);
2759 DMESG("prev skb free ok");
2762 priv->rx_skb=tmp_skb;
2766 DMESG("going to copy current payload %x",len);
2768 if(!priv->rx_skb_complete) {
2769 #ifdef CONFIG_RTL8185B
2771 memcpy(skb_put(priv->rx_skb,len),
2772 (((unsigned char *)priv->rxbuffer->buf) + 2),len);
2775 memcpy(skb_put(priv->rx_skb,len),
2776 priv->rxbuffer->buf,len);
2777 #ifdef CONFIG_RTL8185B
2782 DMESG("current fragment skb copy complete");
2785 if(last && !priv->rx_skb_complete){
2788 DMESG("Got last fragment");
2791 if(priv->rx_skb->len > 4)
2792 skb_trim(priv->rx_skb,priv->rx_skb->len-4);
2794 DMESG("yanked out crc, passing to the upper layer");
2797 #ifndef RX_DONT_PASS_UL
2798 if(!ieee80211_rx(priv->ieee80211,
2799 priv->rx_skb, &stats)){
2801 DMESGW("Packet not consumed");
2803 #endif // RX_DONT_PASS_UL
2805 dev_kfree_skb_any(priv->rx_skb);
2806 #ifndef RX_DONT_PASS_UL
2814 priv->rx_skb_complete=1;
2819 pci_dma_sync_single_for_device(priv->pdev,
2820 priv->rxbuffer->dma,
2821 priv->rxbuffersize * \
2823 PCI_DMA_FROMDEVICE);
2826 drop: // this is used when we have not enought mem
2828 /* restore the descriptor */
2829 *(priv->rxringtail+2)=priv->rxbuffer->dma;
2830 *(priv->rxringtail)=*(priv->rxringtail) &~ 0xfff;
2831 *(priv->rxringtail)=
2832 *(priv->rxringtail) | priv->rxbuffersize;
2834 *(priv->rxringtail)=
2835 *(priv->rxringtail) | (1<<31);
2841 DMESG("Current descriptor: %x",(u32)priv->rxringtail);
2843 //unsigned long flags;
2844 //spin_lock_irqsave(&priv->irq_lock,flags);
2846 priv->rxringtail+=rx_desc_size;
2847 if(priv->rxringtail >=
2848 (priv->rxring)+(priv->rxringcount )*rx_desc_size)
2849 priv->rxringtail=priv->rxring;
2851 //spin_unlock_irqrestore(&priv->irq_lock,flags);
2854 priv->rxbuffer=(priv->rxbuffer->next);
2860 // if(get_curr_tx_free_desc(dev,priority))
2861 // ieee80211_sta_ps_sleep(priv->ieee80211, &tmp, &tmp2);
2868 void rtl8180_dma_kick(struct net_device *dev, int priority)
2870 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2872 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2879 write_nic_byte(dev,TX_DMA_POLLING,
2880 (1<< TX_DMA_POLLING_LOWPRIORITY_SHIFT) |
2881 priv->dma_poll_mask);
2886 write_nic_byte(dev,TX_DMA_POLLING,
2887 (1<< TX_DMA_POLLING_NORMPRIORITY_SHIFT) |
2888 priv->dma_poll_mask);
2893 write_nic_byte(dev,TX_DMA_POLLING,
2894 (1<< TX_DMA_POLLING_HIPRIORITY_SHIFT) |
2895 priv->dma_poll_mask);
2900 write_nic_byte(dev, TX_DMA_POLLING,
2901 (1 << (priority + 1)) | priv->dma_poll_mask);
2902 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2904 force_pci_posting(dev);
2908 void rtl8180_tx_queues_stop(struct net_device *dev)
2910 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2911 u8 dma_poll_mask = (1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
2912 dma_poll_mask |= (1<<TX_DMA_STOP_HIPRIORITY_SHIFT);
2913 dma_poll_mask |= (1<<TX_DMA_STOP_NORMPRIORITY_SHIFT);
2914 dma_poll_mask |= (1<<TX_DMA_STOP_BEACON_SHIFT);
2916 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2917 write_nic_byte(dev,TX_DMA_POLLING,dma_poll_mask);
2918 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2922 void rtl8180_data_hard_stop(struct net_device *dev)
2924 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2926 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2927 #ifdef CONFIG_RTL8185B
2928 priv->dma_poll_stop_mask |= TPPOLLSTOP_AC_VIQ;
2929 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
2931 priv->dma_poll_mask |= (1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
2932 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
2934 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2938 void rtl8180_data_hard_resume(struct net_device *dev)
2940 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2942 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2943 #ifdef CONFIG_RTL8185B
2944 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_AC_VIQ);
2945 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
2947 priv->dma_poll_mask &= ~(1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
2948 write_nic_byte(dev,TX_DMA_POLLING,priv->dma_poll_mask);
2950 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2954 /* this function TX data frames when the ieee80211 stack requires this.
2955 * It checks also if we need to stop the ieee tx queue, eventually do it
2957 void rtl8180_hard_data_xmit(struct sk_buff *skb,struct net_device *dev, int
2960 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2962 struct ieee80211_hdr_3addr *h = (struct ieee80211_hdr_3addr *) skb->data;
2963 short morefrag = (h->frame_ctl) & IEEE80211_FCTL_MOREFRAGS;
2964 unsigned long flags;
2966 //static int count = 0;
2968 mode = priv->ieee80211->iw_mode;
2970 rate = ieeerate2rtlrate(rate);
2972 * This function doesn't require lock because we make
2973 * sure it's called with the tx_lock already acquired.
2974 * this come from the kernel's hard_xmit callback (trought
2975 * the ieee stack, or from the try_wake_queue (again trought
2978 #ifdef CONFIG_RTL8185B
2979 priority = AC2Q(skb->priority);
2981 priority = LOW_PRIORITY;
2983 spin_lock_irqsave(&priv->tx_lock,flags);
2985 if(priv->ieee80211->bHwRadioOff)
2987 spin_unlock_irqrestore(&priv->tx_lock,flags);
2992 //printk(KERN_WARNING "priority = %d@%d\n", priority, count++);
2993 if (!check_nic_enought_desc(dev, priority)){
2994 //DMESG("Error: no descriptor left by previous TX (avail %d) ",
2995 // get_curr_tx_free_desc(dev, priority));
2996 DMESGW("Error: no descriptor left by previous TX (avail %d) ",
2997 get_curr_tx_free_desc(dev, priority));
2998 //printk(KERN_WARNING "==============================================================> \n");
2999 ieee80211_stop_queue(priv->ieee80211);
3001 rtl8180_tx(dev, skb->data, skb->len, priority, morefrag,0,rate);
3002 if (!check_nic_enought_desc(dev, priority))
3003 ieee80211_stop_queue(priv->ieee80211);
3005 //dev_kfree_skb_any(skb);
3006 spin_unlock_irqrestore(&priv->tx_lock,flags);
3010 /* This is a rough attempt to TX a frame
3011 * This is called by the ieee 80211 stack to TX management frames.
3012 * If the ring is full packet are dropped (for data frame the queue
3013 * is stopped before this can happen). For this reason it is better
3014 * if the descriptors are larger than the largest management frame
3015 * we intend to TX: i'm unsure what the HW does if it will not found
3016 * the last fragment of a frame because it has been dropped...
3017 * Since queues for Management and Data frames are different we
3018 * might use a different lock than tx_lock (for example mgmt_tx_lock)
3020 /* these function may loops if invoked with 0 descriptors or 0 len buffer*/
3021 int rtl8180_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
3023 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3025 unsigned long flags;
3029 #ifdef CONFIG_RTL8185B
3030 priority = MANAGE_PRIORITY;
3032 priority = NORM_PRIORITY;
3035 spin_lock_irqsave(&priv->tx_lock,flags);
3037 if(priv->ieee80211->bHwRadioOff)
3039 spin_unlock_irqrestore(&priv->tx_lock,flags);
3041 dev_kfree_skb_any(skb);
3045 rtl8180_tx(dev, skb->data, skb->len, priority,
3046 0, 0,ieeerate2rtlrate(priv->ieee80211->basic_rate));
3048 priv->ieee80211->stats.tx_bytes+=skb->len;
3049 priv->ieee80211->stats.tx_packets++;
3050 spin_unlock_irqrestore(&priv->tx_lock,flags);
3052 dev_kfree_skb_any(skb);
3056 // longpre 144+48 shortpre 72+24
3057 u16 rtl8180_len2duration(u32 len, short rate,short* ext)
3066 duration = ((len+4)<<4) /0x2;
3067 drift = ((len+4)<<4) % 0x2;
3068 if(drift ==0 ) break;
3074 duration = ((len+4)<<4) /0x4;
3075 drift = ((len+4)<<4) % 0x4;
3076 if(drift ==0 ) break;
3082 duration = ((len+4)<<4) /0xb;
3083 drift = ((len+4)<<4) % 0xb;
3092 duration = ((len+4)<<4) /0x16;
3093 drift = ((len+4)<<4) % 0x16;
3107 void rtl8180_prepare_beacon(struct net_device *dev)
3110 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3112 struct sk_buff *skb;
3114 u16 word = read_nic_word(dev, BcnItv);
3115 word &= ~BcnItv_BcnItv; // clear Bcn_Itv
3116 word |= cpu_to_le16(priv->ieee80211->current_network.beacon_interval);//0x64;
3117 write_nic_word(dev, BcnItv, word);
3120 skb = ieee80211_get_beacon(priv->ieee80211);
3122 rtl8180_tx(dev,skb->data,skb->len,BEACON_PRIORITY,
3123 0,0,ieeerate2rtlrate(priv->ieee80211->basic_rate));
3124 dev_kfree_skb_any(skb);
3127 //DMESG("size %x",len);
3128 if(*tail & (1<<31)){
3130 //DMESG("No more beacon TX desc");
3134 //while(! (*tail & (1<<31))){
3135 *tail= 0; // zeroes header
3137 *tail = *tail| (1<<29) ; //fist segment of the packet
3138 *tail = (*tail) | (1<<28); // last segment
3139 // *tail = *tail | (1<<18); // this is a beacon frame
3140 *(tail+3)=*(tail+3) &~ 0xfff;
3141 *(tail+3)=*(tail+3) | len; // buffer lenght
3143 // zeroes the second 32-bits dword of the descriptor
3145 *tail = *tail | (rate << 24);
3147 duration = rtl8180_len2duration(len,rate,&ext);
3149 *(tail+1) = *(tail+1) | ((duration & 0x7fff)<<16);
3151 *tail = *tail | (1<<31);
3152 //^ descriptor ready to be txed
3153 if((tail - begin)/8 == priv->txbeaconcount-1)
3161 /* This function do the real dirty work: it enqueues a TX command
3162 * descriptor in the ring buffer, copyes the frame in a TX buffer
3163 * and kicks the NIC to ensure it does the DMA transfer.
3165 short rtl8180_tx(struct net_device *dev, u8* txbuf, int len, int priority,
3166 short morefrag, short descfrag, int rate)
3168 struct r8180_priv *priv = ieee80211_priv(dev);
3169 u32 *tail,*temp_tail;
3180 struct buffer* buflist;
3181 //unsigned long flags;
3182 #ifdef CONFIG_RTL8185B
3183 struct ieee80211_hdr_3addr *frag_hdr = (struct ieee80211_hdr_3addr *)txbuf;
3185 u8 bUseShortPreamble = 0;
3189 //u8 RetryLimit = 0;
3192 u16 ThisFrameTime = 0;
3193 u16 TxDescDuration = 0;
3194 u8 ownbit_flag = false; //added by david woo for sync Tx, 2007.12.14
3198 case MANAGE_PRIORITY:
3199 tail=priv->txmapringtail;
3200 begin=priv->txmapring;
3201 buflist = priv->txmapbufstail;
3202 count = priv->txringcount;
3206 tail=priv->txbkpringtail;
3207 begin=priv->txbkpring;
3208 buflist = priv->txbkpbufstail;
3209 count = priv->txringcount;
3213 tail=priv->txbepringtail;
3214 begin=priv->txbepring;
3215 buflist = priv->txbepbufstail;
3216 count = priv->txringcount;
3220 tail=priv->txvipringtail;
3221 begin=priv->txvipring;
3222 buflist = priv->txvipbufstail;
3223 count = priv->txringcount;
3227 tail=priv->txvopringtail;
3228 begin=priv->txvopring;
3229 buflist = priv->txvopbufstail;
3230 count = priv->txringcount;
3234 tail=priv->txhpringtail;
3235 begin=priv->txhpring;
3236 buflist = priv->txhpbufstail;
3237 count = priv->txringcount;
3240 case BEACON_PRIORITY:
3241 tail=priv->txbeaconringtail;
3242 begin=priv->txbeaconring;
3243 buflist = priv->txbeaconbufstail;
3244 count = priv->txbeaconcount;
3252 //printk("in rtl8180_tx(): rate is %d\n",priv->ieee80211->rate);
3254 memcpy(&dest, frag_hdr->addr1, ETH_ALEN);
3255 if (is_multicast_ether_addr(dest) ||
3256 is_broadcast_ether_addr(dest))
3263 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate), 0, bUseShortPreamble);
3264 TxDescDuration = ThisFrameTime;
3265 } else {// Unicast packet
3269 //YJ,add,080828,for Keep alive
3270 priv->NumTxUnicast++;
3272 // Figure out ACK rate according to BSS basic rate and Tx rate, 2006.03.08 by rcnjko.
3273 //AckRate = ComputeAckRate( pMgntInfo->mBrates, (u1Byte)(pTcb->DataRate) );
3274 // Figure out ACK time according to the AckRate and assume long preamble is used on receiver, 2006.03.08, by rcnjko.
3275 //AckTime = ComputeTxTime( sAckCtsLng/8, AckRate, FALSE, FALSE);
3276 //For simplicity, just use the 1M basic rate
3277 //AckTime = ComputeTxTime(14, 540,0, 0); // AckCTSLng = 14 use 1M bps send
3278 AckTime = ComputeTxTime(14, 10,0, 0); // AckCTSLng = 14 use 1M bps send
3279 //AckTime = ComputeTxTime(14, 2,false, false); // AckCTSLng = 14 use 1M bps send
3281 if ( ((len + sCrcLng) > priv->rts) && priv->rts )
3283 u16 RtsTime, CtsTime;
3288 // Rate and time required for RTS.
3289 RtsTime = ComputeTxTime( sAckCtsLng/8,priv->ieee80211->basic_rate, 0, 0);
3290 // Rate and time required for CTS.
3291 CtsTime = ComputeTxTime(14, 10,0, 0); // AckCTSLng = 14 use 1M bps send
3293 // Figure out time required to transmit this frame.
3294 ThisFrameTime = ComputeTxTime(len + sCrcLng,
3295 rtl8180_rate2rate(rate),
3299 // RTS-CTS-ThisFrame-ACK.
3300 RtsDur = CtsTime + ThisFrameTime + AckTime + 3*aSifsTime;
3302 TxDescDuration = RtsTime + RtsDur;
3304 else {// Normal case.
3309 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate), 0, bUseShortPreamble);
3310 TxDescDuration = ThisFrameTime + aSifsTime + AckTime;
3313 if(!(frag_hdr->frame_ctl & IEEE80211_FCTL_MOREFRAGS)) { //no more fragment
3315 Duration = aSifsTime + AckTime;
3316 } else { // One or more fragments remained.
3318 NextFragTime = ComputeTxTime( len + sCrcLng, //pretend following packet length equal current packet
3319 rtl8180_rate2rate(rate),
3321 bUseShortPreamble );
3323 //ThisFrag-ACk-NextFrag-ACK.
3324 Duration = NextFragTime + 3*aSifsTime + 2*AckTime;
3327 } // End of Unicast packet
3329 frag_hdr->duration_id = Duration;
3332 buflen=priv->txbuffsize;
3335 //printk("================================>buflen = %d, remain = %d!\n", buflen,remain);
3337 #ifdef DEBUG_TX_FRAG
3338 DMESG("TX iteration");
3341 DMESG("TX: filling descriptor %x",(u32)tail);
3345 DMESGE("TX buffer error, cannot TX frames. pri %d.", priority);
3346 //spin_unlock_irqrestore(&priv->tx_lock,flags);
3351 if( (*tail & (1<<31)) && (priority != BEACON_PRIORITY)){
3353 DMESGW("No more TX desc, returning %x of %x",
3355 priv->stats.txrdu++;
3356 #ifdef DEBUG_TX_DESC
3357 check_tx_ring(dev,priority);
3358 // netif_stop_queue(dev);
3359 // netif_carrier_off(dev);
3361 // spin_unlock_irqrestore(&priv->tx_lock,flags);
3367 *tail= 0; // zeroes header
3374 if(priv->card_8185){
3375 //FIXME: this should be triggered by HW encryption parameters.
3376 *tail |= (1<<15); //no encrypt
3377 // *tail |= (1<<30); //raise int when completed
3379 // *tail = *tail | (1<<16);
3380 if(remain==len && !descfrag) {
3381 ownbit_flag = false; //added by david woo,2007.12.14
3382 #ifdef DEBUG_TX_FRAG
3383 DMESG("First descriptor");
3385 *tail = *tail| (1<<29) ; //fist segment of the packet
3386 *tail = *tail |(len);
3391 for(i=0;i<buflen&& remain >0;i++,remain--){
3392 ((u8*)buf)[i]=txbuf[i]; //copy data into descriptor pointed DMAble buffer
3393 if(remain == 4 && i+4 >= buflen) break;
3394 /* ensure the last desc has at least 4 bytes payload */
3398 *(tail+3)=*(tail+3) &~ 0xfff;
3399 *(tail+3)=*(tail+3) | i; // buffer lenght
3400 // Use short preamble or not
3401 if (priv->ieee80211->current_network.capability&WLAN_CAPABILITY_SHORT_PREAMBLE)
3402 if (priv->plcp_preamble_mode==1 && rate!=0) // short mode now, not long!
3403 // *tail |= (1<<16); // enable short preamble mode.
3405 #ifdef CONFIG_RTL8185B
3410 if(bRTSEnable) //rts enable
3412 *tail |= ((ieeerate2rtlrate(priv->ieee80211->basic_rate))<<19);//RTS RATE
3413 *tail |= (1<<23);//rts enable
3414 *(tail+1) |=(RtsDur&0xffff);//RTS Duration
3416 *(tail+3) |= ((TxDescDuration&0xffff)<<16); //DURATION
3417 // *(tail+3) |= (0xe6<<16);
3418 *(tail+5) |= (11<<8);//(priv->retry_data<<8); //retry lim ;
3421 #ifdef CONFIG_RTL8187B
3422 if ( (len>priv->rts) && priv->rts && priority!=MANAGE_PRIORITY){
3424 if ( (len>priv->rts) && priv->rts && priority==LOW_PRIORITY){
3426 *tail |= (1<<23); //enalbe RTS function
3427 *tail |= (0<<19); //use 1M bps send RTS packet
3428 AckCtsTime = ComputeTxTime(14, 10,0, 0); // AckCTSLng = 14 use 1M bps send
3429 FrameTime = ComputeTxTime(len + 4, rtl8180_rate2rate(rate), 0, *tail&(1<<16));
3430 // RTS/CTS time is calculate as follow
3431 duration = FrameTime + 3*10 + 2*AckCtsTime; //10us is the SifsTime;
3432 *(tail+1) |= duration; //Need to edit here! ----hikaru
3434 *(tail+1)= 0; // zeroes the second 32-bits dword of the descriptor
3438 *tail = *tail | ((rate&0xf) << 24);
3439 //DMESG("rate %d",rate);
3441 if(priv->card_8185){
3444 *(tail+5)&= ~(1<<24); /* tx ant 0 */
3446 *(tail+5) &= ~(1<<23); /* random tx agc 23-16 */
3447 *(tail+5) |= (1<<22)|(1<<21)|(1<<20)|(1<<19)|(1<<18)|(1<<17)|(1<<16);
3450 ~((1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(1<<10)|(1<<9)|(1<<8));
3451 *(tail+5) |= (7<<8); // Max retry limit
3453 *(tail+5) &= ~((1<<7)|(1<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0));
3454 *(tail+5) |= (8<<4); // Max contention window
3455 *(tail+6) |= 4; // Min contention window
3460 /* hw_plcp_len is not used for rtl8180 chip */
3462 if(priv->card_8185 == 0 || !priv->hw_plcp_len){
3464 duration = rtl8180_len2duration(len,
3469 DMESG("PLCP duration %d",duration );
3470 //DMESG("drift %d",drift);
3471 DMESG("extension %s", (ext==1) ? "on":"off");
3473 *(tail+1) = *(tail+1) | ((duration & 0x7fff)<<16);
3474 if(ext) *(tail+1) = *(tail+1) |(1<<31); //plcp length extension
3477 if(morefrag) *tail = (*tail) | (1<<17); // more fragment
3478 if(!remain) *tail = (*tail) | (1<<28); // last segment of frame
3480 #ifdef DEBUG_TX_FRAG
3481 if(!remain)DMESG("Last descriptor");
3482 if(morefrag)DMESG("More frag");
3484 *(tail+5) = *(tail+5)|(2<<27);
3485 *(tail+7) = *(tail+7)|(1<<4);
3490 *tail = *tail | (1<<31); // descriptor ready to be txed
3493 #ifdef DEBUG_TX_DESC2
3494 printk("tx desc is:\n");
3495 DMESG("%8x %8x %8x %8x %8x %8x %8x %8x", tail[0], tail[1], tail[2], tail[3],
3496 tail[4], tail[5], tail[6], tail[7]);
3499 if((tail - begin)/8 == count-1)
3505 buflist=buflist->next;
3510 case MANAGE_PRIORITY:
3511 priv->txmapringtail=tail;
3512 priv->txmapbufstail=buflist;
3516 priv->txbkpringtail=tail;
3517 priv->txbkpbufstail=buflist;
3521 priv->txbepringtail=tail;
3522 priv->txbepbufstail=buflist;
3526 priv->txvipringtail=tail;
3527 priv->txvipbufstail=buflist;
3531 priv->txvopringtail=tail;
3532 priv->txvopbufstail=buflist;
3536 priv->txhpringtail=tail;
3537 priv->txhpbufstail = buflist;
3540 case BEACON_PRIORITY:
3541 /* the HW seems to be happy with the 1st
3542 * descriptor filled and the 2nd empty...
3543 * So always update descriptor 1 and never
3546 // priv->txbeaconringtail=tail;
3547 // priv->txbeaconbufstail=buflist;
3553 //rtl8180_dma_kick(dev,priority);
3555 *temp_tail = *temp_tail | (1<<31); // descriptor ready to be txed
3556 rtl8180_dma_kick(dev,priority);
3557 //spin_unlock_irqrestore(&priv->tx_lock,flags);
3564 void rtl8180_irq_rx_tasklet(struct r8180_priv * priv);
3567 void rtl8180_link_change(struct net_device *dev)
3569 struct r8180_priv *priv = ieee80211_priv(dev);
3570 u16 beacon_interval;
3572 struct ieee80211_network *net = &priv->ieee80211->current_network;
3573 // rtl8180_adapter_start(dev);
3574 rtl8180_update_msr(dev);
3577 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
3579 write_nic_dword(dev,BSSID,((u32*)net->bssid)[0]);
3580 write_nic_word(dev,BSSID+4,((u16*)net->bssid)[2]);
3583 beacon_interval = read_nic_dword(dev,BEACON_INTERVAL);
3584 beacon_interval &= ~ BEACON_INTERVAL_MASK;
3585 beacon_interval |= net->beacon_interval;
3586 write_nic_dword(dev, BEACON_INTERVAL, beacon_interval);
3588 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
3592 u16 atim = read_nic_dword(dev,ATIM);
3593 u16 = u16 &~ ATIM_MASK;
3594 u16 = u16 | beacon->atim;
3597 if (net->capability & WLAN_CAPABILITY_PRIVACY) {
3599 DMESG("Enabling hardware WEP support");
3600 rtl8180_set_hw_wep(dev);
3601 priv->ieee80211->host_encrypt=0;
3602 priv->ieee80211->host_decrypt=0;
3604 #ifndef CONFIG_IEEE80211_NOWEP
3606 priv->ieee80211->host_encrypt=1;
3607 priv->ieee80211->host_decrypt=1;
3611 #ifndef CONFIG_IEEE80211_NOWEP
3613 priv->ieee80211->host_encrypt=0;
3614 priv->ieee80211->host_decrypt=0;
3621 rtl8180_set_chan(dev, priv->chan);
3626 void rtl8180_rq_tx_ack(struct net_device *dev){
3628 struct r8180_priv *priv = ieee80211_priv(dev);
3629 // printk("====================>%s\n",__func__);
3630 write_nic_byte(dev,CONFIG4,read_nic_byte(dev,CONFIG4)|CONFIG4_PWRMGT);
3631 priv->ack_tx_to_ieee = 1;
3634 short rtl8180_is_tx_queue_empty(struct net_device *dev){
3636 struct r8180_priv *priv = ieee80211_priv(dev);
3639 for (d = priv->txmapring;
3640 d < priv->txmapring + priv->txringcount;d+=8)
3641 if(*d & (1<<31)) return 0;
3643 for (d = priv->txbkpring;
3644 d < priv->txbkpring + priv->txringcount;d+=8)
3645 if(*d & (1<<31)) return 0;
3647 for (d = priv->txbepring;
3648 d < priv->txbepring + priv->txringcount;d+=8)
3649 if(*d & (1<<31)) return 0;
3651 for (d = priv->txvipring;
3652 d < priv->txvipring + priv->txringcount;d+=8)
3653 if(*d & (1<<31)) return 0;
3655 for (d = priv->txvopring;
3656 d < priv->txvopring + priv->txringcount;d+=8)
3657 if(*d & (1<<31)) return 0;
3659 for (d = priv->txhpring;
3660 d < priv->txhpring + priv->txringcount;d+=8)
3661 if(*d & (1<<31)) return 0;
3664 /* FIXME FIXME 5msecs is random */
3665 #define HW_WAKE_DELAY 5
3667 void rtl8180_hw_wakeup(struct net_device *dev)
3669 unsigned long flags;
3671 struct r8180_priv *priv = ieee80211_priv(dev);
3673 spin_lock_irqsave(&priv->ps_lock,flags);
3674 //DMESG("Waken up!");
3675 write_nic_byte(dev,CONFIG4,read_nic_byte(dev,CONFIG4)&~CONFIG4_PWRMGT);
3678 priv->rf_wakeup(dev);
3679 // mdelay(HW_WAKE_DELAY);
3680 spin_unlock_irqrestore(&priv->ps_lock,flags);
3683 void rtl8180_hw_sleep_down(struct net_device *dev)
3685 unsigned long flags;
3687 struct r8180_priv *priv = ieee80211_priv(dev);
3689 spin_lock_irqsave(&priv->ps_lock,flags);
3693 priv->rf_sleep(dev);
3694 spin_unlock_irqrestore(&priv->ps_lock,flags);
3698 void rtl8180_hw_sleep(struct net_device *dev, u32 th, u32 tl)
3701 struct r8180_priv *priv = ieee80211_priv(dev);
3704 unsigned long flags;
3706 spin_lock_irqsave(&priv->ps_lock,flags);
3708 /* Writing HW register with 0 equals to disable
3709 * the timer, that is not really what we want
3711 tl -= MSECS(4+16+7);
3713 //if(tl == 0) tl = 1;
3715 /* FIXME HACK FIXME HACK */
3716 // force_pci_posting(dev);
3719 // rb = read_nic_dword(dev, TSFTR);
3721 /* If the interval in witch we are requested to sleep is too
3722 * short then give up and remain awake
3724 if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME))
3725 ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
3726 spin_unlock_irqrestore(&priv->ps_lock,flags);
3727 printk("too short to sleep\n");
3731 // write_nic_dword(dev, TimerInt, tl);
3732 // rb = read_nic_dword(dev, TSFTR);
3734 u32 tmp = (tl>rb)?(tl-rb):(rb-tl);
3738 priv->DozePeriodInPast2Sec += jiffies_to_msecs(tmp);
3740 queue_delayed_work(priv->ieee80211->wq, &priv->ieee80211->hw_wakeup_wq, tmp); //as tl may be less than rb
3742 /* if we suspect the TimerInt is gone beyond tl
3743 * while setting it, then give up
3746 if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))||
3747 ((tl < rb) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))) {
3748 spin_unlock_irqrestore(&priv->ps_lock,flags);
3752 // if(priv->rf_sleep)
3753 // priv->rf_sleep(dev);
3755 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_sleep_wq);
3756 spin_unlock_irqrestore(&priv->ps_lock,flags);
3760 //void rtl8180_wmm_param_update(struct net_device *dev,u8 *ac_param)
3761 #if LINUX_VERSION_CODE >=KERNEL_VERSION(2,6,20)
3762 void rtl8180_wmm_param_update(struct work_struct * work)
3764 struct ieee80211_device * ieee = container_of(work, struct ieee80211_device,wmm_param_update_wq);
3765 //struct r8180_priv *priv = (struct r8180_priv*)(ieee->priv);
3766 struct net_device *dev = ieee->dev;
3768 void rtl8180_wmm_param_update(struct ieee80211_device *ieee)
3770 struct net_device *dev = ieee->dev;
3771 struct r8180_priv *priv = ieee80211_priv(dev);
3773 u8 *ac_param = (u8 *)(ieee->current_network.wmm_param);
3774 u8 mode = ieee->current_network.mode;
3780 #ifndef CONFIG_RTL8185B
3781 //for legacy 8185 keep the PARAM unchange.
3784 if(!ieee->current_network.QoS_Enable){
3785 //legacy ac_xx_param update
3786 AcParam.longData = 0;
3787 AcParam.f.AciAifsn.f.AIFSN = 2; // Follow 802.11 DIFS.
3788 AcParam.f.AciAifsn.f.ACM = 0;
3789 AcParam.f.Ecw.f.ECWmin = 3; // Follow 802.11 CWmin.
3790 AcParam.f.Ecw.f.ECWmax = 7; // Follow 802.11 CWmax.
3791 AcParam.f.TXOPLimit = 0;
3792 for(eACI = 0; eACI < AC_MAX; eACI++){
3793 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
3797 pAcParam = (PAC_PARAM)(&AcParam);
3798 // Retrive paramters to udpate.
3799 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN *(((mode&IEEE_G) == IEEE_G)?9:20) + aSifsTime;
3800 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit))<<AC_PARAM_TXOP_LIMIT_OFFSET)|
3801 (((u32)(pAcParam->f.Ecw.f.ECWmax))<<AC_PARAM_ECW_MAX_OFFSET)|
3802 (((u32)(pAcParam->f.Ecw.f.ECWmin))<<AC_PARAM_ECW_MIN_OFFSET)|
3803 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
3806 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
3810 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
3814 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
3818 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
3822 printk(KERN_WARNING "SetHwReg8185():invalid ACI: %d!\n", eACI);
3830 for(i = 0; i < AC_MAX; i++){
3831 //AcParam.longData = 0;
3832 pAcParam = (AC_PARAM * )ac_param;
3838 // Retrive paramters to udpate.
3839 eACI = pAcParam->f.AciAifsn.f.ACI;
3840 //Mode G/A: slotTimeTimer = 9; Mode B: 20
3841 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G)?9:20) + aSifsTime;
3842 u4bAcParam = ( (((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
3843 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
3844 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
3845 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
3849 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
3853 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
3857 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
3861 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
3865 printk(KERN_WARNING "SetHwReg8185(): invalid ACI: %d !\n", eACI);
3869 ac_param += (sizeof(AC_PARAM));
3874 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3875 void rtl8180_tx_irq_wq(struct work_struct *work);
3877 void rtl8180_tx_irq_wq(struct net_device *dev);
3883 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3884 void rtl8180_restart_wq(struct work_struct *work);
3885 //void rtl8180_rq_tx_ack(struct work_struct *work);
3887 void rtl8180_restart_wq(struct net_device *dev);
3888 //void rtl8180_rq_tx_ack(struct net_device *dev);
3890 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3891 void rtl8180_watch_dog_wq(struct work_struct *work);
3893 void rtl8180_watch_dog_wq(struct net_device *dev);
3895 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3896 void rtl8180_hw_wakeup_wq(struct work_struct *work);
3898 void rtl8180_hw_wakeup_wq(struct net_device *dev);
3901 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3902 void rtl8180_hw_sleep_wq(struct work_struct *work);
3904 void rtl8180_hw_sleep_wq(struct net_device *dev);
3909 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
3910 void rtl8180_sw_antenna_wq(struct work_struct *work);
3912 void rtl8180_sw_antenna_wq(struct net_device *dev);
3914 void rtl8180_watch_dog(struct net_device *dev);
3915 void watch_dog_adaptive(unsigned long data)
3917 struct r8180_priv* priv = ieee80211_priv((struct net_device *)data);
3918 // DMESG("---->watch_dog_adaptive()\n");
3921 DMESG("<----watch_dog_adaptive():driver is not up!\n");
3925 // queue_work(priv->ieee80211->wq,&priv->ieee80211->watch_dog_wq);
3928 // Tx High Power Mechanism.
3930 if(CheckHighPower((struct net_device *)data))
3932 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->tx_pw_wq);
3936 #ifdef CONFIG_RTL818X_S
3937 // Tx Power Tracking on 87SE.
3939 //if( priv->bTxPowerTrack ) //lzm mod 080826
3940 if( CheckTxPwrTracking((struct net_device *)data));
3941 TxPwrTracking87SE((struct net_device *)data);
3945 // Perform DIG immediately.
3947 if(CheckDig((struct net_device *)data) == true)
3949 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_dig_wq);
3954 rtl8180_watch_dog((struct net_device *)data);
3957 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->GPIOChangeRFWorkItem);
3959 priv->watch_dog_timer.expires = jiffies + MSECS(IEEE80211_WATCH_DOG_TIME);
3960 add_timer(&priv->watch_dog_timer);
3961 // DMESG("<----watch_dog_adaptive()\n");
3964 #ifdef ENABLE_DOT11D
3966 static CHANNEL_LIST ChannelPlan[] = {
3967 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64},19}, //FCC
3968 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
3969 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
3970 {{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.
3971 {{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.
3972 {{14,36,40,44,48,52,56,60,64},9}, //MKK
3973 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14, 36,40,44,48,52,56,60,64},22},//MKK1
3974 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //Israel.
3975 {{1,2,3,4,5,6,7,8,9,10,11,12,13,34,38,42,46},17}, // For 11a , TELEC
3976 {{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
3977 {{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
3980 static void rtl8180_set_channel_map(u8 channel_plan, struct ieee80211_device *ieee)
3985 ieee->MinPassiveChnlNum=MAX_CHANNEL_NUMBER+1;
3986 ieee->IbssStartChnl=0;
3988 switch (channel_plan)
3990 case COUNTRY_CODE_FCC:
3991 case COUNTRY_CODE_IC:
3992 case COUNTRY_CODE_ETSI:
3993 case COUNTRY_CODE_SPAIN:
3994 case COUNTRY_CODE_FRANCE:
3995 case COUNTRY_CODE_MKK:
3996 case COUNTRY_CODE_MKK1:
3997 case COUNTRY_CODE_ISRAEL:
3998 case COUNTRY_CODE_TELEC:
4001 ieee->bGlobalDomain = false;
4002 if (ChannelPlan[channel_plan].Len != 0){
4003 // Clear old channel map
4004 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
4005 // Set new channel map
4006 for (i=0;i<ChannelPlan[channel_plan].Len;i++)
4008 if(ChannelPlan[channel_plan].Channel[i] <= 14)
4009 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
4014 case COUNTRY_CODE_GLOBAL_DOMAIN:
4016 GET_DOT11D_INFO(ieee)->bEnabled = 0;
4018 ieee->bGlobalDomain = true;
4021 case COUNTRY_CODE_WORLD_WIDE_13_INDEX://lzm add 080826
4023 ieee->MinPassiveChnlNum=12;
4024 ieee->IbssStartChnl= 10;
4030 ieee->bGlobalDomain = false;
4031 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
4034 GET_DOT11D_INFO(ieee)->channel_map[i] = 1;
4042 //Add for RF power on power off by lizhaoming 080512
4043 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
4044 void GPIOChangeRFWorkItemCallBack(struct work_struct *work);
4046 void GPIOChangeRFWorkItemCallBack(struct ieee80211_device *ieee);
4050 static void rtl8180_statistics_init(struct Stats *pstats)
4052 memset(pstats, 0, sizeof(struct Stats));
4054 static void rtl8180_link_detect_init(plink_detect_t plink_detect)
4056 memset(plink_detect, 0, sizeof(link_detect_t));
4057 plink_detect->SlotNum = DEFAULT_SLOT_NUM;
4061 short rtl8180_init(struct net_device *dev)
4063 struct r8180_priv *priv = ieee80211_priv(dev);
4072 #ifdef ENABLE_DOT11D
4074 for(i=0;i<0xFF;i++) {
4076 printk("\n[%x]: ", i/16);
4077 printk("\t%4.4x", eprom_read(dev,i));
4080 priv->channel_plan = eprom_read(dev, EEPROM_COUNTRY_CODE>>1) & 0xFF;
4081 if(priv->channel_plan > COUNTRY_CODE_GLOBAL_DOMAIN){
4082 printk("rtl8180_init:Error channel plan! Set to default.\n");
4083 priv->channel_plan = 0;
4085 //priv->channel_plan = 9; //Global Domain
4087 DMESG("Channel plan is %d\n",priv->channel_plan);
4088 rtl8180_set_channel_map(priv->channel_plan, priv->ieee80211);
4091 //Set Default Channel Plan
4093 DMESG("No channels, aborting");
4097 priv->channel_plan = 0;//hikaru
4098 // set channels 1..14 allowed in given locale
4099 for (i=1; i<=14; i++) {
4100 (priv->ieee80211->channel_map)[i] = (u8)(ch & 0x01);
4105 //memcpy(priv->stats,0,sizeof(struct Stats));
4107 //FIXME: these constants are placed in a bad pleace.
4108 priv->txbuffsize = 2048;//1024;
4109 priv->txringcount = 32;//32;
4110 priv->rxbuffersize = 2048;//1024;
4111 priv->rxringcount = 64;//32;
4112 priv->txbeaconcount = 2;
4113 priv->rx_skb_complete = 1;
4114 //priv->txnp_pending.ispending=0;
4115 /* ^^ the SKB does not containt a partial RXed
4119 #ifdef CONFIG_RTL8185B
4120 #ifdef CONFIG_RTL818X_S
4121 priv->RegThreeWireMode = HW_THREE_WIRE_SI;
4123 priv->RegThreeWireMode = SW_THREE_WIRE;
4127 //Add for RF power on power off by lizhaoming 080512
4128 priv->RFChangeInProgress = false;
4129 priv->SetRFPowerStateInProgress = false;
4130 priv->RFProgType = 0;
4131 priv->bInHctTest = false;
4133 priv->irq_enabled=0;
4135 //YJ,modified,080828
4137 priv->stats.rxdmafail=0;
4138 priv->stats.txrdu=0;
4139 priv->stats.rxrdu=0;
4140 priv->stats.rxnolast=0;
4141 priv->stats.rxnodata=0;
4142 //priv->stats.rxreset=0;
4143 //priv->stats.rxwrkaround=0;
4144 priv->stats.rxnopointer=0;
4145 priv->stats.txnperr=0;
4146 priv->stats.txresumed=0;
4147 priv->stats.rxerr=0;
4148 priv->stats.rxoverflow=0;
4149 priv->stats.rxint=0;
4150 priv->stats.txnpokint=0;
4151 priv->stats.txhpokint=0;
4152 priv->stats.txhperr=0;
4154 priv->stats.shints=0;
4155 priv->stats.txoverflow=0;
4156 priv->stats.txbeacon=0;
4157 priv->stats.txbeaconerr=0;
4158 priv->stats.txlperr=0;
4159 priv->stats.txlpokint=0;
4160 priv->stats.txretry=0;//tony 20060601
4161 priv->stats.rxcrcerrmin=0;
4162 priv->stats.rxcrcerrmid=0;
4163 priv->stats.rxcrcerrmax=0;
4164 priv->stats.rxicverr=0;
4166 rtl8180_statistics_init(&priv->stats);
4167 rtl8180_link_detect_init(&priv->link_detect);
4169 //YJ,modified,080828,end
4172 priv->ack_tx_to_ieee = 0;
4173 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
4174 priv->ieee80211->iw_mode = IW_MODE_INFRA;
4175 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
4176 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
4177 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;
4178 priv->ieee80211->active_scan = 1;
4179 priv->ieee80211->rate = 110; //11 mbps
4180 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION;
4181 priv->ieee80211->host_encrypt = 1;
4182 priv->ieee80211->host_decrypt = 1;
4183 priv->ieee80211->sta_wake_up = rtl8180_hw_wakeup;
4184 priv->ieee80211->ps_request_tx_ack = rtl8180_rq_tx_ack;
4185 priv->ieee80211->enter_sleep_state = rtl8180_hw_sleep;
4186 priv->ieee80211->ps_is_queue_empty = rtl8180_is_tx_queue_empty;
4188 priv->hw_wep = hwwep;
4191 priv->retry_rts = DEFAULT_RETRY_RTS;
4192 priv->retry_data = DEFAULT_RETRY_DATA;
4193 priv->RFChangeInProgress = false;
4194 priv->SetRFPowerStateInProgress = false;
4195 priv->RFProgType = 0;
4196 priv->bInHctTest = false;
4197 priv->bInactivePs = true;//false;
4198 priv->ieee80211->bInactivePs = priv->bInactivePs;
4199 priv->bSwRfProcessing = false;
4200 priv->eRFPowerState = eRfOff;
4201 priv->RfOffReason = 0;
4202 priv->LedStrategy = SW_LED_MODE0;
4203 //priv->NumRxOkInPeriod = 0; //YJ,del,080828
4204 //priv->NumTxOkInPeriod = 0; //YJ,del,080828
4205 priv->TxPollingTimes = 0;//lzm add 080826
4206 priv->bLeisurePs = true;
4207 priv->dot11PowerSaveMode = eActive;
4208 //by amy for antenna
4209 priv->AdMinCheckPeriod = 5;
4210 priv->AdMaxCheckPeriod = 10;
4211 // Lower signal strength threshold to fit the HW participation in antenna diversity. +by amy 080312
4212 priv->AdMaxRxSsThreshold = 30;//60->30
4213 priv->AdRxSsThreshold = 20;//50->20
4214 priv->AdCheckPeriod = priv->AdMinCheckPeriod;
4215 priv->AdTickCount = 0;
4216 priv->AdRxSignalStrength = -1;
4217 priv->RegSwAntennaDiversityMechanism = 0;
4218 priv->RegDefaultAntenna = 0;
4219 priv->SignalStrength = 0;
4220 priv->AdRxOkCnt = 0;
4221 priv->CurrAntennaIndex = 0;
4222 priv->AdRxSsBeforeSwitched = 0;
4223 init_timer(&priv->SwAntennaDiversityTimer);
4224 priv->SwAntennaDiversityTimer.data = (unsigned long)dev;
4225 priv->SwAntennaDiversityTimer.function = (void *)SwAntennaDiversityTimerCallback;
4226 //by amy for antenna
4228 priv->bDigMechanism = 1;
4229 priv->InitialGain = 6;
4230 priv->bXtalCalibration = false;
4231 priv->XtalCal_Xin = 0;
4232 priv->XtalCal_Xout = 0;
4233 priv->bTxPowerTrack = false;
4234 priv->ThermalMeter = 0;
4235 priv->FalseAlarmRegValue = 0;
4236 priv->RegDigOfdmFaUpTh = 0xc; // Upper threhold of OFDM false alarm, which is used in DIG.
4237 priv->DIG_NumberFallbackVote = 0;
4238 priv->DIG_NumberUpgradeVote = 0;
4239 priv->LastSignalStrengthInPercent = 0;
4240 priv->Stats_SignalStrength = 0;
4241 priv->LastRxPktAntenna = 0;
4242 priv->SignalQuality = 0; // in 0-100 index.
4243 priv->Stats_SignalQuality = 0;
4244 priv->RecvSignalPower = 0; // in dBm.
4245 priv->Stats_RecvSignalPower = 0;
4246 priv->AdMainAntennaRxOkCnt = 0;
4247 priv->AdAuxAntennaRxOkCnt = 0;
4248 priv->bHWAdSwitched = false;
4249 priv->bRegHighPowerMechanism = true;
4250 priv->RegHiPwrUpperTh = 77;
4251 priv->RegHiPwrLowerTh = 75;
4252 priv->RegRSSIHiPwrUpperTh = 70;
4253 priv->RegRSSIHiPwrLowerTh = 20;
4254 priv->bCurCCKPkt = false;
4255 priv->UndecoratedSmoothedSS = -1;
4256 priv->bToUpdateTxPwr = false;
4257 priv->CurCCKRSSI = 0;
4261 priv->NumTxOkTotal = 0;
4262 priv->NumTxUnicast = 0;
4263 priv->keepAliveLevel = DEFAULT_KEEP_ALIVE_LEVEL;
4264 priv->PowerProfile = POWER_PROFILE_AC;
4266 //by amy for rate adaptive
4267 priv->CurrRetryCnt=0;
4268 priv->LastRetryCnt=0;
4269 priv->LastTxokCnt=0;
4270 priv->LastRxokCnt=0;
4271 priv->LastRetryRate=0;
4274 priv->CurrRetryRate=0;
4275 priv->TryupingCount=0;
4276 priv->TryupingCountNoData=0;
4277 priv->TryDownCountLowData=0;
4278 priv->LastTxOKBytes=0;
4279 priv->LastFailTxRate=0;
4280 priv->LastFailTxRateSS=0;
4281 priv->FailTxRateCount=0;
4282 priv->LastTxThroughput=0;
4283 priv->NumTxOkBytesTotal=0;
4284 priv->ForcedDataRate = 0;
4285 priv->RegBModeGainStage = 1;
4287 //by amy for rate adaptive
4289 priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
4290 spin_lock_init(&priv->irq_lock);
4291 spin_lock_init(&priv->irq_th_lock);
4292 spin_lock_init(&priv->tx_lock);
4293 spin_lock_init(&priv->ps_lock);
4294 spin_lock_init(&priv->rf_ps_lock);
4295 sema_init(&priv->wx_sem,1);
4296 sema_init(&priv->rf_state,1);
4297 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
4298 INIT_WORK(&priv->reset_wq,(void*) rtl8180_restart_wq);
4299 INIT_WORK(&priv->tx_irq_wq,(void*) rtl8180_tx_irq_wq);
4300 INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8180_hw_wakeup_wq);
4301 INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8180_hw_sleep_wq);
4302 //INIT_DELAYED_WORK(&priv->ieee80211->watch_dog_wq,(void*) rtl8180_watch_dog_wq);
4303 //INIT_DELAYED_WORK(&priv->ieee80211->sw_antenna_wq,(void*) rtl8180_sw_antenna_wq);
4304 INIT_WORK(&priv->ieee80211->wmm_param_update_wq,(void*) rtl8180_wmm_param_update);
4305 INIT_DELAYED_WORK(&priv->ieee80211->rate_adapter_wq,(void*)rtl8180_rate_adapter);//+by amy 080312
4306 INIT_DELAYED_WORK(&priv->ieee80211->hw_dig_wq,(void*)rtl8180_hw_dig_wq);//+by amy 080312
4307 INIT_DELAYED_WORK(&priv->ieee80211->tx_pw_wq,(void*)rtl8180_tx_pw_wq);//+by amy 080312
4309 //add for RF power on power off by lizhaoming 080512
4310 INIT_DELAYED_WORK(&priv->ieee80211->GPIOChangeRFWorkItem,(void*) GPIOChangeRFWorkItemCallBack);
4312 INIT_WORK(&priv->reset_wq,(void*) rtl8180_restart_wq,dev);
4313 INIT_WORK(&priv->tx_irq_wq,(void*) rtl8180_tx_irq_wq,dev);
4314 //INIT_WORK(&priv->ieee80211->watch_dog_wq,(void*) rtl8180_watch_dog_wq,dev);
4315 INIT_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8180_hw_wakeup_wq,dev);
4316 INIT_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8180_hw_sleep_wq,dev);
4317 //INIT_WORK(&priv->ieee80211->sw_antenna_wq,(void*) rtl8180_sw_antenna_wq,dev);
4318 INIT_WORK(&priv->ieee80211->wmm_param_update_wq,(void*) rtl8180_wmm_param_update,priv->ieee80211);
4319 INIT_WORK(&priv->ieee80211->rate_adapter_wq,(void*)rtl8180_rate_adapter,dev);//+by amy 080312
4320 INIT_WORK(&priv->ieee80211->hw_dig_wq,(void*)rtl8180_hw_dig_wq,dev);//+by amy 080312
4321 INIT_WORK(&priv->ieee80211->tx_pw_wq,(void*)rtl8180_tx_pw_wq,dev);//+by amy 080312
4323 //add for RF power on power off by lizhaoming 080512
4324 INIT_WORK(&priv->ieee80211->GPIOChangeRFWorkItem,(void*) GPIOChangeRFWorkItemCallBack, priv->ieee80211);
4326 //INIT_WORK(&priv->reset_wq,(void*) rtl8180_restart_wq,dev);
4328 tasklet_init(&priv->irq_rx_tasklet,
4329 (void(*)(unsigned long)) rtl8180_irq_rx_tasklet,
4330 (unsigned long)priv);
4332 init_timer(&priv->watch_dog_timer);
4333 priv->watch_dog_timer.data = (unsigned long)dev;
4334 priv->watch_dog_timer.function = watch_dog_adaptive;
4338 //by amy for rate adaptive
4339 init_timer(&priv->rateadapter_timer);
4340 priv->rateadapter_timer.data = (unsigned long)dev;
4341 priv->rateadapter_timer.function = timer_rate_adaptive;
4342 priv->RateAdaptivePeriod= RATE_ADAPTIVE_TIMER_PERIOD;
4343 priv->bEnhanceTxPwr=false;
4344 //by amy for rate adaptive
4346 //priv->ieee80211->func =
4347 // kmalloc(sizeof(struct ieee80211_helper_functions),GFP_KERNEL);
4348 //memset(priv->ieee80211->func, 0,
4349 // sizeof(struct ieee80211_helper_functions));
4351 priv->ieee80211->softmac_hard_start_xmit = rtl8180_hard_start_xmit;
4352 priv->ieee80211->set_chan = rtl8180_set_chan;
4353 priv->ieee80211->link_change = rtl8180_link_change;
4354 priv->ieee80211->softmac_data_hard_start_xmit = rtl8180_hard_data_xmit;
4355 priv->ieee80211->data_hard_stop = rtl8180_data_hard_stop;
4356 priv->ieee80211->data_hard_resume = rtl8180_data_hard_resume;
4358 priv->ieee80211->init_wmmparam_flag = 0;
4360 priv->ieee80211->start_send_beacons = rtl8180_start_tx_beacon;
4361 priv->ieee80211->stop_send_beacons = rtl8180_beacon_tx_disable;
4362 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
4364 #ifdef CONFIG_RTL8185B
4365 priv->MWIEnable = 0;
4367 priv->ShortRetryLimit = 7;
4368 priv->LongRetryLimit = 7;
4369 priv->EarlyRxThreshold = 7;
4371 priv->CSMethod = (0x01 << 29);
4373 priv->TransmitConfig =
4374 1<<TCR_DurProcMode_OFFSET | //for RTL8185B, duration setting by HW
4375 (7<<TCR_MXDMA_OFFSET) | // Max DMA Burst Size per Tx DMA Burst, 7: reservied.
4376 (priv->ShortRetryLimit<<TCR_SRL_OFFSET) | // Short retry limit
4377 (priv->LongRetryLimit<<TCR_LRL_OFFSET) | // Long retry limit
4378 (0 ? TCR_SAT : 0); // FALSE: HW provies PLCP length and LENGEXT, TURE: SW proiveds them
4380 priv->ReceiveConfig =
4381 #ifdef CONFIG_RTL818X_S
4386 RCR_AMF | RCR_ADF | //accept management/data
4387 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
4388 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
4389 //RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet
4390 (7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
4391 (priv->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold.
4392 (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT:0);
4394 priv->IntrMask = IMR_TMGDOK | IMR_TBDER | IMR_THPDER |
4395 IMR_THPDER | IMR_THPDOK |
4396 IMR_TVODER | IMR_TVODOK |
4397 IMR_TVIDER | IMR_TVIDOK |
4398 IMR_TBEDER | IMR_TBEDOK |
4399 IMR_TBKDER | IMR_TBKDOK |
4400 IMR_RDU | // To handle the defragmentation not enough Rx descriptors case. Annie, 2006-03-27.
4402 IMR_RQoSOK; // <NOTE> ROK and RQoSOK are mutually exclusive, so, we must handle RQoSOK interrupt to receive QoS frames, 2005.12.09, by rcnjko.
4404 priv->InitialGain = 6;
4407 hw_version =( read_nic_dword(dev, TCR) & TCR_HWVERID_MASK)>>TCR_HWVERID_SHIFT;
4409 switch (hw_version){
4410 #ifdef CONFIG_RTL8185B
4411 case HW_VERID_R8185B_B:
4412 #ifdef CONFIG_RTL818X_S
4413 priv->card_8185 = VERSION_8187S_C;
4414 DMESG("MAC controller is a RTL8187SE b/g");
4418 DMESG("MAC controller is a RTL8185B b/g");
4419 priv->card_8185 = 3;
4424 case HW_VERID_R8185_ABC:
4425 DMESG("MAC controller is a RTL8185 b/g");
4426 priv->card_8185 = 1;
4427 /* you should not find a card with 8225 PHY ver < C*/
4431 case HW_VERID_R8185_D:
4432 DMESG("MAC controller is a RTL8185 b/g (V. D)");
4433 priv->card_8185 = 2;
4434 /* you should not find a card with 8225 PHY ver < C*/
4438 case HW_VERID_R8180_ABCD:
4439 DMESG("MAC controller is a RTL8180");
4440 priv->card_8185 = 0;
4443 case HW_VERID_R8180_F:
4444 DMESG("MAC controller is a RTL8180 (v. F)");
4445 priv->card_8185 = 0;
4449 DMESGW("MAC chip not recognized: version %x. Assuming RTL8180",hw_version);
4450 priv->card_8185 = 0;
4454 if(priv->card_8185){
4455 priv->ieee80211->modulation |= IEEE80211_OFDM_MODULATION;
4456 priv->ieee80211->short_slot = 1;
4458 /* you should not found any 8185 Ver B Card */
4459 priv->card_8185_Bversion = 0;
4461 #ifdef CONFIG_RTL8185B
4462 #ifdef CONFIG_RTL818X_S
4464 priv->card_type = PCI;
4465 DMESG("This is a PCI NIC");
4467 config3 = read_nic_byte(dev, CONFIG3);
4469 priv->card_type = CARDBUS;
4470 DMESG("This is a CARDBUS NIC");
4472 else if( config3 & 0x4){
4473 priv->card_type = MINIPCI;
4474 DMESG("This is a MINI-PCI NIC");
4476 priv->card_type = PCI;
4477 DMESG("This is a PCI NIC");
4481 priv->enable_gpio0 = 0;
4483 //by amy for antenna
4484 #ifdef CONFIG_RTL8185B
4485 usValue = eprom_read(dev, EEPROM_SW_REVD_OFFSET);
4486 DMESG("usValue is 0x%x\n",usValue);
4487 #ifdef CONFIG_RTL818X_S
4488 //3Read AntennaDiversity
4489 // SW Antenna Diversity.
4490 if( (usValue & EEPROM_SW_AD_MASK) != EEPROM_SW_AD_ENABLE )
4492 priv->EEPROMSwAntennaDiversity = false;
4493 //printk("EEPROM Disable SW Antenna Diversity\n");
4497 priv->EEPROMSwAntennaDiversity = true;
4498 //printk("EEPROM Enable SW Antenna Diversity\n");
4500 // Default Antenna to use.
4501 if( (usValue & EEPROM_DEF_ANT_MASK) != EEPROM_DEF_ANT_1 )
4503 priv->EEPROMDefaultAntenna1 = false;
4504 //printk("EEPROM Default Antenna 0\n");
4508 priv->EEPROMDefaultAntenna1 = true;
4509 //printk("EEPROM Default Antenna 1\n");
4513 // Antenna diversity mechanism. Added by Roger, 2007.11.05.
4515 if( priv->RegSwAntennaDiversityMechanism == 0 ) // Auto
4516 {// 0: default from EEPROM.
4517 priv->bSwAntennaDiverity = priv->EEPROMSwAntennaDiversity;
4520 {// 1:disable antenna diversity, 2: enable antenna diversity.
4521 priv->bSwAntennaDiverity = ((priv->RegSwAntennaDiversityMechanism == 1)? false : true);
4523 //printk("bSwAntennaDiverity = %d\n", priv->bSwAntennaDiverity);
4527 // Default antenna settings. Added by Roger, 2007.11.05.
4529 if( priv->RegDefaultAntenna == 0)
4530 {// 0: default from EEPROM.
4531 priv->bDefaultAntenna1 = priv->EEPROMDefaultAntenna1;
4534 {// 1: main, 2: aux.
4535 priv->bDefaultAntenna1 = ((priv->RegDefaultAntenna== 2) ? true : false);
4537 //printk("bDefaultAntenna1 = %d\n", priv->bDefaultAntenna1);
4540 //by amy for antenna
4541 /* rtl8185 can calc plcp len in HW.*/
4542 priv->hw_plcp_len = 1;
4544 priv->plcp_preamble_mode = 2;
4545 /*the eeprom type is stored in RCR register bit #6 */
4546 if (RCR_9356SEL & read_nic_dword(dev, RCR)){
4547 priv->epromtype=EPROM_93c56;
4548 //DMESG("Reported EEPROM chip is a 93c56 (2Kbit)");
4550 priv->epromtype=EPROM_93c46;
4551 //DMESG("Reported EEPROM chip is a 93c46 (1Kbit)");
4554 dev->get_stats = rtl8180_stats;
4556 dev->dev_addr[0]=eprom_read(dev,MAC_ADR) & 0xff;
4557 dev->dev_addr[1]=(eprom_read(dev,MAC_ADR) & 0xff00)>>8;
4558 dev->dev_addr[2]=eprom_read(dev,MAC_ADR+1) & 0xff;
4559 dev->dev_addr[3]=(eprom_read(dev,MAC_ADR+1) & 0xff00)>>8;
4560 dev->dev_addr[4]=eprom_read(dev,MAC_ADR+2) & 0xff;
4561 dev->dev_addr[5]=(eprom_read(dev,MAC_ADR+2) & 0xff00)>>8;
4562 //DMESG("Card MAC address is "MAC_FMT, MAC_ARG(dev->dev_addr));
4565 for(i=1,j=0; i<14; i+=2,j++){
4567 word = eprom_read(dev,EPROM_TXPW_CH1_2 + j);
4568 priv->chtxpwr[i]=word & 0xff;
4569 priv->chtxpwr[i+1]=(word & 0xff00)>>8;
4571 DMESG("tx word %x:%x",j,word);
4572 DMESG("ch %d pwr %x",i,priv->chtxpwr[i]);
4573 DMESG("ch %d pwr %x",i+1,priv->chtxpwr[i+1]);
4576 if(priv->card_8185){
4577 for(i=1,j=0; i<14; i+=2,j++){
4579 word = eprom_read(dev,EPROM_TXPW_OFDM_CH1_2 + j);
4580 priv->chtxpwr_ofdm[i]=word & 0xff;
4581 priv->chtxpwr_ofdm[i+1]=(word & 0xff00)>>8;
4583 DMESG("ofdm tx word %x:%x",j,word);
4584 DMESG("ofdm ch %d pwr %x",i,priv->chtxpwr_ofdm[i]);
4585 DMESG("ofdm ch %d pwr %x",i+1,priv->chtxpwr_ofdm[i+1]);
4590 //3Read crystal calibtration and thermal meter indication on 87SE.
4592 // By SD3 SY's request. Added by Roger, 2007.12.11.
4594 tmpu16 = eprom_read(dev, EEPROM_RSV>>1);
4596 //printk("ReadAdapterInfo8185(): EEPROM_RSV(%04x)\n", tmpu16);
4598 // Crystal calibration for Xin and Xout resp.
4599 priv->XtalCal_Xout = tmpu16 & EEPROM_XTAL_CAL_XOUT_MASK; // 0~7.5pF
4600 priv->XtalCal_Xin = (tmpu16 & EEPROM_XTAL_CAL_XIN_MASK)>>4; // 0~7.5pF
4601 if((tmpu16 & EEPROM_XTAL_CAL_ENABLE)>>12)
4602 priv->bXtalCalibration = true;
4604 // Thermal meter reference indication.
4605 priv->ThermalMeter = (u8)((tmpu16 & EEPROM_THERMAL_METER_MASK)>>8);
4606 if((tmpu16 & EEPROM_THERMAL_METER_ENABLE)>>13)
4607 priv->bTxPowerTrack = true;
4610 #ifdef CONFIG_RTL8185B
4611 word = eprom_read(dev,EPROM_TXPW_BASE);
4612 priv->cck_txpwr_base = word & 0xf;
4613 priv->ofdm_txpwr_base = (word>>4) & 0xf;
4616 version = eprom_read(dev,EPROM_VERSION);
4617 DMESG("EEPROM version %x",version);
4618 if( (!priv->card_8185) && version < 0x0101){
4619 DMESG ("EEPROM version too old, assuming defaults");
4620 DMESG ("If you see this message *plase* send your \
4621 DMESG output to andreamrl@tiscali.it THANKS");
4625 priv->cs_treshold=0xc;
4627 priv->rf_chip=RFCHIPID_PHILIPS;
4629 if(!priv->card_8185){
4630 u8 rfparam = eprom_read(dev,RF_PARAM);
4631 DMESG("RfParam: %x",rfparam);
4633 priv->digphy = rfparam & (1<<RF_PARAM_DIGPHY_SHIFT) ? 0:1;
4634 priv->antb = rfparam & (1<<RF_PARAM_ANTBDEFAULT_SHIFT) ? 1:0;
4636 priv->rcr_csense = (rfparam & RF_PARAM_CARRIERSENSE_MASK) >>
4637 RF_PARAM_CARRIERSENSE_SHIFT;
4640 (read_nic_byte(dev,CONFIG2)&(1<<CONFIG2_ANTENNA_SHIFT)) ? 1:0;
4642 priv->rcr_csense = 3;
4645 priv->cs_treshold = (eprom_read(dev,ENERGY_TRESHOLD)&0xff00) >>8;
4647 priv->rf_chip = 0xff & eprom_read(dev,RFCHIPID);
4650 #ifdef CONFIG_RTL8185B
4651 #ifdef CONFIG_RTL818X_S
4652 priv->rf_chip = RF_ZEBRA4;
4653 priv->rf_sleep = rtl8225z4_rf_sleep;
4654 priv->rf_wakeup = rtl8225z4_rf_wakeup;
4656 priv->rf_chip = RF_ZEBRA2;
4658 //DMESG("Card reports RF frontend Realtek 8225z2");
4659 //DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4660 //DMESGW("use it with care and at your own risk and");
4661 DMESGW("**PLEASE** REPORT SUCCESSFUL/UNSUCCESSFUL TO Realtek!");
4663 priv->rf_close = rtl8225z2_rf_close;
4664 priv->rf_init = rtl8225z2_rf_init;
4665 priv->rf_set_chan = rtl8225z2_rf_set_chan;
4666 priv->rf_set_sens = NULL;
4667 //priv->rf_sleep = rtl8225_rf_sleep;
4668 //priv->rf_wakeup = rtl8225_rf_wakeup;
4671 /* check RF frontend chipset */
4672 switch (priv->rf_chip) {
4674 case RFCHIPID_RTL8225:
4676 if(priv->card_8185){
4677 DMESG("Card reports RF frontend Realtek 8225");
4678 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4679 DMESGW("use it with care and at your own risk and");
4680 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4682 priv->rf_close = rtl8225_rf_close;
4683 priv->rf_init = rtl8225_rf_init;
4684 priv->rf_set_chan = rtl8225_rf_set_chan;
4685 priv->rf_set_sens = NULL;
4686 priv->rf_sleep = rtl8225_rf_sleep;
4687 priv->rf_wakeup = rtl8225_rf_wakeup;
4690 DMESGW("Detected RTL8225 radio on a card recognized as RTL8180");
4691 DMESGW("This could not be... something went wrong....");
4696 case RFCHIPID_RTL8255:
4697 if(priv->card_8185){
4698 DMESG("Card reports RF frontend Realtek 8255");
4699 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4700 DMESGW("use it with care and at your own risk and");
4701 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4703 priv->rf_close = rtl8255_rf_close;
4704 priv->rf_init = rtl8255_rf_init;
4705 priv->rf_set_chan = rtl8255_rf_set_chan;
4706 priv->rf_set_sens = NULL;
4707 priv->rf_sleep = NULL;
4708 priv->rf_wakeup = NULL;
4711 DMESGW("Detected RTL8255 radio on a card recognized as RTL8180");
4712 DMESGW("This could not be... something went wrong....");
4718 case RFCHIPID_INTERSIL:
4719 DMESGW("Card reports RF frontend by Intersil.");
4720 DMESGW("This driver has NO support for this chipset.");
4725 DMESGW("Card reports RF frontend by RFMD.");
4726 DMESGW("This driver has NO support for this chipset.");
4731 DMESGW("Card reports RF frontend by GCT.");
4732 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4733 DMESGW("use it with care and at your own risk and");
4734 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4735 priv->rf_close = gct_rf_close;
4736 priv->rf_init = gct_rf_init;
4737 priv->rf_set_chan = gct_rf_set_chan;
4738 priv->rf_set_sens = NULL;
4739 priv->rf_sleep = NULL;
4740 priv->rf_wakeup = NULL;
4743 case RFCHIPID_MAXIM:
4744 DMESGW("Card reports RF frontend by MAXIM.");
4745 DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4746 DMESGW("use it with care and at your own risk and");
4747 DMESGW("**PLEASE** REPORT SUCCESS/INSUCCESS TO andreamrl@tiscali.it");
4748 priv->rf_close = maxim_rf_close;
4749 priv->rf_init = maxim_rf_init;
4750 priv->rf_set_chan = maxim_rf_set_chan;
4751 priv->rf_set_sens = NULL;
4752 priv->rf_sleep = NULL;
4753 priv->rf_wakeup = NULL;
4756 case RFCHIPID_PHILIPS:
4757 DMESG("Card reports RF frontend by Philips.");
4758 DMESG("OK! Philips SA2400 radio chipset is supported.");
4759 priv->rf_close = sa2400_rf_close;
4760 priv->rf_init = sa2400_rf_init;
4761 priv->rf_set_chan = sa2400_rf_set_chan;
4762 priv->rf_set_sens = sa2400_rf_set_sens;
4763 priv->sens = SA2400_RF_DEF_SENS; /* default sensitivity */
4764 priv->max_sens = SA2400_RF_MAX_SENS; /* maximum sensitivity */
4765 priv->rf_sleep = NULL;
4766 priv->rf_wakeup = NULL;
4769 DMESGW("Digital PHY found");
4770 DMESGW("Philips DIGITAL PHY is untested! *Please*\
4771 report success/failure to <andreamrl@tiscali.it>");
4773 DMESG ("Analog PHY found");
4779 DMESGW("Unknown RF module %x",priv->rf_chip);
4780 DMESGW("Exiting...");
4787 if(!priv->card_8185){
4789 DMESG ("Antenna B is default antenna");
4791 DMESG ("Antenna A is default antenna");
4794 DMESG ("Antenna diversity is enabled");
4796 DMESG("Antenna diversity is disabled");
4798 DMESG("Carrier sense %d",priv->rcr_csense);
4801 if (0!=alloc_rx_desc_ring(dev, priv->rxbuffersize, priv->rxringcount))
4804 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4805 TX_MANAGEPRIORITY_RING_ADDR))
4808 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4809 TX_BKPRIORITY_RING_ADDR))
4812 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4813 TX_BEPRIORITY_RING_ADDR))
4816 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4817 TX_VIPRIORITY_RING_ADDR))
4820 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4821 TX_VOPRIORITY_RING_ADDR))
4824 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4825 TX_HIGHPRIORITY_RING_ADDR))
4828 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txbeaconcount,
4829 TX_BEACON_RING_ADDR))
4833 //priv->beacon_buf=NULL;
4835 if(!priv->card_8185){
4837 if(read_nic_byte(dev, CONFIG0) & (1<<CONFIG0_WEP40_SHIFT))
4838 DMESG ("40-bit WEP is supported in hardware");
4840 DMESG ("40-bit WEP is NOT supported in hardware");
4842 if(read_nic_byte(dev,CONFIG0) & (1<<CONFIG0_WEP104_SHIFT))
4843 DMESG ("104-bit WEP is supported in hardware");
4845 DMESG ("104-bit WEP is NOT supported in hardware");
4847 #if !defined(SA_SHIRQ)
4848 if(request_irq(dev->irq, (void *)rtl8180_interrupt, IRQF_SHARED, dev->name, dev)){
4850 if(request_irq(dev->irq, (void *)rtl8180_interrupt, SA_SHIRQ, dev->name, dev)){
4852 DMESGE("Error allocating IRQ %d",dev->irq);
4856 DMESG("IRQ %d",dev->irq);
4868 void rtl8180_no_hw_wep(struct net_device *dev)
4870 struct r8180_priv *priv = ieee80211_priv(dev);
4872 if(!priv->card_8185)
4876 security = read_nic_byte(dev, SECURITY);
4877 security &=~(1<<SECURITY_WEP_TX_ENABLE_SHIFT);
4878 security &=~(1<<SECURITY_WEP_RX_ENABLE_SHIFT);
4880 write_nic_byte(dev, SECURITY, security);
4887 write_nic_dword(dev,TX_CONF,read_nic_dword(dev,TX_CONF) |
4888 (1<<TX_NOICV_SHIFT) );
4890 // priv->ieee80211->hw_wep=0;
4894 void rtl8180_set_hw_wep(struct net_device *dev)
4896 struct r8180_priv *priv = ieee80211_priv(dev);
4901 pgreg=read_nic_byte(dev, PGSELECT);
4902 write_nic_byte(dev, PGSELECT, pgreg &~ (1<<PGSELECT_PG_SHIFT));
4904 key0_word4 = read_nic_dword(dev, KEY0+4+4+4);
4905 key0_word4 &= ~ 0xff;
4906 key0_word4 |= priv->key0[3]& 0xff;
4907 write_nic_dword(dev,KEY0,(priv->key0[0]));
4908 write_nic_dword(dev,KEY0+4,(priv->key0[1]));
4909 write_nic_dword(dev,KEY0+4+4,(priv->key0[2]));
4910 write_nic_dword(dev,KEY0+4+4+4,(key0_word4));
4913 TX_CONF,read_nic_dword(dev,TX_CONF) &~(1<<TX_NOICV_SHIFT));
4916 security = read_nic_byte(dev,SECURITY);
4917 security |= (1<<SECURITY_WEP_TX_ENABLE_SHIFT);
4918 security |= (1<<SECURITY_WEP_RX_ENABLE_SHIFT);
4919 security &= ~ SECURITY_ENCRYP_MASK;
4920 security |= (SECURITY_ENCRYP_104<<SECURITY_ENCRYP_SHIFT);
4922 write_nic_byte(dev, SECURITY, security);
4924 DMESG("key %x %x %x %x",read_nic_dword(dev,KEY0+4+4+4),
4925 read_nic_dword(dev,KEY0+4+4),read_nic_dword(dev,KEY0+4),
4926 read_nic_dword(dev,KEY0));
4928 //priv->ieee80211->hw_wep=1;
4932 void rtl8185_rf_pins_enable(struct net_device *dev)
4935 // tmp = read_nic_word(dev, RFPinsEnable);
4936 write_nic_word(dev, RFPinsEnable, 0x1fff);// | tmp);
4937 // write_nic_word(dev, RFPinsEnable,7 | tmp);
4941 void rtl8185_set_anaparam2(struct net_device *dev, u32 a)
4945 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
4947 conf3 = read_nic_byte(dev, CONFIG3);
4948 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
4949 write_nic_dword(dev, ANAPARAM2, a);
4951 conf3 = read_nic_byte(dev, CONFIG3);
4952 write_nic_byte(dev, CONFIG3, conf3 &~(1<<CONFIG3_ANAPARAM_W_SHIFT));
4953 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
4958 void rtl8180_set_anaparam(struct net_device *dev, u32 a)
4962 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
4964 conf3 = read_nic_byte(dev, CONFIG3);
4965 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
4966 write_nic_dword(dev, ANAPARAM, a);
4968 conf3 = read_nic_byte(dev, CONFIG3);
4969 write_nic_byte(dev, CONFIG3, conf3 &~(1<<CONFIG3_ANAPARAM_W_SHIFT));
4970 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
4974 void rtl8185_tx_antenna(struct net_device *dev, u8 ant)
4976 write_nic_byte(dev, TX_ANTENNA, ant);
4977 force_pci_posting(dev);
4982 void rtl8185_write_phy(struct net_device *dev, u8 adr, u32 data)
4990 phyw= ((data<<8) | adr);
4993 write_nic_dword(dev, PHY_ADR, phyw);
4995 //read_nic_dword(dev, PHY_ADR);
4997 write_nic_dword(dev, PHY_ADR, 0xffffff7f & phyw);
4998 phyr = read_nic_byte(dev, PHY_READ);
4999 if(phyr == (data&0xff)) break;
5003 // Note that, we must write 0xff7c after 0x7d-0x7f to write BB register.
5004 write_nic_byte(dev, 0x7f, ((phyw & 0xff000000) >> 24));
5005 write_nic_byte(dev, 0x7e, ((phyw & 0x00ff0000) >> 16));
5006 write_nic_byte(dev, 0x7d, ((phyw & 0x0000ff00) >> 8));
5007 write_nic_byte(dev, 0x7c, ((phyw & 0x000000ff) ));
5009 /* this is ok to fail when we write AGC table. check for AGC table might be
5010 * done by masking with 0x7f instead of 0xff
5012 //if(phyr != (data&0xff)) DMESGW("Phy write timeout %x %x %x", phyr, data,adr);
5016 inline void write_phy_ofdm (struct net_device *dev, u8 adr, u32 data)
5019 rtl8185_write_phy(dev, adr, data);
5023 void write_phy_cck (struct net_device *dev, u8 adr, u32 data)
5026 rtl8185_write_phy(dev, adr, data | 0x10000);
5031 * I hope this is enougth
5034 void write_phy(struct net_device *dev, u8 adr, u8 data)
5041 phy |= 0x80; /* this should enable writing */
5044 //PHY_ADR, PHY_R and PHY_W are contig and treated as one dword
5045 write_nic_dword(dev,PHY_ADR, phy);
5050 write_nic_dword(dev,PHY_ADR, phy);
5051 for(i=0;i<MAX_PHY;i++){
5052 phy=read_nic_dword(dev,PHY_ADR);
5053 phy= phy & 0xff0000;
5055 if(phy == data){ //SUCCESS!
5056 force_pci_posting(dev);
5057 mdelay(3); //random value
5059 DMESG("Phy wr %x,%x",adr,data);
5063 force_pci_posting(dev);
5064 mdelay(3); //random value
5067 DMESGW ("Phy writing %x %x failed!", adr,data);
5070 void rtl8185_set_rate(struct net_device *dev)
5074 int basic_rate,min_rr_rate,max_rr_rate;
5076 // struct r8180_priv *priv = ieee80211_priv(dev);
5078 //if (ieee80211_is_54g(priv->ieee80211->current_network) &&
5079 // priv->ieee80211->state == IEEE80211_LINKED){
5080 basic_rate = ieeerate2rtlrate(240);
5081 min_rr_rate = ieeerate2rtlrate(60);
5082 max_rr_rate = ieeerate2rtlrate(240);
5086 // basic_rate = ieeerate2rtlrate(20);
5087 // min_rr_rate = ieeerate2rtlrate(10);
5088 // max_rr_rate = ieeerate2rtlrate(110);
5091 write_nic_byte(dev, RESP_RATE,
5092 max_rr_rate<<MAX_RESP_RATE_SHIFT| min_rr_rate<<MIN_RESP_RATE_SHIFT);
5094 word = read_nic_word(dev, BRSR);
5095 word &= ~BRSR_MBR_8185;
5098 for(i=0;i<=basic_rate;i++)
5101 write_nic_word(dev, BRSR, word);
5102 //DMESG("RR:%x BRSR: %x", read_nic_byte(dev,RESP_RATE),read_nic_word(dev,BRSR));
5107 void rtl8180_adapter_start(struct net_device *dev)
5109 struct r8180_priv *priv = ieee80211_priv(dev);
5115 rtl8180_rtx_disable(dev);
5118 /* seems that 0xffff or 0xafff will cause
5119 * HW interrupt line crash
5122 //priv->irq_mask = 0xafff;
5123 // priv->irq_mask = 0x4fcf;
5125 /* enable beacon timeout, beacon TX ok and err
5126 * LP tx ok and err, HP TX ok and err, NP TX ok and err,
5127 * RX ok and ERR, and GP timer */
5128 priv->irq_mask = 0x6fcf;
5130 priv->dma_poll_mask = 0;
5132 rtl8180_beacon_tx_disable(dev);
5134 if(priv->card_type == CARDBUS ){
5135 config3=read_nic_byte(dev, CONFIG3);
5136 write_nic_byte(dev,CONFIG3,config3 | CONFIG3_FuncRegEn);
5137 write_nic_word(dev,FEMR, FEMR_INTR | FEMR_WKUP | FEMR_GWAKE |
5138 read_nic_word(dev, FEMR));
5140 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5141 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
5142 write_nic_word(dev, MAC4, ((u32*)dev->dev_addr)[1] & 0xffff );
5143 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5145 rtl8180_update_msr(dev);
5147 if(!priv->card_8185){
5148 anaparam = eprom_read(dev,EPROM_ANAPARAM_ADDRLWORD);
5149 anaparam |= eprom_read(dev,EPROM_ANAPARAM_ADDRHWORD)<<16;
5151 rtl8180_set_anaparam(dev,anaparam);
5153 /* These might be unnecessary since we do in rx_enable / tx_enable */
5156 /*set_nic_rxring(dev);
5157 set_nic_txring(dev);*/
5159 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5162 The following is very strange. seems to be that 1 means test mode,
5163 but we need to acknolwledges the nic when a packet is ready
5164 altought we set it to 0
5168 CONFIG2, read_nic_byte(dev,CONFIG2) &~\
5169 (1<<CONFIG2_DMA_POLLING_MODE_SHIFT));
5170 //^the nic isn't in test mode
5173 CONFIG2, read_nic_byte(dev,CONFIG2)|(1<<4));
5175 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
5177 write_nic_dword(dev,INT_TIMEOUT,0);
5178 #ifdef DEBUG_REGISTERS
5179 rtl8180_dump_reg(dev);
5182 if(!priv->card_8185)
5185 experimental - this might be needed to calibrate AGC,
5186 anyway it shouldn't hurt
5188 write_nic_byte(dev, CONFIG5,
5189 read_nic_byte(dev, CONFIG5) | (1<<AGCRESET_SHIFT));
5190 read_nic_byte(dev, CONFIG5);
5192 write_nic_byte(dev, CONFIG5,
5193 read_nic_byte(dev, CONFIG5) &~ (1<<AGCRESET_SHIFT));
5196 write_nic_byte(dev, WPA_CONFIG, 0);
5197 //write_nic_byte(dev, TESTR, 0xd);
5200 rtl8180_no_hw_wep(dev);
5202 if(priv->card_8185){
5203 rtl8185_set_rate(dev);
5204 write_nic_byte(dev, RATE_FALLBACK, 0x81);
5205 // write_nic_byte(dev, 0xdf, 0x15);
5207 word = read_nic_word(dev, BRSR);
5209 word &= ~BRSR_BPLCP;
5210 word |= ieeerate2rtlrate(priv->ieee80211->basic_rate);
5214 write_nic_word(dev, BRSR, word);
5218 if(priv->card_8185){
5219 write_nic_byte(dev, GP_ENABLE,read_nic_byte(dev, GP_ENABLE) & ~(1<<6));
5221 //FIXME cfg 3 ClkRun enable - isn't it ReadOnly ?
5222 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
5223 write_nic_byte(dev,CONFIG3, read_nic_byte(dev, CONFIG3)
5224 |(1<<CONFIG3_CLKRUN_SHIFT));
5225 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5231 if(priv->rf_set_sens != NULL)
5232 priv->rf_set_sens(dev,priv->sens);
5233 rtl8180_irq_enable(dev);
5235 netif_start_queue(dev);
5236 /*DMESG ("lfree %d",get_curr_tx_free_desc(dev,LOW_PRIORITY));
5238 DMESG ("nfree %d",get_curr_tx_free_desc(dev,NORM_PRIORITY));
5240 DMESG ("hfree %d",get_curr_tx_free_desc(dev,HI_PRIORITY));
5241 if(check_nic_enought_desc(dev,NORM_PRIORITY)) DMESG("NORM OK");
5242 if(check_nic_enought_desc(dev,HI_PRIORITY)) DMESG("HI OK");
5243 if(check_nic_enought_desc(dev,LOW_PRIORITY)) DMESG("LOW OK");*/
5248 /* this configures registers for beacon tx and enables it via
5249 * rtl8180_beacon_tx_enable(). rtl8180_beacon_tx_disable() might
5250 * be used to stop beacon transmission
5252 void rtl8180_start_tx_beacon(struct net_device *dev)
5254 // struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
5256 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
5258 DMESG("Enabling beacon TX");
5259 //write_nic_byte(dev, 0x42,0xe6);// TCR
5260 // set_nic_txring(dev);
5261 // fix_tx_fifo(dev);
5262 rtl8180_prepare_beacon(dev);
5263 rtl8180_irq_disable(dev);
5264 rtl8180_beacon_tx_enable(dev);
5266 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
5267 //write_nic_byte(dev,0x9d,0x20); //DMA Poll
5268 //write_nic_word(dev,0x7a,0);
5269 //write_nic_word(dev,0x7a,0x8000);
5272 word = read_nic_word(dev, BcnItv);
5273 word &= ~BcnItv_BcnItv; // clear Bcn_Itv
5274 word |= priv->ieee80211->current_network.beacon_interval;//0x64;
5275 write_nic_word(dev, BcnItv, word);
5278 word = read_nic_word(dev, AtimWnd) &~ AtimWnd_AtimWnd;
5279 write_nic_word(dev, AtimWnd,word);// word |=
5280 //priv->ieee80211->current_network.atim_window);
5282 word = read_nic_word(dev, BintrItv);
5283 word &= ~BintrItv_BintrItv;
5284 word |= 1000;/*priv->ieee80211->current_network.beacon_interval *
5285 ((priv->txbeaconcount > 1)?(priv->txbeaconcount-1):1);
5286 // FIXME: check if correct ^^ worked with 0x3e8;
5288 write_nic_word(dev, BintrItv, word);
5291 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
5293 // rtl8180_beacon_tx_enable(dev);
5294 #ifdef CONFIG_RTL8185B
5295 rtl8185b_irq_enable(dev);
5297 rtl8180_irq_enable(dev);
5299 /* VV !!!!!!!!!! VV*/
5301 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
5302 write_nic_byte(dev,0x9d,0x00);
5303 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
5305 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
5311 /***************************************************************************
5312 -------------------------------NET STUFF---------------------------
5313 ***************************************************************************/
5314 static struct net_device_stats *rtl8180_stats(struct net_device *dev)
5316 struct r8180_priv *priv = ieee80211_priv(dev);
5318 return &priv->ieee80211->stats;
5321 // Change current and default preamble mode.
5322 // 2005.01.06, by rcnjko.
5325 MgntActSet_802_11_PowerSaveMode(
5326 struct r8180_priv *priv,
5331 // Currently, we do not change power save mode on IBSS mode.
5332 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
5338 // <RJ_NOTE> If we make HW to fill up the PwrMgt bit for us,
5339 // some AP will not response to our mgnt frames with PwrMgt bit set,
5340 // e.g. cannot associate the AP.
5341 // So I commented out it. 2005.02.16, by rcnjko.
5343 // // Change device's power save mode.
5344 // Adapter->HalFunc.SetPSModeHandler( Adapter, rtPsMode );
5346 // Update power save mode configured.
5347 // priv->dot11PowerSaveMode = rtPsMode;
5348 priv->ieee80211->ps = rtPsMode;
5349 // Determine ListenInterval.
5351 if(priv->dot11PowerSaveMode == eMaxPs)
5353 priv->ieee80211->ListenInterval = 10;
5357 priv->ieee80211->ListenInterval = 2;
5363 //================================================================================
5364 // Leisure Power Save in linked state.
5365 //================================================================================
5369 // Enter the leisure power save mode.
5373 struct r8180_priv *priv
5376 if (priv->bLeisurePs)
5378 if (priv->ieee80211->ps == IEEE80211_PS_DISABLED)
5380 //printk("----Enter PS\n");
5381 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST);//IEEE80211_PS_ENABLE
5389 // Leave the leisure power save mode.
5393 struct r8180_priv *priv
5396 if (priv->bLeisurePs)
5398 if (priv->ieee80211->ps != IEEE80211_PS_DISABLED)
5400 //printk("----Leave PS\n");
5401 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_DISABLED);
5405 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5406 void rtl8180_hw_wakeup_wq (struct work_struct *work)
5408 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
5409 // struct ieee80211_device * ieee = (struct ieee80211_device*)
5410 // container_of(work, struct ieee80211_device, watch_dog_wq);
5411 struct delayed_work *dwork = to_delayed_work(work);
5412 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq);
5413 struct net_device *dev = ieee->dev;
5415 void rtl8180_hw_wakeup_wq(struct net_device *dev)
5417 struct r8180_priv *priv = ieee80211_priv(dev);
5420 // printk("dev is %d\n",dev);
5421 // printk("&*&(^*(&(&=========>%s()\n", __func__);
5422 rtl8180_hw_wakeup(dev);
5426 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5427 void rtl8180_hw_sleep_wq (struct work_struct *work)
5429 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
5430 // struct ieee80211_device * ieee = (struct ieee80211_device*)
5431 // container_of(work, struct ieee80211_device, watch_dog_wq);
5432 struct delayed_work *dwork = to_delayed_work(work);
5433 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq);
5434 struct net_device *dev = ieee->dev;
5436 void rtl8180_hw_sleep_wq(struct net_device *dev)
5438 struct r8180_priv *priv = ieee80211_priv(dev);
5441 rtl8180_hw_sleep_down(dev);
5444 //YJ,add,080828,for KeepAlive
5445 static void MgntLinkKeepAlive(struct r8180_priv *priv )
5447 if (priv->keepAliveLevel == 0)
5450 if(priv->ieee80211->state == IEEE80211_LINKED)
5455 //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);
5457 if ( (priv->keepAliveLevel== 2) ||
5458 (priv->link_detect.LastNumTxUnicast == priv->NumTxUnicast &&
5459 priv->link_detect.LastNumRxUnicast == priv->ieee80211->NumRxUnicast )
5462 priv->link_detect.IdleCount++;
5465 // Send a Keep-Alive packet packet to AP if we had been idle for a while.
5467 if(priv->link_detect.IdleCount >= ((KEEP_ALIVE_INTERVAL / CHECK_FOR_HANG_PERIOD)-1) )
5469 priv->link_detect.IdleCount = 0;
5470 ieee80211_sta_ps_send_null_frame(priv->ieee80211, false);
5475 priv->link_detect.IdleCount = 0;
5477 priv->link_detect.LastNumTxUnicast = priv->NumTxUnicast;
5478 priv->link_detect.LastNumRxUnicast = priv->ieee80211->NumRxUnicast;
5481 //YJ,add,080828,for KeepAlive,end
5483 static u8 read_acadapter_file(char *filename);
5484 void rtl8180_watch_dog(struct net_device *dev)
5486 struct r8180_priv *priv = ieee80211_priv(dev);
5487 bool bEnterPS = false;
5488 bool bBusyTraffic = false;
5493 if(priv->ieee80211->actscanning == false){
5494 if((priv->ieee80211->iw_mode != IW_MODE_ADHOC) && (priv->ieee80211->state == IEEE80211_NOLINK) && (priv->ieee80211->beinretry == false) && (priv->eRFPowerState == eRfOn)){
5499 //YJ,add,080828,for link state check
5500 if((priv->ieee80211->state == IEEE80211_LINKED) && (priv->ieee80211->iw_mode == IW_MODE_INFRA)){
5501 SlotIndex = (priv->link_detect.SlotIndex++) % priv->link_detect.SlotNum;
5502 priv->link_detect.RxFrameNum[SlotIndex] = priv->ieee80211->NumRxDataInPeriod + priv->ieee80211->NumRxBcnInPeriod;
5503 for( i=0; i<priv->link_detect.SlotNum; i++ )
5504 TotalRxNum+= priv->link_detect.RxFrameNum[i];
5505 //printk("&&&&&=== TotalRxNum = %d\n", TotalRxNum);
5506 if(TotalRxNum == 0){
5507 priv->ieee80211->state = IEEE80211_ASSOCIATING;
5508 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
5512 //YJ,add,080828,for KeepAlive
5513 MgntLinkKeepAlive(priv);
5515 //YJ,add,080828,for LPS
5517 if(priv->PowerProfile == POWER_PROFILE_BATTERY )
5519 //Turn on LeisurePS on battery power
5520 //printk("!!!!!On battery power\n");
5521 priv->bLeisurePs = true;
5523 else if(priv->PowerProfile == POWER_PROFILE_AC )
5525 // Turn off LeisurePS on AC power
5526 //printk("----On AC power\n");
5527 LeisurePSLeave(priv);
5528 priv->bLeisurePs= false;
5534 if(priv->ieee80211->state == IEEE80211_LINKED){
5535 if( priv->NumRxOkInPeriod> 666 ||
5536 priv->NumTxOkInPeriod > 666 ) {
5537 bBusyTraffic = true;
5539 if((priv->ieee80211->NumRxData + priv->NumTxOkInPeriod)<8) {
5543 LeisurePSEnter(priv);
5546 LeisurePSLeave(priv);
5550 LeisurePSLeave(priv);
5553 priv->NumRxOkInPeriod = 0;
5554 priv->NumTxOkInPeriod = 0;
5555 priv->ieee80211->NumRxData = 0;
5558 if(priv->ieee80211->state == IEEE80211_LINKED){
5559 priv->link_detect.NumRxOkInPeriod = priv->ieee80211->NumRxDataInPeriod;
5560 //printk("TxOk=%d RxOk=%d\n", priv->link_detect.NumTxOkInPeriod, priv->link_detect.NumRxOkInPeriod);
5561 if( priv->link_detect.NumRxOkInPeriod> 666 ||
5562 priv->link_detect.NumTxOkInPeriod> 666 ) {
5563 bBusyTraffic = true;
5565 if(((priv->link_detect.NumRxOkInPeriod + priv->link_detect.NumTxOkInPeriod) > 8)
5566 || (priv->link_detect.NumRxOkInPeriod > 2)) {
5574 LeisurePSEnter(priv);
5577 LeisurePSLeave(priv);
5581 LeisurePSLeave(priv);
5584 priv->link_detect.bBusyTraffic = bBusyTraffic;
5585 priv->link_detect.NumRxOkInPeriod = 0;
5586 priv->link_detect.NumTxOkInPeriod = 0;
5587 priv->ieee80211->NumRxDataInPeriod = 0;
5588 priv->ieee80211->NumRxBcnInPeriod = 0;
5591 int _rtl8180_up(struct net_device *dev)
5593 struct r8180_priv *priv = ieee80211_priv(dev);
5598 DMESG("Bringing up iface");
5599 #ifdef CONFIG_RTL8185B
5600 rtl8185b_adapter_start(dev);
5601 rtl8185b_rx_enable(dev);
5602 rtl8185b_tx_enable(dev);
5604 rtl8180_adapter_start(dev);
5605 rtl8180_rx_enable(dev);
5606 rtl8180_tx_enable(dev);
5609 if(priv->bInactivePs){
5610 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
5616 timer_rate_adaptive((unsigned long)dev);
5619 watch_dog_adaptive((unsigned long)dev);
5621 if(priv->bSwAntennaDiverity)
5622 SwAntennaDiversityTimerCallback(dev);
5625 ieee80211_softmac_start_protocol(priv->ieee80211);
5627 //Add for RF power on power off by lizhaoming 080512
5628 // priv->eRFPowerState = eRfOn;
5629 // printk("\n--------Start queue_work:GPIOChangeRFWorkItem");
5630 // queue_delayed_work(priv->ieee80211->wq,&priv->ieee80211->GPIOChangeRFWorkItem,1000);
5636 int rtl8180_open(struct net_device *dev)
5638 struct r8180_priv *priv = ieee80211_priv(dev);
5641 down(&priv->wx_sem);
5642 ret = rtl8180_up(dev);
5649 int rtl8180_up(struct net_device *dev)
5651 struct r8180_priv *priv = ieee80211_priv(dev);
5653 if (priv->up == 1) return -1;
5655 return _rtl8180_up(dev);
5659 int rtl8180_close(struct net_device *dev)
5661 struct r8180_priv *priv = ieee80211_priv(dev);
5664 down(&priv->wx_sem);
5665 ret = rtl8180_down(dev);
5672 int rtl8180_down(struct net_device *dev)
5674 struct r8180_priv *priv = ieee80211_priv(dev);
5676 if (priv->up == 0) return -1;
5680 ieee80211_softmac_stop_protocol(priv->ieee80211);
5682 if (!netif_queue_stopped(dev))
5683 netif_stop_queue(dev);
5684 rtl8180_rtx_disable(dev);
5685 rtl8180_irq_disable(dev);
5686 del_timer_sync(&priv->watch_dog_timer);
5687 //cancel_delayed_work(&priv->ieee80211->watch_dog_wq);
5689 del_timer_sync(&priv->rateadapter_timer);
5690 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
5692 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
5693 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
5694 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
5695 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
5696 del_timer_sync(&priv->SwAntennaDiversityTimer);
5697 SetZebraRFPowerState8185(dev,eRfOff);
5698 //ieee80211_softmac_stop_protocol(priv->ieee80211);
5699 memset(&(priv->ieee80211->current_network),0,sizeof(struct ieee80211_network));
5700 priv->ieee80211->state = IEEE80211_NOLINK;
5704 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
5705 void rtl8180_restart_wq(struct work_struct *work)
5707 struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
5708 struct net_device *dev = priv->dev;
5710 void rtl8180_restart_wq(struct net_device *dev)
5712 struct r8180_priv *priv = ieee80211_priv(dev);
5714 down(&priv->wx_sem);
5716 rtl8180_commit(dev);
5721 void rtl8180_restart(struct net_device *dev)
5723 struct r8180_priv *priv = ieee80211_priv(dev);
5724 //rtl8180_commit(dev);
5725 schedule_work(&priv->reset_wq);
5726 //DMESG("TXTIMEOUT");
5730 void rtl8180_commit(struct net_device *dev)
5732 struct r8180_priv *priv = ieee80211_priv(dev);
5734 if (priv->up == 0) return ;
5736 del_timer_sync(&priv->watch_dog_timer);
5737 //cancel_delayed_work(&priv->ieee80211->watch_dog_wq);
5739 //by amy for rate adaptive
5740 del_timer_sync(&priv->rateadapter_timer);
5741 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
5742 //by amy for rate adaptive
5744 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
5745 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
5746 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
5747 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
5748 del_timer_sync(&priv->SwAntennaDiversityTimer);
5749 ieee80211_softmac_stop_protocol(priv->ieee80211);
5750 rtl8180_irq_disable(dev);
5751 rtl8180_rtx_disable(dev);
5756 static void r8180_set_multicast(struct net_device *dev)
5758 struct r8180_priv *priv = ieee80211_priv(dev);
5761 //down(&priv->wx_sem);
5763 promisc = (dev->flags & IFF_PROMISC) ? 1:0;
5765 if (promisc != priv->promisc)
5766 rtl8180_restart(dev);
5768 priv->promisc = promisc;
5770 //up(&priv->wx_sem);
5774 /* this is called by the kernel when it needs to TX a 802.3 encapsulated frame*/
5775 int rtl8180_8023_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
5777 struct r8180_priv *priv = ieee80211_priv(dev);
5779 unsigned long flags;
5781 spin_lock_irqsave(&priv->tx_lock,flags);
5782 ret = ieee80211_r8180_8023_hardstartxmit(skb,priv->ieee80211);
5783 spin_unlock_irqrestore(&priv->tx_lock,flags);
5788 int r8180_set_mac_adr(struct net_device *dev, void *mac)
5790 struct r8180_priv *priv = ieee80211_priv(dev);
5791 struct sockaddr *addr = mac;
5793 down(&priv->wx_sem);
5795 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
5797 if(priv->ieee80211->iw_mode == IW_MODE_MASTER)
5798 memcpy(priv->ieee80211->current_network.bssid, dev->dev_addr, ETH_ALEN);
5810 /* based on ipw2200 driver */
5811 int rtl8180_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5813 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
5815 struct iwreq *wrq = (struct iwreq *) rq;
5818 case RTL_IOCTL_WPA_SUPPLICANT:
5819 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
5831 /****************************************************************************
5832 -----------------------------PCI STUFF---------------------------
5833 *****************************************************************************/
5836 static int __devinit rtl8180_pci_probe(struct pci_dev *pdev,
5837 const struct pci_device_id *id)
5839 unsigned long ioaddr = 0;
5840 struct net_device *dev = NULL;
5841 struct r8180_priv *priv= NULL;
5845 #ifdef CONFIG_RTL8180_IO_MAP
5846 unsigned long pio_start, pio_len, pio_flags;
5848 unsigned long pmem_start, pmem_len, pmem_flags;
5849 #endif //end #ifdef RTL_IO_MAP
5851 DMESG("Configuring chip resources");
5853 if( pci_enable_device (pdev) ){
5854 DMESG("Failed to enable PCI device");
5858 pci_set_master(pdev);
5859 //pci_set_wmi(pdev);
5860 pci_set_dma_mask(pdev, 0xffffff00ULL);
5861 pci_set_consistent_dma_mask(pdev,0xffffff00ULL);
5862 dev = alloc_ieee80211(sizeof(struct r8180_priv));
5865 priv = ieee80211_priv(dev);
5866 priv->ieee80211 = netdev_priv(dev);
5868 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
5869 SET_MODULE_OWNER(dev);
5871 pci_set_drvdata(pdev, dev);
5872 SET_NETDEV_DEV(dev, &pdev->dev);
5874 priv = ieee80211_priv(dev);
5875 // memset(priv,0,sizeof(struct r8180_priv));
5879 #ifdef CONFIG_RTL8180_IO_MAP
5881 pio_start = (unsigned long)pci_resource_start (pdev, 0);
5882 pio_len = (unsigned long)pci_resource_len (pdev, 0);
5883 pio_flags = (unsigned long)pci_resource_flags (pdev, 0);
5885 if (!(pio_flags & IORESOURCE_IO)) {
5886 DMESG("region #0 not a PIO resource, aborting");
5890 //DMESG("IO space @ 0x%08lx", pio_start );
5891 if( ! request_region( pio_start, pio_len, RTL8180_MODULE_NAME ) ){
5892 DMESG("request_region failed!");
5897 dev->base_addr = ioaddr; // device I/O address
5901 pmem_start = pci_resource_start(pdev, 1);
5902 pmem_len = pci_resource_len(pdev, 1);
5903 pmem_flags = pci_resource_flags (pdev, 1);
5905 if (!(pmem_flags & IORESOURCE_MEM)) {
5906 DMESG("region #1 not a MMIO resource, aborting");
5910 //DMESG("Memory mapped space @ 0x%08lx ", pmem_start);
5911 if( ! request_mem_region(pmem_start, pmem_len, RTL8180_MODULE_NAME)) {
5912 DMESG("request_mem_region failed!");
5917 ioaddr = (unsigned long)ioremap_nocache( pmem_start, pmem_len);
5918 if( ioaddr == (unsigned long)NULL ){
5919 DMESG("ioremap failed!");
5920 // release_mem_region( pmem_start, pmem_len );
5924 dev->mem_start = ioaddr; // shared mem start
5925 dev->mem_end = ioaddr + pci_resource_len(pdev, 0); // shared mem end
5927 #endif //end #ifdef RTL_IO_MAP
5929 #ifdef CONFIG_RTL8185B
5930 //pci_read_config_byte(pdev, 0x05, ptr);
5931 //pci_write_config_byte(pdev, 0x05, (*ptr) & (~0x04));
5932 pci_read_config_byte(pdev, 0x05, &unit);
5933 pci_write_config_byte(pdev, 0x05, unit & (~0x04));
5936 dev->irq = pdev->irq;
5939 dev->open = rtl8180_open;
5940 dev->stop = rtl8180_close;
5941 //dev->hard_start_xmit = ieee80211_xmit;
5942 dev->tx_timeout = rtl8180_restart;
5943 dev->wireless_handlers = &r8180_wx_handlers_def;
5944 dev->do_ioctl = rtl8180_ioctl;
5945 dev->set_multicast_list = r8180_set_multicast;
5946 dev->set_mac_address = r8180_set_mac_adr;
5948 #if WIRELESS_EXT >= 12
5949 #if WIRELESS_EXT < 17
5950 dev->get_wireless_stats = r8180_get_wireless_stats;
5952 dev->wireless_handlers = (struct iw_handler_def *) &r8180_wx_handlers_def;
5955 dev->type=ARPHRD_ETHER;
5956 dev->watchdog_timeo = HZ*3; //added by david woo, 2007.12.13
5958 if (dev_alloc_name(dev, ifname) < 0){
5959 DMESG("Oops: devname already taken! Trying wlan%%d...\n");
5961 // ifname = "ath%d";
5962 dev_alloc_name(dev, ifname);
5966 if(rtl8180_init(dev)!=0){
5967 DMESG("Initialization failed");
5971 netif_carrier_off(dev);
5973 register_netdev(dev);
5975 rtl8180_proc_init_one(dev);
5977 DMESG("Driver probe completed\n");
5982 #ifdef CONFIG_RTL8180_IO_MAP
5984 if( dev->base_addr != 0 ){
5986 release_region(dev->base_addr,
5987 pci_resource_len(pdev, 0) );
5990 if( dev->mem_start != (unsigned long)NULL ){
5991 iounmap( (void *)dev->mem_start );
5992 release_mem_region( pci_resource_start(pdev, 1),
5993 pci_resource_len(pdev, 1) );
5995 #endif //end #ifdef RTL_IO_MAP
6002 free_irq(dev->irq, dev);
6005 free_ieee80211(dev);
6008 pci_disable_device(pdev);
6010 DMESG("wlan driver load failed\n");
6011 pci_set_drvdata(pdev, NULL);
6017 static void __devexit rtl8180_pci_remove(struct pci_dev *pdev)
6019 struct r8180_priv *priv;
6020 struct net_device *dev = pci_get_drvdata(pdev);
6023 unregister_netdev(dev);
6025 priv=ieee80211_priv(dev);
6027 rtl8180_proc_remove_one(dev);
6029 priv->rf_close(dev);
6031 //rtl8180_rtx_disable(dev);
6032 //rtl8180_irq_disable(dev);
6034 //write_nic_word(dev,INTA,read_nic_word(dev,INTA));
6035 //force_pci_posting(dev);
6040 DMESG("Freeing irq %d",dev->irq);
6041 free_irq(dev->irq, dev);
6046 free_rx_desc_ring(dev);
6047 free_tx_desc_rings(dev);
6048 // free_beacon_desc_ring(dev,priv->txbeaconcount);
6050 #ifdef CONFIG_RTL8180_IO_MAP
6052 if( dev->base_addr != 0 ){
6054 release_region(dev->base_addr,
6055 pci_resource_len(pdev, 0) );
6058 if( dev->mem_start != (unsigned long)NULL ){
6059 iounmap( (void *)dev->mem_start );
6060 release_mem_region( pci_resource_start(pdev, 1),
6061 pci_resource_len(pdev, 1) );
6063 #endif /*end #ifdef RTL_IO_MAP*/
6065 free_ieee80211(dev);
6067 pci_disable_device(pdev);
6069 DMESG("wlan driver removed\n");
6073 /* fun with the built-in ieee80211 stack... */
6074 extern int ieee80211_crypto_init(void);
6075 extern void ieee80211_crypto_deinit(void);
6076 extern int ieee80211_crypto_tkip_init(void);
6077 extern void ieee80211_crypto_tkip_exit(void);
6078 extern int ieee80211_crypto_ccmp_init(void);
6079 extern void ieee80211_crypto_ccmp_exit(void);
6080 extern int ieee80211_crypto_wep_init(void);
6081 extern void ieee80211_crypto_wep_exit(void);
6083 static int __init rtl8180_pci_module_init(void)
6087 ret = ieee80211_crypto_init();
6089 printk(KERN_ERR "ieee80211_crypto_init() failed %d\n", ret);
6092 ret = ieee80211_crypto_tkip_init();
6094 printk(KERN_ERR "ieee80211_crypto_tkip_init() failed %d\n", ret);
6097 ret = ieee80211_crypto_ccmp_init();
6099 printk(KERN_ERR "ieee80211_crypto_ccmp_init() failed %d\n", ret);
6102 ret = ieee80211_crypto_wep_init();
6104 printk(KERN_ERR "ieee80211_crypto_wep_init() failed %d\n", ret);
6108 printk(KERN_INFO "\nLinux kernel driver for RTL8180 \
6109 / RTL8185 based WLAN cards\n");
6110 printk(KERN_INFO "Copyright (c) 2004-2005, Andrea Merello\n");
6111 DMESG("Initializing module");
6112 DMESG("Wireless extensions version %d", WIRELESS_EXT);
6113 rtl8180_proc_module_init();
6115 #if(LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22))
6116 if(0!=pci_module_init(&rtl8180_pci_driver))
6118 if(0!=pci_register_driver(&rtl8180_pci_driver))
6120 //if(0!=pci_module_init(&rtl8180_pci_driver))
6122 DMESG("No device found");
6123 /*pci_unregister_driver (&rtl8180_pci_driver);*/
6130 static void __exit rtl8180_pci_module_exit(void)
6132 pci_unregister_driver (&rtl8180_pci_driver);
6133 rtl8180_proc_module_remove();
6134 ieee80211_crypto_tkip_exit();
6135 ieee80211_crypto_ccmp_exit();
6136 ieee80211_crypto_wep_exit();
6137 ieee80211_crypto_deinit();
6142 void rtl8180_try_wake_queue(struct net_device *dev, int pri)
6144 unsigned long flags;
6146 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
6148 spin_lock_irqsave(&priv->tx_lock,flags);
6149 enough_desc = check_nic_enought_desc(dev,pri);
6150 spin_unlock_irqrestore(&priv->tx_lock,flags);
6153 ieee80211_wake_queue(priv->ieee80211);
6156 /*****************************************************************************
6157 -----------------------------IRQ STUFF---------------------------
6158 ******************************************************************************/
6160 void rtl8180_tx_isr(struct net_device *dev, int pri,short error)
6162 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
6164 u32 *tail; //tail virtual addr
6165 u32 *head; //head virtual addr
6166 u32 *begin;//start of ring virtual addr
6167 u32 *nicv; //nic pointer virtual addr
6168 // u32 *txdv; //packet just TXed
6169 u32 nic; //nic pointer physical addr
6170 u32 nicbegin;// start of ring physical addr
6173 /* physical addr are ok on 32 bits since we set DMA mask*/
6178 if (error) priv->stats.txretry++; //tony 20060601
6179 spin_lock_irqsave(&priv->tx_lock,flag);
6181 case MANAGE_PRIORITY:
6182 tail = priv->txmapringtail;
6183 begin = priv->txmapring;
6184 head = priv->txmapringhead;
6185 nic = read_nic_dword(dev,TX_MANAGEPRIORITY_RING_ADDR);
6186 nicbegin = priv->txmapringdma;
6190 tail = priv->txbkpringtail;
6191 begin = priv->txbkpring;
6192 head = priv->txbkpringhead;
6193 nic = read_nic_dword(dev,TX_BKPRIORITY_RING_ADDR);
6194 nicbegin = priv->txbkpringdma;
6198 tail = priv->txbepringtail;
6199 begin = priv->txbepring;
6200 head = priv->txbepringhead;
6201 nic = read_nic_dword(dev,TX_BEPRIORITY_RING_ADDR);
6202 nicbegin = priv->txbepringdma;
6206 tail = priv->txvipringtail;
6207 begin = priv->txvipring;
6208 head = priv->txvipringhead;
6209 nic = read_nic_dword(dev,TX_VIPRIORITY_RING_ADDR);
6210 nicbegin = priv->txvipringdma;
6214 tail = priv->txvopringtail;
6215 begin = priv->txvopring;
6216 head = priv->txvopringhead;
6217 nic = read_nic_dword(dev,TX_VOPRIORITY_RING_ADDR);
6218 nicbegin = priv->txvopringdma;
6222 tail = priv->txhpringtail;
6223 begin = priv->txhpring;
6224 head = priv->txhpringhead;
6225 nic = read_nic_dword(dev,TX_HIGHPRIORITY_RING_ADDR);
6226 nicbegin = priv->txhpringdma;
6230 spin_unlock_irqrestore(&priv->tx_lock,flag);
6233 /* DMESG("%x %s %x %x",((int)nic & 0xfff)/8/4,
6234 *(priv->txnpring + ((int)nic&0xfff)/4/8) & (1<<31) ? "filled" : "empty",
6235 (priv->txnpringtail - priv->txnpring)/8,(priv->txnpringhead -
6238 //nicv = (u32*) ((nic - nicbegin) + (int)begin);
6239 nicv = (u32*) ((nic - nicbegin) + (u8*)begin);
6240 if((head <= tail && (nicv > tail || nicv < head)) ||
6241 (head > tail && (nicv > tail && nicv < head))){
6243 DMESGW("nic has lost pointer");
6244 #ifdef DEBUG_TX_DESC
6245 //check_tx_ring(dev,NORM_PRIORITY);
6246 check_tx_ring(dev,pri);
6248 spin_unlock_irqrestore(&priv->tx_lock,flag);
6249 rtl8180_restart(dev);
6253 /* we check all the descriptors between the head and the nic,
6254 * but not the currenly pointed by the nic (the next to be txed)
6255 * and the previous of the pointed (might be in process ??)
6257 //if (head == nic) return;
6258 //DMESG("%x %x",head,nic);
6259 offs = (nic - nicbegin);
6260 //DMESG("%x %x %x",nic ,(u32)nicbegin, (int)nic -nicbegin);
6264 hd = (head - begin) /8;
6269 j = offs + (priv->txringcount -1 -hd);
6270 // j= priv->txringcount -1- (hd - offs);
6278 // printk("+++++++++++++check status desc\n");
6279 if((*head) & (1<<31))
6281 if(((*head)&(0x10000000)) != 0){
6282 // printk("++++++++++++++last desc,retry count is %d\n",((*head) & (0x000000ff)));
6283 priv->CurrRetryCnt += (u16)((*head) & (0x000000ff));
6287 priv->NumTxOkTotal++;
6288 // printk("NumTxOkTotal is %d\n",priv->NumTxOkTotal++);
6291 // printk("in function %s:curr_retry_count is %d\n",__func__,((*head) & (0x000000ff)));
6294 priv->NumTxOkBytesTotal += (*(head+3)) & (0x00000fff);
6296 // printk("in function %s:curr_txokbyte_count is %d\n",__func__,(*(head+3)) & (0x00000fff));
6297 *head = *head &~ (1<<31);
6299 if((head - begin)/8 == priv->txringcount-1)
6307 txdv = begin + (priv->txringcount -1)*8;
6311 txed = !(txdv[0] &(1<<31));
6314 if(!(txdv[0] & (1<<15))) error = 1;
6315 //if(!(txdv[0] & (1<<30))) error = 1;
6316 if(error)DMESG("%x",txdv[0]);
6319 //DMESG("%x",txdv[0]);
6320 /* the head has been moved to the last certainly TXed
6321 * (or at least processed by the nic) packet.
6322 * The driver take forcefully owning of all these packets
6323 * If the packet previous of the nic pointer has been
6324 * processed this doesn't matter: it will be checked
6325 * here at the next round. Anyway if no more packet are
6326 * TXed no memory leak occour at all.
6330 case MANAGE_PRIORITY:
6331 priv->txmapringhead = head;
6332 //printk("1==========================================> priority check!\n");
6333 if(priv->ack_tx_to_ieee){
6334 // try to implement power-save mode 2008.1.22
6335 // printk("2==========================================> priority check!\n");
6337 if(rtl8180_is_tx_queue_empty(dev)){
6338 // printk("tx queue empty, after send null sleep packet, try to sleep !\n");
6339 priv->ack_tx_to_ieee = 0;
6340 ieee80211_ps_tx_ack(priv->ieee80211,!error);
6347 priv->txbkpringhead = head;
6351 priv->txbepringhead = head;
6355 priv->txvipringhead = head;
6359 priv->txvopringhead = head;
6363 priv->txhpringhead = head;
6367 /*DMESG("%x %x %x", (priv->txnpringhead - priv->txnpring) /8 ,
6368 (priv->txnpringtail - priv->txnpring) /8,
6372 spin_unlock_irqrestore(&priv->tx_lock,flag);
6376 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
6377 void rtl8180_tx_irq_wq(struct work_struct *work)
6379 //struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
6380 struct delayed_work *dwork = to_delayed_work(work);
6381 struct ieee80211_device * ieee = (struct ieee80211_device*)
6382 container_of(dwork, struct ieee80211_device, watch_dog_wq);
6383 struct net_device *dev = ieee->dev;
6385 void rtl8180_tx_irq_wq(struct net_device *dev)
6387 //struct r8180_priv *priv = ieee80211_priv(dev);
6389 rtl8180_tx_isr(dev,MANAGE_PRIORITY,0);
6391 irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs)
6393 struct net_device *dev = (struct net_device *) netdev;
6394 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
6395 unsigned long flags;
6398 /* We should return IRQ_NONE, but for now let me keep this */
6399 if(priv->irq_enabled == 0) return IRQ_HANDLED;
6401 spin_lock_irqsave(&priv->irq_th_lock,flags);
6403 #ifdef CONFIG_RTL8185B
6405 inta = read_nic_dword(dev, ISR);// & priv->IntrMask;
6406 write_nic_dword(dev,ISR,inta); // reset int situation
6408 inta = read_nic_word(dev,INTA) & priv->irq_mask;
6409 write_nic_word(dev,INTA,inta); // reset int situation
6412 priv->stats.shints++;
6414 //DMESG("Enter interrupt, ISR value = 0x%08x", inta);
6417 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6420 most probably we can safely return IRQ_NONE,
6421 but for now is better to avoid problems
6427 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6433 DMESG("NIC irq %x",inta);
6435 //priv->irqpending = inta;
6438 if(!netif_running(dev)) {
6439 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6443 if(inta & ISR_TimeOut){
6444 write_nic_dword(dev, TimerInt, 0);
6445 //DMESG("=================>waking up");
6446 // rtl8180_hw_wakeup(dev);
6449 if(inta & ISR_TBDOK){
6450 priv->stats.txbeacon++;
6453 if(inta & ISR_TBDER){
6454 priv->stats.txbeaconerr++;
6457 if(inta & IMR_TMGDOK ) {
6458 // priv->NumTxOkTotal++;
6459 rtl8180_tx_isr(dev,MANAGE_PRIORITY,0);
6460 // schedule_work(&priv->tx_irq_wq);
6464 if(inta & ISR_THPDER){
6466 DMESG ("TX high priority ERR");
6468 priv->stats.txhperr++;
6469 rtl8180_tx_isr(dev,HI_PRIORITY,1);
6470 priv->ieee80211->stats.tx_errors++;
6473 if(inta & ISR_THPDOK){ //High priority tx ok
6475 DMESG ("TX high priority OK");
6477 // priv->NumTxOkTotal++;
6478 //priv->NumTxOkInPeriod++; //YJ,del,080828
6479 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6480 priv->stats.txhpokint++;
6481 rtl8180_tx_isr(dev,HI_PRIORITY,0);
6484 if(inta & ISR_RER) {
6485 priv->stats.rxerr++;
6487 DMESGW("RX error int");
6490 #ifdef CONFIG_RTL8185B
6491 if(inta & ISR_TBKDER){ //corresponding to BK_PRIORITY
6492 priv->stats.txbkperr++;
6493 priv->ieee80211->stats.tx_errors++;
6495 DMESGW("TX bkp error int");
6497 //tasklet_schedule(&priv->irq_tx_tasklet);
6498 rtl8180_tx_isr(dev,BK_PRIORITY,1);
6499 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6502 if(inta & ISR_TBEDER){ //corresponding to BE_PRIORITY
6503 priv->stats.txbeperr++;
6504 priv->ieee80211->stats.tx_errors++;
6506 DMESGW("TX bep error int");
6508 rtl8180_tx_isr(dev,BE_PRIORITY,1);
6509 //tasklet_schedule(&priv->irq_tx_tasklet);
6510 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6513 if(inta & ISR_TNPDER){ //corresponding to VO_PRIORITY
6514 priv->stats.txnperr++;
6515 priv->ieee80211->stats.tx_errors++;
6517 DMESGW("TX np error int");
6519 //tasklet_schedule(&priv->irq_tx_tasklet);
6520 rtl8180_tx_isr(dev,NORM_PRIORITY,1);
6521 #ifdef CONFIG_RTL8185B
6522 rtl8180_try_wake_queue(dev, NORM_PRIORITY);
6526 if(inta & ISR_TLPDER){ //corresponding to VI_PRIORITY
6527 priv->stats.txlperr++;
6528 priv->ieee80211->stats.tx_errors++;
6530 DMESGW("TX lp error int");
6532 rtl8180_tx_isr(dev,LOW_PRIORITY,1);
6533 //tasklet_schedule(&priv->irq_tx_tasklet);
6534 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
6539 DMESG("Frame arrived !");
6541 //priv->NumRxOkInPeriod++; //YJ,del,080828
6542 priv->stats.rxint++;
6543 tasklet_schedule(&priv->irq_rx_tasklet);
6546 if(inta & ISR_RQoSOK ){
6548 DMESG("QoS Frame arrived !");
6550 //priv->NumRxOkInPeriod++; //YJ,del,080828
6551 priv->stats.rxint++;
6552 tasklet_schedule(&priv->irq_rx_tasklet);
6554 if(inta & ISR_BcnInt) {
6555 //DMESG("Preparing Beacons");
6556 rtl8180_prepare_beacon(dev);
6561 DMESGW("No RX descriptor available");
6562 priv->stats.rxrdu++;
6564 tasklet_schedule(&priv->irq_rx_tasklet);
6565 /*queue_work(priv->workqueue ,&priv->restart_work);*/
6568 if(inta & ISR_RXFOVW){
6570 DMESGW("RX fifo overflow");
6572 priv->stats.rxoverflow++;
6573 tasklet_schedule(&priv->irq_rx_tasklet);
6574 //queue_work(priv->workqueue ,&priv->restart_work);
6577 if(inta & ISR_TXFOVW) priv->stats.txoverflow++;
6579 if(inta & ISR_TNPDOK){ //Normal priority tx ok
6581 DMESG ("TX normal priority OK");
6583 // priv->NumTxOkTotal++;
6584 //priv->NumTxOkInPeriod++; //YJ,del,080828
6585 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6586 // priv->ieee80211->stats.tx_packets++;
6587 priv->stats.txnpokint++;
6588 rtl8180_tx_isr(dev,NORM_PRIORITY,0);
6591 if(inta & ISR_TLPDOK){ //Low priority tx ok
6593 DMESG ("TX low priority OK");
6595 // priv->NumTxOkTotal++;
6596 //priv->NumTxOkInPeriod++; //YJ,del,080828
6597 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6598 // priv->ieee80211->stats.tx_packets++;
6599 priv->stats.txlpokint++;
6600 rtl8180_tx_isr(dev,LOW_PRIORITY,0);
6601 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
6604 #ifdef CONFIG_RTL8185B
6605 if(inta & ISR_TBKDOK){ //corresponding to BK_PRIORITY
6606 priv->stats.txbkpokint++;
6608 DMESGW("TX bk priority ok");
6610 // priv->NumTxOkTotal++;
6611 //priv->NumTxOkInPeriod++; //YJ,del,080828
6612 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6613 rtl8180_tx_isr(dev,BK_PRIORITY,0);
6614 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6617 if(inta & ISR_TBEDOK){ //corresponding to BE_PRIORITY
6618 priv->stats.txbeperr++;
6620 DMESGW("TX be priority ok");
6622 // priv->NumTxOkTotal++;
6623 //priv->NumTxOkInPeriod++; //YJ,del,080828
6624 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6625 rtl8180_tx_isr(dev,BE_PRIORITY,0);
6626 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6629 force_pci_posting(dev);
6630 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6636 void rtl8180_irq_rx_tasklet(struct r8180_priv* priv)
6638 // unsigned long flags;
6640 /* spin_lock_irqsave(&priv->irq_lock, flags);
6641 priv->irq_mask &=~IMR_ROK;
6642 priv->irq_mask &=~IMR_RDU;
6644 rtl8180_irq_enable(priv->dev);
6645 spin_unlock_irqrestore(&priv->irq_lock, flags);
6647 rtl8180_rx(priv->dev);
6649 /* spin_lock_irqsave(&priv->irq_lock, flags);
6650 priv->irq_mask |= IMR_ROK;
6651 priv->irq_mask |= IMR_RDU;
6652 rtl8180_irq_enable(priv->dev);
6653 spin_unlock_irqrestore(&priv->irq_lock, flags);
6657 /****************************************************************************
6658 lizhaoming--------------------------- RF power on/power off -----------------
6659 *****************************************************************************/
6661 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20))
6662 void GPIOChangeRFWorkItemCallBack(struct work_struct *work)
6664 //struct delayed_work *dwork = to_delayed_work(work);
6665 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, GPIOChangeRFWorkItem.work);
6666 struct net_device *dev = ieee->dev;
6667 struct r8180_priv *priv = ieee80211_priv(dev);
6669 void GPIOChangeRFWorkItemCallBack(struct ieee80211_device *ieee)
6671 struct net_device *dev = ieee->dev;
6672 struct r8180_priv *priv = ieee80211_priv(dev);
6678 RT_RF_POWER_STATE eRfPowerStateToSet;
6679 bool bActuallySet=false;
6682 static char *RadioPowerPath = "/etc/acpi/events/RadioPower.sh";
6683 static char *envp[] = {"HOME=/", "TERM=linux", "PATH=/usr/bin:/bin", NULL};
6684 static int readf_count = 0;
6685 //printk("============>%s in \n", __func__);
6688 if(readf_count % 10 == 0)
6689 priv->PowerProfile = read_acadapter_file("/proc/acpi/ac_adapter/AC0/state");
6691 readf_count = (readf_count+1)%0xffff;
6694 if(priv->up == 0)//driver stopped
6696 printk("\nDo nothing...");
6702 // We should turn off LED before polling FF51[4].
6705 btPSR = read_nic_byte(dev, PSR);
6706 write_nic_byte(dev, PSR, (btPSR & ~BIT3));
6708 //It need to delay 4us suggested by Jong, 2008-01-16
6711 //HW radio On/Off according to the value of FF51[4](config0)
6712 btConfig0 = btPSR = read_nic_byte(dev, CONFIG0);
6715 write_nic_byte(dev, PSR, btPSR| BIT3);
6717 eRfPowerStateToSet = (btConfig0 & BIT4) ? eRfOn : eRfOff;
6719 if((priv->ieee80211->bHwRadioOff == true) && (eRfPowerStateToSet == eRfOn))
6721 priv->ieee80211->bHwRadioOff = false;
6722 bActuallySet = true;
6724 else if((priv->ieee80211->bHwRadioOff == false) && (eRfPowerStateToSet == eRfOff))
6726 priv->ieee80211->bHwRadioOff = true;
6727 bActuallySet = true;
6732 MgntActSet_RF_State(dev, eRfPowerStateToSet, RF_CHANGE_BY_HW);
6734 /* To update the UI status for Power status changed */
6735 if(priv->ieee80211->bHwRadioOff == true)
6738 //if(!priv->RfOffReason)
6741 // argv[1] = "RFOFF";
6743 argv[0] = RadioPowerPath;
6746 call_usermodehelper(RadioPowerPath,argv,envp,1);
6753 static u8 read_acadapter_file(char *filename)
6755 //#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21))
6762 mm_segment_t old_fs = get_fs();
6765 fd = sys_open(filename, O_RDONLY, 0);
6767 while (sys_read(fd, buf, 1) == 1)
6782 // printk("%s \n", ret);
6785 if(strncmp(ret, "off-line",8) == 0)
6793 /***************************************************************************
6794 ------------------- module init / exit stubs ----------------
6795 ****************************************************************************/
6796 module_init(rtl8180_pci_module_init);
6797 module_exit(rtl8180_pci_module_exit);