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 #include <linux/syscalls.h>
63 //#include <linux/fcntl.h>
64 //#include <asm/uaccess.h>
67 #include "r8180_sa2400.h" /* PHILIPS Radio frontend */
68 #include "r8180_max2820.h" /* MAXIM Radio frontend */
69 #include "r8180_gct.h" /* GCT Radio frontend */
70 #include "r8180_rtl8225.h" /* RTL8225 Radio frontend */
71 #include "r8180_rtl8255.h" /* RTL8255 Radio frontend */
72 #include "r8180_93cx6.h" /* Card EEPROM */
78 #include "ieee80211/dot11d.h"
80 #ifndef PCI_VENDOR_ID_BELKIN
81 #define PCI_VENDOR_ID_BELKIN 0x1799
83 #ifndef PCI_VENDOR_ID_DLINK
84 #define PCI_VENDOR_ID_DLINK 0x1186
87 static struct pci_device_id rtl8180_pci_id_tbl[] __devinitdata = {
89 .vendor = PCI_VENDOR_ID_REALTEK,
92 .subvendor = PCI_ANY_ID,
93 .subdevice = PCI_ANY_ID,
98 .vendor = PCI_VENDOR_ID_BELKIN,
100 .subvendor = PCI_ANY_ID,
101 .subdevice = PCI_ANY_ID,
104 { /* Belkin F5D6020 v3 */
105 .vendor = PCI_VENDOR_ID_BELKIN,
107 .subvendor = PCI_ANY_ID,
108 .subdevice = PCI_ANY_ID,
111 { /* D-Link DWL-610 */
112 .vendor = PCI_VENDOR_ID_DLINK,
114 .subvendor = PCI_ANY_ID,
115 .subdevice = PCI_ANY_ID,
119 .vendor = PCI_VENDOR_ID_REALTEK,
121 .subvendor = PCI_ANY_ID,
122 .subdevice = PCI_ANY_ID,
136 static char* ifname = "wlan%d";
137 static int hwseqnum = 0;
138 //static char* ifname = "ath%d";
139 static int hwwep = 0;
140 static int channels = 0x3fff;
142 #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 )
143 #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])
144 MODULE_LICENSE("GPL");
145 MODULE_DEVICE_TABLE(pci, rtl8180_pci_id_tbl);
146 MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>");
147 MODULE_DESCRIPTION("Linux driver for Realtek RTL8180 / RTL8185 WiFi cards");
152 MODULE_PARM(ifname, "s");
153 MODULE_PARM_DESC(devname," Net interface name, wlan%d=default");
155 MODULE_PARM(hwseqnum,"i");
156 MODULE_PARM_DESC(hwseqnum," Try to use hardware 802.11 header sequence numbers. Zero=default");
158 MODULE_PARM(hwwep,"i");
159 MODULE_PARM_DESC(hwwep," Try to use hardware WEP support. Still broken and not available on all cards");
161 MODULE_PARM(channels,"i");
162 MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");
165 module_param(ifname, charp, S_IRUGO|S_IWUSR );
166 module_param(hwseqnum,int, S_IRUGO|S_IWUSR);
167 module_param(hwwep,int, S_IRUGO|S_IWUSR);
168 module_param(channels,int, S_IRUGO|S_IWUSR);
170 MODULE_PARM_DESC(devname," Net interface name, wlan%d=default");
171 //MODULE_PARM_DESC(devname," Net interface name, ath%d=default");
172 MODULE_PARM_DESC(hwseqnum," Try to use hardware 802.11 header sequence numbers. Zero=default");
173 MODULE_PARM_DESC(hwwep," Try to use hardware WEP support. Still broken and not available on all cards");
174 MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI");
177 static int __devinit rtl8180_pci_probe(struct pci_dev *pdev,
178 const struct pci_device_id *id);
180 static void __devexit rtl8180_pci_remove(struct pci_dev *pdev);
182 static void rtl8180_shutdown (struct pci_dev *pdev)
184 struct net_device *dev = pci_get_drvdata(pdev);
185 if (dev->netdev_ops->ndo_stop)
186 dev->netdev_ops->ndo_stop(dev);
187 pci_disable_device(pdev);
190 static struct pci_driver rtl8180_pci_driver = {
191 .name = RTL8180_MODULE_NAME, /* Driver name */
192 .id_table = rtl8180_pci_id_tbl, /* PCI_ID table */
193 .probe = rtl8180_pci_probe, /* probe fn */
194 .remove = __devexit_p(rtl8180_pci_remove),/* remove fn */
195 .suspend = rtl8180_suspend, /* PM suspend fn */
196 .resume = rtl8180_resume, /* PM resume fn */
197 .shutdown = rtl8180_shutdown,
203 u8 read_nic_byte(struct net_device *dev, int x)
205 return 0xff&readb((u8*)dev->mem_start +x);
208 u32 read_nic_dword(struct net_device *dev, int x)
210 return readl((u8*)dev->mem_start +x);
213 u16 read_nic_word(struct net_device *dev, int x)
215 return readw((u8*)dev->mem_start +x);
218 void write_nic_byte(struct net_device *dev, int x,u8 y)
220 writeb(y,(u8*)dev->mem_start +x);
224 void write_nic_dword(struct net_device *dev, int x,u32 y)
226 writel(y,(u8*)dev->mem_start +x);
230 void write_nic_word(struct net_device *dev, int x,u16 y)
232 writew(y,(u8*)dev->mem_start +x);
241 inline void force_pci_posting(struct net_device *dev)
243 read_nic_byte(dev,EPROM_CMD);
248 irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs);
249 void set_nic_rxring(struct net_device *dev);
250 void set_nic_txring(struct net_device *dev);
251 static struct net_device_stats *rtl8180_stats(struct net_device *dev);
252 void rtl8180_commit(struct net_device *dev);
253 void rtl8180_start_tx_beacon(struct net_device *dev);
255 /****************************************************************************
256 -----------------------------PROCFS STUFF-------------------------
257 *****************************************************************************/
259 static struct proc_dir_entry *rtl8180_proc = NULL;
261 static int proc_get_registers(char *page, char **start,
262 off_t offset, int count,
263 int *eof, void *data)
265 struct net_device *dev = data;
266 // struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
273 /* This dump the current register page */
276 //printk( "\nD: %2x> ", n);
277 len += snprintf(page + len, count - len,
280 for(i=0;i<16 && n<=max;i++,n++)
281 len += snprintf(page + len, count - len,
282 "%2x ",read_nic_byte(dev,n));
284 // printk("%2x ",read_nic_byte(dev,n));
286 len += snprintf(page + len, count - len,"\n");
295 int get_curr_tx_free_desc(struct net_device *dev, int priority);
297 static int proc_get_stats_hw(char *page, char **start,
298 off_t offset, int count,
299 int *eof, void *data)
301 //struct net_device *dev = data;
302 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
311 static int proc_get_stats_rx(char *page, char **start,
312 off_t offset, int count,
313 int *eof, void *data)
315 struct net_device *dev = data;
316 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
320 len += snprintf(page + len, count - len,
321 /* "RX descriptor not available: %lu\n"
322 "RX incomplete (missing last descriptor): %lu\n"
324 //"RX descriptor pointer reset: %lu\n"
325 "RX descriptor pointer lost: %lu\n"
326 //"RX pointer workaround: %lu\n"
327 "RX error int: %lu\n"
328 "RX fifo overflow: %lu\n"
332 "RX DMA fail: %lu\n",
334 priv->stats.rxnolast,
335 priv->stats.rxnodata,
336 //priv->stats.rxreset,
337 priv->stats.rxnopointer,
338 //priv->stats.rxwrkaround,
340 priv->stats.rxoverflow,
342 priv->ieee80211->stats.rx_packets,
343 priv->ieee80211->stats.rx_bytes,
344 priv->stats.rxdmafail */
347 "RX CRC Error(0-500): %lu\n"
348 "RX CRC Error(500-1000): %lu\n"
349 "RX CRC Error(>1000): %lu\n"
350 "RX ICV Error: %lu\n",
353 priv->stats.rxcrcerrmin,
354 priv->stats.rxcrcerrmid,
355 priv->stats.rxcrcerrmax,
364 static int proc_get_stats_ieee(char *page, char **start,
365 off_t offset, int count,
366 int *eof, void *data)
368 struct net_device *dev = data;
369 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
373 len += snprintf(page + len, count - len,
374 "TXed association requests: %u\n"
375 "TXed authentication requests: %u\n"
376 "RXed successful association response: %u\n"
377 "RXed failed association response: %u\n"
378 "RXed successful authentication response: %u\n"
379 "RXed failed authentication response: %u\n"
380 "Association requests without response: %u\n"
381 "Authentication requests without response: %u\n"
382 "TX probe response: %u\n"
383 "RX probe request: %u\n"
384 "TX probe request: %lu\n"
385 "RX authentication requests: %lu\n"
386 "RX association requests: %lu\n"
387 "Reassociations: %lu\n",
388 priv->ieee80211->ieee_stats.tx_ass,
389 priv->ieee80211->ieee_stats.tx_aut,
390 priv->ieee80211->ieee_stats.rx_ass_ok,
391 priv->ieee80211->ieee_stats.rx_ass_err,
392 priv->ieee80211->ieee_stats.rx_aut_ok,
393 priv->ieee80211->ieee_stats.rx_aut_err,
394 priv->ieee80211->ieee_stats.ass_noresp,
395 priv->ieee80211->ieee_stats.aut_noresp,
396 priv->ieee80211->ieee_stats.tx_probe,
397 priv->ieee80211->ieee_stats.rx_probe,
398 priv->ieee80211->ieee_stats.tx_probe_rq,
399 priv->ieee80211->ieee_stats.rx_auth_rq,
400 priv->ieee80211->ieee_stats.rx_assoc_rq,
401 priv->ieee80211->ieee_stats.reassoc);
408 static int proc_get_stats_ap(char *page, char **start,
409 off_t offset, int count,
410 int *eof, void *data)
412 struct net_device *dev = data;
413 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
414 struct mac_htable_t *list;
418 if(priv->ieee80211->iw_mode != IW_MODE_MASTER){
419 len += snprintf(page + len, count - len,
420 "Card is not acting as AP...\n"
423 len += snprintf(page + len, count - len,
424 "List of associated STA:\n"
427 for(i=0;i<MAC_HTABLE_ENTRY;i++)
428 for (list = priv->ieee80211->assoc_htable[i]; list!=NULL; list = list->next){
429 len += snprintf(page + len, count - len,
430 MACSTR"\n",MAC2STR(list->adr));
439 static int proc_get_stats_tx(char *page, char **start,
440 off_t offset, int count,
441 int *eof, void *data)
443 struct net_device *dev = data;
444 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
447 unsigned long totalOK;
449 totalOK=priv->stats.txnpokint+priv->stats.txhpokint+priv->stats.txlpokint;
450 len += snprintf(page + len, count - len,
451 /* "TX normal priority ok int: %lu\n"
452 "TX normal priority error int: %lu\n"
453 "TX high priority ok int: %lu\n"
454 "TX high priority failed error int: %lu\n"
455 "TX low priority ok int: %lu\n"
456 "TX low priority failed error int: %lu\n"
459 "TX queue resume: %lu\n"
460 "TX queue stopped?: %d\n"
461 "TX fifo overflow: %lu\n"
462 //"SW TX stop: %lu\n"
463 //"SW TX wake: %lu\n"
465 "TX beacon aborted: %lu\n",
466 priv->stats.txnpokint,
468 priv->stats.txhpokint,
470 priv->stats.txlpokint,
472 priv->ieee80211->stats.tx_bytes,
473 priv->ieee80211->stats.tx_packets,
474 priv->stats.txresumed,
475 netif_queue_stopped(dev),
476 priv->stats.txoverflow,
477 //priv->ieee80211->ieee_stats.swtxstop,
478 //priv->ieee80211->ieee_stats.swtxawake,
479 priv->stats.txbeacon,
480 priv->stats.txbeaconerr */
484 "TX beacon OK: %lu\n"
485 "TX beacon error: %lu\n",
487 priv->stats.txnperr+priv->stats.txhperr+priv->stats.txlperr,
489 priv->stats.txbeacon,
490 priv->stats.txbeaconerr
497 void rtl8180_proc_module_init(void)
499 DMESG("Initializing proc filesystem");
500 rtl8180_proc=create_proc_entry(RTL8180_MODULE_NAME, S_IFDIR, init_net.proc_net);
504 void rtl8180_proc_module_remove(void)
506 remove_proc_entry(RTL8180_MODULE_NAME, init_net.proc_net);
510 void rtl8180_proc_remove_one(struct net_device *dev)
512 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
514 remove_proc_entry("stats-hw", priv->dir_dev);
515 remove_proc_entry("stats-tx", priv->dir_dev);
516 remove_proc_entry("stats-rx", priv->dir_dev);
517 // remove_proc_entry("stats-ieee", priv->dir_dev);
518 // remove_proc_entry("stats-ap", priv->dir_dev);
519 remove_proc_entry("registers", priv->dir_dev);
520 remove_proc_entry(dev->name, rtl8180_proc);
521 priv->dir_dev = NULL;
526 void rtl8180_proc_init_one(struct net_device *dev)
528 struct proc_dir_entry *e;
529 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
530 priv->dir_dev = rtl8180_proc;
531 if (!priv->dir_dev) {
532 DMESGE("Unable to initialize /proc/net/r8180/%s\n",
537 e = create_proc_read_entry("stats-hw", S_IFREG | S_IRUGO,
538 priv->dir_dev, proc_get_stats_hw, dev);
541 DMESGE("Unable to initialize "
542 "/proc/net/r8180/%s/stats-hw\n",
546 e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
547 priv->dir_dev, proc_get_stats_rx, dev);
550 DMESGE("Unable to initialize "
551 "/proc/net/r8180/%s/stats-rx\n",
556 e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
557 priv->dir_dev, proc_get_stats_tx, dev);
560 DMESGE("Unable to initialize "
561 "/proc/net/r8180/%s/stats-tx\n",
565 e = create_proc_read_entry("stats-ieee", S_IFREG | S_IRUGO,
566 priv->dir_dev, proc_get_stats_ieee, dev);
569 DMESGE("Unable to initialize "
570 "/proc/net/rtl8180/%s/stats-ieee\n",
575 e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO,
576 priv->dir_dev, proc_get_stats_ap, dev);
579 DMESGE("Unable to initialize "
580 "/proc/net/rtl8180/%s/stats-ap\n",
585 e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
586 priv->dir_dev, proc_get_registers, dev);
589 DMESGE("Unable to initialize "
590 "/proc/net/r8180/%s/registers\n",
594 /****************************************************************************
595 -----------------------------MISC STUFF-------------------------
596 *****************************************************************************/
598 FIXME: check if we can use some standard already-existent
599 data type+functions in kernel
602 short buffer_add(struct buffer **buffer, u32 *buf, dma_addr_t dma,
603 struct buffer **bufferhead)
606 DMESG("adding buffer to TX/RX struct");
613 *buffer = kmalloc(sizeof(struct buffer),GFP_KERNEL);
615 if (*buffer == NULL) {
616 DMESGE("Failed to kmalloc head of TX/RX struct");
619 (*buffer)->next=*buffer;
622 if(bufferhead !=NULL)
623 (*bufferhead) = (*buffer);
628 while(tmp->next!=(*buffer)) tmp=tmp->next;
629 if ((tmp->next= kmalloc(sizeof(struct buffer),GFP_KERNEL)) == NULL){
630 DMESGE("Failed to kmalloc TX/RX struct");
635 tmp->next->next=*buffer;
641 void buffer_free(struct net_device *dev,struct buffer **buffer,int len,short
645 struct buffer *tmp,*next;
646 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
647 struct pci_dev *pdev=priv->pdev;
650 if(! *buffer) return;
652 /*for(tmp=*buffer; tmp->next != *buffer; tmp=tmp->next)
659 pci_free_consistent(pdev,len,
662 pci_unmap_single(pdev, tmp->dma,
663 len,PCI_DMA_FROMDEVICE);
669 while(next != *buffer);
675 void print_buffer(u32 *buffer, int len)
678 u8 *buf =(u8*)buffer;
680 printk("ASCII BUFFER DUMP (len: %x):\n",len);
685 printk("\nBINARY BUFFER DUMP (len: %x):\n",len);
688 printk("%02x",buf[i]);
694 int get_curr_tx_free_desc(struct net_device *dev, int priority)
696 struct r8180_priv *priv = ieee80211_priv(dev);
702 case MANAGE_PRIORITY:
703 head = priv->txmapringhead;
704 tail = priv->txmapringtail;
707 head = priv->txbkpringhead;
708 tail = priv->txbkpringtail;
711 head = priv->txbepringhead;
712 tail = priv->txbepringtail;
715 head = priv->txvipringhead;
716 tail = priv->txvipringtail;
719 head = priv->txvopringhead;
720 tail = priv->txvopringtail;
723 head = priv->txhpringhead;
724 tail = priv->txhpringtail;
730 //DMESG("%x %x", head, tail);
732 /* FIXME FIXME FIXME FIXME */
735 if( head <= tail ) return priv->txringcount-1 - (tail - head)/8;
736 return (head - tail)/8/4;
739 ret = priv->txringcount - (tail - head)/8;
741 ret = (head - tail)/8;
743 if(ret > priv->txringcount ) DMESG("BUG");
749 short check_nic_enought_desc(struct net_device *dev, int priority)
751 struct r8180_priv *priv = ieee80211_priv(dev);
752 struct ieee80211_device *ieee = netdev_priv(dev);
754 int requiredbyte, required;
755 requiredbyte = priv->ieee80211->fts + sizeof(struct ieee80211_header_data);
757 if(ieee->current_network.QoS_Enable) {
761 required = requiredbyte / (priv->txbuffsize-4);
762 if (requiredbyte % priv->txbuffsize) required++;
763 /* for now we keep two free descriptor as a safety boundary
764 * between the tail and the head
767 return (required+2 < get_curr_tx_free_desc(dev,priority));
771 /* This function is only for debuging purpose */
772 void check_tx_ring(struct net_device *dev, int pri)
774 static int maxlog =3;
775 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
784 struct buffer* buffer;
787 if (maxlog <0 ) return;
790 case MANAGE_PRIORITY:
791 tail = priv->txmapringtail;
792 begin = priv->txmapring;
793 head = priv->txmapringhead;
794 nic = read_nic_dword(dev,TX_MANAGEPRIORITY_RING_ADDR);
795 buffer = priv->txmapbufs;
796 nicbegin = priv->txmapringdma;
801 tail = priv->txbkpringtail;
802 begin = priv->txbkpring;
803 head = priv->txbkpringhead;
804 nic = read_nic_dword(dev,TX_BKPRIORITY_RING_ADDR);
805 buffer = priv->txbkpbufs;
806 nicbegin = priv->txbkpringdma;
810 tail = priv->txbepringtail;
811 begin = priv->txbepring;
812 head = priv->txbepringhead;
813 nic = read_nic_dword(dev,TX_BEPRIORITY_RING_ADDR);
814 buffer = priv->txbepbufs;
815 nicbegin = priv->txbepringdma;
819 tail = priv->txvipringtail;
820 begin = priv->txvipring;
821 head = priv->txvipringhead;
822 nic = read_nic_dword(dev,TX_VIPRIORITY_RING_ADDR);
823 buffer = priv->txvipbufs;
824 nicbegin = priv->txvipringdma;
829 tail = priv->txvopringtail;
830 begin = priv->txvopring;
831 head = priv->txvopringhead;
832 nic = read_nic_dword(dev,TX_VOPRIORITY_RING_ADDR);
833 buffer = priv->txvopbufs;
834 nicbegin = priv->txvopringdma;
838 tail = priv->txhpringtail;
839 begin = priv->txhpring;
840 head = priv->txhpringhead;
841 nic = read_nic_dword(dev,TX_HIGHPRIORITY_RING_ADDR);
842 buffer = priv->txhpbufs;
843 nicbegin = priv->txhpringdma;
852 DMESGE ("NIC TX ack, but TX queue corrupted!");
855 for(i=0,buf=buffer, tmp=begin;
856 tmp<begin+(priv->txringcount)*8;
857 tmp+=8,buf=buf->next,i++)
859 DMESG("BUF%d %s %x %s. Next : %x",i,
860 *tmp & (1<<31) ? "filled" : "empty",
862 *tmp & (1<<15)? "ok": "err", *(tmp+4));
870 /* this function is only for debugging purpose */
871 void check_rxbuf(struct net_device *dev)
873 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
881 DMESGE ("NIC RX ack, but RX queue corrupted!");
885 for(buf=priv->rxbuffer, tmp=priv->rxring;
886 tmp < priv->rxring+(priv->rxringcount)*rx_desc_size;
887 tmp+=rx_desc_size, buf=buf->next)
890 *tmp & (1<<31) ? "empty" : "filled",
898 void dump_eprom(struct net_device *dev)
902 DMESG("EEPROM addr %x : %x", i, eprom_read(dev,i));
906 void rtl8180_dump_reg(struct net_device *dev)
912 DMESG("Dumping NIC register map");
916 printk( "\nD: %2x> ", n);
917 for(i=0;i<16 && n<=max;i++,n++)
918 printk("%2x ",read_nic_byte(dev,n));
924 void fix_tx_fifo(struct net_device *dev)
926 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
929 #ifdef DEBUG_TX_ALLOC
930 DMESG("FIXING TX FIFOs");
932 for (tmp=priv->txmapring, i=0;
933 i < priv->txringcount;
935 *tmp = *tmp &~ (1<<31);
938 for (tmp=priv->txbkpring, i=0;
939 i < priv->txringcount;
941 *tmp = *tmp &~ (1<<31);
944 for (tmp=priv->txbepring, i=0;
945 i < priv->txringcount;
947 *tmp = *tmp &~ (1<<31);
949 for (tmp=priv->txvipring, i=0;
950 i < priv->txringcount;
952 *tmp = *tmp &~ (1<<31);
955 for (tmp=priv->txvopring, i=0;
956 i < priv->txringcount;
958 *tmp = *tmp &~ (1<<31);
961 for (tmp=priv->txhpring, i=0;
962 i < priv->txringcount;
964 *tmp = *tmp &~ (1<<31);
967 for (tmp=priv->txbeaconring, i=0;
968 i < priv->txbeaconcount;
970 *tmp = *tmp &~ (1<<31);
972 #ifdef DEBUG_TX_ALLOC
973 DMESG("TX FIFOs FIXED");
975 priv->txmapringtail = priv->txmapring;
976 priv->txmapringhead = priv->txmapring;
977 priv->txmapbufstail = priv->txmapbufs;
979 priv->txbkpringtail = priv->txbkpring;
980 priv->txbkpringhead = priv->txbkpring;
981 priv->txbkpbufstail = priv->txbkpbufs;
983 priv->txbepringtail = priv->txbepring;
984 priv->txbepringhead = priv->txbepring;
985 priv->txbepbufstail = priv->txbepbufs;
987 priv->txvipringtail = priv->txvipring;
988 priv->txvipringhead = priv->txvipring;
989 priv->txvipbufstail = priv->txvipbufs;
991 priv->txvopringtail = priv->txvopring;
992 priv->txvopringhead = priv->txvopring;
993 priv->txvopbufstail = priv->txvopbufs;
995 priv->txhpringtail = priv->txhpring;
996 priv->txhpringhead = priv->txhpring;
997 priv->txhpbufstail = priv->txhpbufs;
999 priv->txbeaconringtail = priv->txbeaconring;
1000 priv->txbeaconbufstail = priv->txbeaconbufs;
1001 set_nic_txring(dev);
1003 ieee80211_reset_queue(priv->ieee80211);
1004 priv->ack_tx_to_ieee = 0;
1008 void fix_rx_fifo(struct net_device *dev)
1010 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1012 struct buffer *rxbuf;
1015 rx_desc_size = 8; // 4*8 = 32 bytes
1017 #ifdef DEBUG_RXALLOC
1018 DMESG("FIXING RX FIFO");
1022 for (tmp=priv->rxring, rxbuf=priv->rxbufferhead;
1023 (tmp < (priv->rxring)+(priv->rxringcount)*rx_desc_size);
1024 tmp+=rx_desc_size,rxbuf=rxbuf->next){
1025 *(tmp+2) = rxbuf->dma;
1027 *tmp=*tmp | priv->rxbuffersize;
1031 #ifdef DEBUG_RXALLOC
1032 DMESG("RX FIFO FIXED");
1036 priv->rxringtail=priv->rxring;
1037 priv->rxbuffer=priv->rxbufferhead;
1038 priv->rx_skb_complete=1;
1039 set_nic_rxring(dev);
1043 /****************************************************************************
1044 ------------------------------HW STUFF---------------------------
1045 *****************************************************************************/
1047 unsigned char QUALITY_MAP[] = {
1048 0x64, 0x64, 0x64, 0x63, 0x63, 0x62, 0x62, 0x61,
1049 0x61, 0x60, 0x60, 0x5f, 0x5f, 0x5e, 0x5d, 0x5c,
1050 0x5b, 0x5a, 0x59, 0x57, 0x56, 0x54, 0x52, 0x4f,
1051 0x4c, 0x49, 0x45, 0x41, 0x3c, 0x37, 0x31, 0x29,
1052 0x24, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
1053 0x22, 0x22, 0x21, 0x21, 0x21, 0x21, 0x21, 0x20,
1054 0x20, 0x20, 0x20, 0x1f, 0x1f, 0x1e, 0x1e, 0x1e,
1055 0x1d, 0x1d, 0x1c, 0x1c, 0x1b, 0x1a, 0x19, 0x19,
1056 0x18, 0x17, 0x16, 0x15, 0x14, 0x12, 0x11, 0x0f,
1057 0x0e, 0x0c, 0x0a, 0x08, 0x06, 0x04, 0x01, 0x00
1060 unsigned char STRENGTH_MAP[] = {
1061 0x64, 0x64, 0x63, 0x62, 0x61, 0x60, 0x5f, 0x5e,
1062 0x5d, 0x5c, 0x5b, 0x5a, 0x57, 0x54, 0x52, 0x50,
1063 0x4e, 0x4c, 0x4a, 0x48, 0x46, 0x44, 0x41, 0x3f,
1064 0x3c, 0x3a, 0x37, 0x36, 0x36, 0x1c, 0x1c, 0x1b,
1065 0x1b, 0x1a, 0x1a, 0x19, 0x19, 0x18, 0x18, 0x17,
1066 0x17, 0x16, 0x16, 0x15, 0x15, 0x14, 0x14, 0x13,
1067 0x13, 0x12, 0x12, 0x11, 0x11, 0x10, 0x10, 0x0f,
1068 0x0f, 0x0e, 0x0e, 0x0d, 0x0d, 0x0c, 0x0c, 0x0b,
1069 0x0b, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x07,
1070 0x07, 0x06, 0x06, 0x05, 0x04, 0x03, 0x02, 0x00
1073 void rtl8180_RSSI_calc(struct net_device *dev, u8 *rssi, u8 *qual){
1074 //void Mlme_UpdateRssiSQ(struct net_device *dev, u8 *rssi, u8 *qual){
1075 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1086 _rssi = 0; // avoid gcc complains..
1089 temp = QUALITY_MAP[q];
1101 switch(priv->rf_chip){
1105 if ( !lsb || !(temp2 <= 0x3c) ) {
1108 temp2 = 100 * temp2 / 0x3c;
1110 *rssi = temp2 & 0xff;
1111 _rssi = temp2 & 0xff;
1113 case RFCHIPID_INTERSIL:
1115 temp2 &= 0xfffffffe;
1124 if ( temp2 <= 0x3e0000 ) {
1125 if ( temp2 < 0xffef0000 )
1139 temp3 = temp3 / 0x6d;
1141 _rssi = temp3 & 0xff;
1142 *rssi = temp3 & 0xff;
1147 if ( ! lsb || !(temp2 <= 0x3c) ){
1150 temp2 = (100 * temp2) / 0x3c;
1152 *rssi = temp2 & 0xff;
1153 _rssi = temp2 & 0xff;
1155 case RFCHIPID_PHILIPS:
1156 if( orig_qual <= 0x4e ){
1157 _rssi = STRENGTH_MAP[orig_qual];
1172 case RFCHIPID_MAXIM:
1180 *rssi = temp2 & 0xff;
1181 _rssi = temp2 & 0xff;
1185 if ( _rssi < 0x64 ){
1197 void rtl8180_irq_enable(struct net_device *dev)
1199 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1200 priv->irq_enabled = 1;
1202 write_nic_word(dev,INTA_MASK,INTA_RXOK | INTA_RXDESCERR | INTA_RXOVERFLOW |\
1203 INTA_TXOVERFLOW | INTA_HIPRIORITYDESCERR | INTA_HIPRIORITYDESCOK |\
1204 INTA_NORMPRIORITYDESCERR | INTA_NORMPRIORITYDESCOK |\
1205 INTA_LOWPRIORITYDESCERR | INTA_LOWPRIORITYDESCOK | INTA_TIMEOUT);
1207 write_nic_word(dev,INTA_MASK, priv->irq_mask);
1211 void rtl8180_irq_disable(struct net_device *dev)
1213 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1215 write_nic_dword(dev,IMR,0);
1216 force_pci_posting(dev);
1217 priv->irq_enabled = 0;
1221 void rtl8180_set_mode(struct net_device *dev,int mode)
1224 ecmd=read_nic_byte(dev, EPROM_CMD);
1225 ecmd=ecmd &~ EPROM_CMD_OPERATING_MODE_MASK;
1226 ecmd=ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
1227 ecmd=ecmd &~ (1<<EPROM_CS_SHIFT);
1228 ecmd=ecmd &~ (1<<EPROM_CK_SHIFT);
1229 write_nic_byte(dev, EPROM_CMD, ecmd);
1232 void rtl8180_adapter_start(struct net_device *dev);
1233 void rtl8180_beacon_tx_enable(struct net_device *dev);
1235 void rtl8180_update_msr(struct net_device *dev)
1237 struct r8180_priv *priv = ieee80211_priv(dev);
1241 msr = read_nic_byte(dev, MSR);
1242 msr &= ~ MSR_LINK_MASK;
1244 rxconf=read_nic_dword(dev,RX_CONF);
1246 if(priv->ieee80211->state == IEEE80211_LINKED)
1248 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
1249 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
1250 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
1251 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
1252 else if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
1253 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
1255 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
1256 rxconf |= (1<<RX_CHECK_BSSID_SHIFT);
1259 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
1260 rxconf &= ~(1<<RX_CHECK_BSSID_SHIFT);
1263 write_nic_byte(dev, MSR, msr);
1264 write_nic_dword(dev, RX_CONF, rxconf);
1270 void rtl8180_set_chan(struct net_device *dev,short ch)
1272 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1274 if((ch > 14) || (ch < 1))
1276 printk("In %s: Invalid chnanel %d\n", __func__, ch);
1281 //printk("in %s:channel is %d\n",__func__,ch);
1282 priv->rf_set_chan(dev,priv->chan);
1287 void rtl8180_rx_enable(struct net_device *dev)
1291 /* for now we accept data, management & ctl frame*/
1292 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1294 rxconf=read_nic_dword(dev,RX_CONF);
1295 rxconf = rxconf &~ MAC_FILTER_MASK;
1296 rxconf = rxconf | (1<<ACCEPT_MNG_FRAME_SHIFT);
1297 rxconf = rxconf | (1<<ACCEPT_DATA_FRAME_SHIFT);
1298 rxconf = rxconf | (1<<ACCEPT_BCAST_FRAME_SHIFT);
1299 rxconf = rxconf | (1<<ACCEPT_MCAST_FRAME_SHIFT);
1300 // rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
1301 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
1303 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
1304 dev->flags & IFF_PROMISC){
1305 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
1307 rxconf = rxconf | (1<<ACCEPT_NICMAC_FRAME_SHIFT);
1308 if(priv->card_8185 == 0)
1309 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
1312 /*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
1313 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
1314 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
1317 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
1318 rxconf = rxconf | (1<<ACCEPT_CTL_FRAME_SHIFT);
1319 rxconf = rxconf | (1<<ACCEPT_ICVERR_FRAME_SHIFT);
1320 rxconf = rxconf | (1<<ACCEPT_PWR_FRAME_SHIFT);
1323 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
1324 rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
1326 //if(!priv->card_8185){
1327 rxconf = rxconf &~ RX_FIFO_THRESHOLD_MASK;
1328 rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
1331 rxconf = rxconf | (1<<RX_AUTORESETPHY_SHIFT);
1332 rxconf = rxconf &~ MAX_RX_DMA_MASK;
1333 rxconf = rxconf | (MAX_RX_DMA_2048<<MAX_RX_DMA_SHIFT);
1335 //if(!priv->card_8185)
1336 rxconf = rxconf | RCR_ONLYERLPKT;
1338 rxconf = rxconf &~ RCR_CS_MASK;
1339 if(!priv->card_8185)
1340 rxconf |= (priv->rcr_csense<<RCR_CS_SHIFT);
1341 // rxconf &=~ 0xfff00000;
1342 // rxconf |= 0x90100000;//9014f76f;
1343 write_nic_dword(dev, RX_CONF, rxconf);
1348 DMESG("rxconf: %x %x",rxconf ,read_nic_dword(dev,RX_CONF));
1350 cmd=read_nic_byte(dev,CMD);
1351 write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
1353 /* In rtl8139 driver seems that DMA threshold has to be written
1354 * after enabling RX, so we rewrite RX_CONFIG register
1357 // write_nic_dword(dev, RX_CONF, rxconf);
1362 void set_nic_txring(struct net_device *dev)
1364 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1365 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1367 write_nic_dword(dev, TX_MANAGEPRIORITY_RING_ADDR, priv->txmapringdma);
1368 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1369 write_nic_dword(dev, TX_BKPRIORITY_RING_ADDR, priv->txbkpringdma);
1370 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1371 write_nic_dword(dev, TX_BEPRIORITY_RING_ADDR, priv->txbepringdma);
1372 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1373 write_nic_dword(dev, TX_VIPRIORITY_RING_ADDR, priv->txvipringdma);
1374 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1375 write_nic_dword(dev, TX_VOPRIORITY_RING_ADDR, priv->txvopringdma);
1376 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1377 write_nic_dword(dev, TX_HIGHPRIORITY_RING_ADDR, priv->txhpringdma);
1378 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
1380 write_nic_dword(dev, TX_BEACON_RING_ADDR, priv->txbeaconringdma);
1384 void rtl8180_conttx_enable(struct net_device *dev)
1387 txconf = read_nic_dword(dev,TX_CONF);
1388 txconf = txconf &~ TX_LOOPBACK_MASK;
1389 txconf = txconf | (TX_LOOPBACK_CONTINUE <<TX_LOOPBACK_SHIFT);
1390 write_nic_dword(dev,TX_CONF,txconf);
1394 void rtl8180_conttx_disable(struct net_device *dev)
1397 txconf = read_nic_dword(dev,TX_CONF);
1398 txconf = txconf &~ TX_LOOPBACK_MASK;
1399 txconf = txconf | (TX_LOOPBACK_NONE <<TX_LOOPBACK_SHIFT);
1400 write_nic_dword(dev,TX_CONF,txconf);
1404 void rtl8180_tx_enable(struct net_device *dev)
1410 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1411 txconf= read_nic_dword(dev,TX_CONF);
1414 if(priv->card_8185){
1417 byte = read_nic_byte(dev,CW_CONF);
1418 byte &= ~(1<<CW_CONF_PERPACKET_CW_SHIFT);
1419 byte &= ~(1<<CW_CONF_PERPACKET_RETRY_SHIFT);
1420 write_nic_byte(dev, CW_CONF, byte);
1422 tx_agc_ctl = read_nic_byte(dev, TX_AGC_CTL);
1423 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_GAIN_SHIFT);
1424 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT);
1425 tx_agc_ctl |=(1<<TX_AGC_CTL_FEEDBACK_ANT);
1426 write_nic_byte(dev, TX_AGC_CTL, tx_agc_ctl);
1428 write_nic_word(dev, 0x5e, 0x01);
1429 force_pci_posting(dev);
1431 write_nic_word(dev, 0xfe, 0x10);
1432 force_pci_posting(dev);
1434 write_nic_word(dev, 0x5e, 0x00);
1435 force_pci_posting(dev);
1438 write_nic_byte(dev, 0xec, 0x3f); /* Disable early TX */
1441 if(priv->card_8185){
1443 txconf = txconf &~ (1<<TCR_PROBE_NOTIMESTAMP_SHIFT);
1448 txconf= txconf &~ (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
1450 txconf= txconf | (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
1453 txconf = txconf &~ TX_LOOPBACK_MASK;
1454 txconf = txconf | (TX_LOOPBACK_NONE <<TX_LOOPBACK_SHIFT);
1455 txconf = txconf &~ TCR_DPRETRY_MASK;
1456 txconf = txconf &~ TCR_RTSRETRY_MASK;
1457 txconf = txconf | (priv->retry_data<<TX_DPRETRY_SHIFT);
1458 txconf = txconf | (priv->retry_rts<<TX_RTSRETRY_SHIFT);
1459 txconf = txconf &~ (1<<TX_NOCRC_SHIFT);
1461 if(priv->card_8185){
1462 if(priv->hw_plcp_len)
1463 txconf = txconf &~ TCR_PLCP_LEN;
1465 txconf = txconf | TCR_PLCP_LEN;
1467 txconf = txconf &~ TCR_SAT;
1469 txconf = txconf &~ TCR_MXDMA_MASK;
1470 txconf = txconf | (TCR_MXDMA_2048<<TCR_MXDMA_SHIFT);
1471 txconf = txconf | TCR_CWMIN;
1472 txconf = txconf | TCR_DISCW;
1474 // if(priv->ieee80211->hw_wep)
1475 // txconf=txconf &~ (1<<TX_NOICV_SHIFT);
1477 txconf=txconf | (1<<TX_NOICV_SHIFT);
1479 write_nic_dword(dev,TX_CONF,txconf);
1485 DMESG("txconf: %x %x",txconf,read_nic_dword(dev,TX_CONF));
1488 cmd=read_nic_byte(dev,CMD);
1489 write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));
1492 write_nic_dword(dev,TX_CONF,txconf);
1495 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1496 write_nic_byte(dev, TX_DMA_POLLING, priv->dma_poll_mask);
1497 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1502 void rtl8180_beacon_tx_enable(struct net_device *dev)
1504 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1506 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1507 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_BQ);
1508 write_nic_byte(dev,TPPollStop, priv->dma_poll_mask);
1509 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1513 void rtl8180_beacon_tx_disable(struct net_device *dev)
1515 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1517 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
1518 priv->dma_poll_stop_mask |= TPPOLLSTOP_BQ;
1519 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
1520 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
1525 void rtl8180_rtx_disable(struct net_device *dev)
1528 struct r8180_priv *priv = ieee80211_priv(dev);
1530 cmd=read_nic_byte(dev,CMD);
1531 write_nic_byte(dev, CMD, cmd &~ \
1532 ((1<<CMD_RX_ENABLE_SHIFT)|(1<<CMD_TX_ENABLE_SHIFT)));
1533 force_pci_posting(dev);
1535 /*while (read_nic_byte(dev,CMD) & (1<<CMD_RX_ENABLE_SHIFT))
1539 if(!priv->rx_skb_complete)
1540 dev_kfree_skb_any(priv->rx_skb);
1544 int alloc_tx_beacon_desc_ring(struct net_device *dev, int count)
1548 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1550 priv->txbeaconring = (u32*)pci_alloc_consistent(priv->pdev,
1551 sizeof(u32)*8*count,
1552 &priv->txbeaconringdma);
1553 if (!priv->txbeaconring) return -1;
1554 for (tmp=priv->txbeaconring,i=0;i<count;i++){
1555 *tmp = *tmp &~ (1<<31); // descriptor empty, owned by the drv
1557 *(tmp+2) = (u32)dma_tmp;
1561 *(tmp+4) = (u32)priv->txbeaconringdma+((i+1)*8*4);
1563 *(tmp+4) = (u32)priv->txbeaconringdma;
1571 short alloc_tx_desc_ring(struct net_device *dev, int bufsize, int count,
1577 dma_addr_t dma_desc, dma_tmp;
1578 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1579 struct pci_dev *pdev = priv->pdev;
1582 if((bufsize & 0xfff) != bufsize) {
1583 DMESGE ("TX buffer allocation too large");
1586 desc = (u32*)pci_alloc_consistent(pdev,
1587 sizeof(u32)*8*count+256, &dma_desc);
1588 if(desc==NULL) return -1;
1589 if(dma_desc & 0xff){
1592 * descriptor's buffer must be 256 byte aligned
1593 * we shouldn't be here, since we set DMA mask !
1595 WARN(1, "DMA buffer is not aligned\n");
1598 for (i=0;i<count;i++)
1600 buf = (void*)pci_alloc_consistent(pdev,bufsize,&dma_tmp);
1601 if (buf == NULL) return -ENOMEM;
1605 case TX_NORMPRIORITY_RING_ADDR:
1606 if(-1 == buffer_add(&(priv->txnpbufs),buf,dma_tmp,NULL)){
1607 DMESGE("Unable to allocate mem for buffer NP");
1612 case TX_LOWPRIORITY_RING_ADDR:
1613 if(-1 == buffer_add(&(priv->txlpbufs),buf,dma_tmp,NULL)){
1614 DMESGE("Unable to allocate mem for buffer LP");
1619 case TX_HIGHPRIORITY_RING_ADDR:
1620 if(-1 == buffer_add(&(priv->txhpbufs),buf,dma_tmp,NULL)){
1621 DMESGE("Unable to allocate mem for buffer HP");
1626 case TX_MANAGEPRIORITY_RING_ADDR:
1627 if(-1 == buffer_add(&(priv->txmapbufs),buf,dma_tmp,NULL)){
1628 DMESGE("Unable to allocate mem for buffer NP");
1633 case TX_BKPRIORITY_RING_ADDR:
1634 if(-1 == buffer_add(&(priv->txbkpbufs),buf,dma_tmp,NULL)){
1635 DMESGE("Unable to allocate mem for buffer LP");
1639 case TX_BEPRIORITY_RING_ADDR:
1640 if(-1 == buffer_add(&(priv->txbepbufs),buf,dma_tmp,NULL)){
1641 DMESGE("Unable to allocate mem for buffer NP");
1646 case TX_VIPRIORITY_RING_ADDR:
1647 if(-1 == buffer_add(&(priv->txvipbufs),buf,dma_tmp,NULL)){
1648 DMESGE("Unable to allocate mem for buffer LP");
1652 case TX_VOPRIORITY_RING_ADDR:
1653 if(-1 == buffer_add(&(priv->txvopbufs),buf,dma_tmp,NULL)){
1654 DMESGE("Unable to allocate mem for buffer NP");
1659 case TX_HIGHPRIORITY_RING_ADDR:
1660 if(-1 == buffer_add(&(priv->txhpbufs),buf,dma_tmp,NULL)){
1661 DMESGE("Unable to allocate mem for buffer HP");
1665 case TX_BEACON_RING_ADDR:
1666 if(-1 == buffer_add(&(priv->txbeaconbufs),buf,dma_tmp,NULL)){
1667 DMESGE("Unable to allocate mem for buffer BP");
1672 *tmp = *tmp &~ (1<<31); // descriptor empty, owned by the drv
1673 *(tmp+2) = (u32)dma_tmp;
1677 *(tmp+4) = (u32)dma_desc+((i+1)*8*4);
1679 *(tmp+4) = (u32)dma_desc;
1685 case TX_MANAGEPRIORITY_RING_ADDR:
1686 priv->txmapringdma=dma_desc;
1687 priv->txmapring=desc;
1690 case TX_BKPRIORITY_RING_ADDR:
1691 priv->txbkpringdma=dma_desc;
1692 priv->txbkpring=desc;
1695 case TX_BEPRIORITY_RING_ADDR:
1696 priv->txbepringdma=dma_desc;
1697 priv->txbepring=desc;
1700 case TX_VIPRIORITY_RING_ADDR:
1701 priv->txvipringdma=dma_desc;
1702 priv->txvipring=desc;
1705 case TX_VOPRIORITY_RING_ADDR:
1706 priv->txvopringdma=dma_desc;
1707 priv->txvopring=desc;
1710 case TX_HIGHPRIORITY_RING_ADDR:
1711 priv->txhpringdma=dma_desc;
1712 priv->txhpring=desc;
1715 case TX_BEACON_RING_ADDR:
1716 priv->txbeaconringdma=dma_desc;
1717 priv->txbeaconring=desc;
1723 DMESG("Tx dma physical address: %x",dma_desc);
1730 void free_tx_desc_rings(struct net_device *dev)
1733 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1734 struct pci_dev *pdev=priv->pdev;
1735 int count = priv->txringcount;
1737 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1738 priv->txmapring, priv->txmapringdma);
1739 buffer_free(dev,&(priv->txmapbufs),priv->txbuffsize,1);
1741 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1742 priv->txbkpring, priv->txbkpringdma);
1743 buffer_free(dev,&(priv->txbkpbufs),priv->txbuffsize,1);
1745 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1746 priv->txbepring, priv->txbepringdma);
1747 buffer_free(dev,&(priv->txbepbufs),priv->txbuffsize,1);
1749 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1750 priv->txvipring, priv->txvipringdma);
1751 buffer_free(dev,&(priv->txvipbufs),priv->txbuffsize,1);
1753 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1754 priv->txvopring, priv->txvopringdma);
1755 buffer_free(dev,&(priv->txvopbufs),priv->txbuffsize,1);
1757 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1758 priv->txhpring, priv->txhpringdma);
1759 buffer_free(dev,&(priv->txhpbufs),priv->txbuffsize,1);
1761 count = priv->txbeaconcount;
1762 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1763 priv->txbeaconring, priv->txbeaconringdma);
1764 buffer_free(dev,&(priv->txbeaconbufs),priv->txbuffsize,1);
1768 void free_beacon_desc_ring(struct net_device *dev,int count)
1771 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1772 struct pci_dev *pdev=priv->pdev;
1774 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1775 priv->txbeaconring, priv->txbeaconringdma);
1777 if (priv->beacon_buf)
1778 pci_free_consistent(priv->pdev,
1779 priv->master_beaconsize,priv->beacon_buf,priv->beacondmabuf);
1783 void free_rx_desc_ring(struct net_device *dev)
1785 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1786 struct pci_dev *pdev = priv->pdev;
1788 int count = priv->rxringcount;
1790 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
1791 priv->rxring, priv->rxringdma);
1793 buffer_free(dev,&(priv->rxbuffer),priv->rxbuffersize,0);
1797 short alloc_rx_desc_ring(struct net_device *dev, u16 bufsize, int count)
1802 dma_addr_t dma_desc,dma_tmp;
1803 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1804 struct pci_dev *pdev=priv->pdev;
1808 rx_desc_size = 8; // 4*8 = 32 bytes
1810 if((bufsize & 0xfff) != bufsize){
1811 DMESGE ("RX buffer allocation too large");
1815 desc = (u32*)pci_alloc_consistent(pdev,sizeof(u32)*rx_desc_size*count+256,
1818 if(dma_desc & 0xff){
1821 * descriptor's buffer must be 256 byte aligned
1822 * should never happen since we specify the DMA mask
1824 WARN(1, "DMA buffer is not aligned\n");
1828 priv->rxringdma=dma_desc;
1831 for (i=0;i<count;i++){
1833 if ((buf= kmalloc(bufsize * sizeof(u8),GFP_ATOMIC)) == NULL){
1834 DMESGE("Failed to kmalloc RX buffer");
1838 dma_tmp = pci_map_single(pdev,buf,bufsize * sizeof(u8),
1839 PCI_DMA_FROMDEVICE);
1841 #ifdef DEBUG_ZERO_RX
1843 for(j=0;j<bufsize;j++) ((u8*)buf)[i] = 0;
1846 //buf = (void*)pci_alloc_consistent(pdev,bufsize,&dma_tmp);
1847 if(-1 == buffer_add(&(priv->rxbuffer), buf,dma_tmp,
1848 &(priv->rxbufferhead))){
1849 DMESGE("Unable to allocate mem RX buf");
1852 *tmp = 0; //zero pads the header of the descriptor
1853 *tmp = *tmp |( bufsize&0xfff);
1854 *(tmp+2) = (u32)dma_tmp;
1855 *tmp = *tmp |(1<<31); // descriptor void, owned by the NIC
1857 #ifdef DEBUG_RXALLOC
1858 DMESG("Alloc %x size buffer, DMA mem @ %x, virtual mem @ %x",
1859 (u32)(bufsize&0xfff), (u32)dma_tmp, (u32)buf);
1862 tmp=tmp+rx_desc_size;
1865 *(tmp-rx_desc_size) = *(tmp-rx_desc_size) | (1<<30); // this is the last descriptor
1868 #ifdef DEBUG_RXALLOC
1869 DMESG("RX DMA physical address: %x",dma_desc);
1876 void set_nic_rxring(struct net_device *dev)
1879 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1881 //rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1883 pgreg=read_nic_byte(dev, PGSELECT);
1884 write_nic_byte(dev, PGSELECT, pgreg &~ (1<<PGSELECT_PG_SHIFT));
1886 //rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1888 write_nic_dword(dev, RXRING_ADDR,priv->rxringdma);
1892 void rtl8180_reset(struct net_device *dev)
1894 //u32 txconf = 0x80e00707; //FIXME: Make me understandable
1897 //write_nic_dword(dev,TX_CONF,txconf);
1899 rtl8180_irq_disable(dev);
1901 cr=read_nic_byte(dev,CMD);
1903 cr = cr | (1<<CMD_RST_SHIFT);
1904 write_nic_byte(dev,CMD,cr);
1906 force_pci_posting(dev);
1910 if(read_nic_byte(dev,CMD) & (1<<CMD_RST_SHIFT))
1911 DMESGW("Card reset timeout!");
1913 DMESG("Card successfully reset");
1915 //#ifndef CONFIG_RTL8185B
1916 rtl8180_set_mode(dev,EPROM_CMD_LOAD);
1917 force_pci_posting(dev);
1922 inline u16 ieeerate2rtlrate(int rate)
1955 static u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540,720};
1956 inline u16 rtl8180_rate2rate(short rate)
1958 if (rate >12) return 10;
1959 return rtl_rate[rate];
1961 inline u8 rtl8180_IsWirelessBMode(u16 rate)
1963 if( ((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220) )
1967 u16 N_DBPSOfRate(u16 DataRate);
1971 u8 bManagementFrame,
1979 if( rtl8180_IsWirelessBMode(DataRate) )
1981 if( bManagementFrame || !bShortPreamble || DataRate == 10 )
1983 FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
1987 FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
1989 if( ( FrameLength*8 % (DataRate/10) ) != 0 ) //Get the Ceilling
1991 } else { //802.11g DSSS-OFDM PLCP length field calculation.
1992 N_DBPS = N_DBPSOfRate(DataRate);
1993 Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
1994 + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
1995 FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
1999 u16 N_DBPSOfRate(u16 DataRate)
2047 // For Netgear case, they want good-looking singal strength.
2048 // 2004.12.05, by rcnjko.
2051 NetgearSignalStrengthTranslate(
2058 // Step 1. Scale mapping.
2059 if(CurrSS >= 71 && CurrSS <= 100)
2061 RetSS = 90 + ((CurrSS - 70) / 3);
2063 else if(CurrSS >= 41 && CurrSS <= 70)
2065 RetSS = 78 + ((CurrSS - 40) / 3);
2067 else if(CurrSS >= 31 && CurrSS <= 40)
2069 RetSS = 66 + (CurrSS - 30);
2071 else if(CurrSS >= 21 && CurrSS <= 30)
2073 RetSS = 54 + (CurrSS - 20);
2075 else if(CurrSS >= 5 && CurrSS <= 20)
2077 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
2079 else if(CurrSS == 4)
2083 else if(CurrSS == 3)
2087 else if(CurrSS == 2)
2091 else if(CurrSS == 1)
2099 //RT_TRACE(COMP_DBG, DBG_LOUD, ("##### After Mapping: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2101 // Step 2. Smoothing.
2104 RetSS = ((LastSS * 5) + (RetSS)+ 5) / 6;
2106 //RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$$$ After Smoothing: LastSS: %d, CurrSS: %d, RetSS: %d\n", LastSS, CurrSS, RetSS));
2112 // Translate 0-100 signal strength index into dBm.
2116 u8 SignalStrengthIndex // 0-100 index.
2119 long SignalPower; // in dBm.
2121 // Translate to dBm (x=0.5y-95).
2122 SignalPower = (long)((SignalStrengthIndex + 1) >> 1);
2129 // Perform signal smoothing for dynamic mechanism.
2130 // This is different with PerformSignalSmoothing8185 in smoothing fomula.
2131 // No dramatic adjustion is apply because dynamic mechanism need some degree
2132 // of correctness. Ported from 8187B.
2133 // 2007-02-26, by Bruce.
2136 PerformUndecoratedSignalSmoothing8185(
2137 struct r8180_priv *priv,
2143 // Determin the current packet is CCK rate.
2144 priv->bCurCCKPkt = bCckRate;
2146 if(priv->UndecoratedSmoothedSS >= 0)
2148 priv->UndecoratedSmoothedSS = ( (priv->UndecoratedSmoothedSS * 5) + (priv->SignalStrength * 10) ) / 6;
2152 priv->UndecoratedSmoothedSS = priv->SignalStrength * 10;
2155 priv->UndercorateSmoothedRxPower = ( (priv->UndercorateSmoothedRxPower * 50) + (priv->RxPower* 11)) / 60;
2157 // printk("Sommthing SignalSterngth (%d) => UndecoratedSmoothedSS (%d)\n", priv->SignalStrength, priv->UndecoratedSmoothedSS);
2158 // printk("Sommthing RxPower (%d) => UndecoratedRxPower (%d)\n", priv->RxPower, priv->UndercorateSmoothedRxPower);
2160 //if(priv->CurCCKRSSI >= 0 && bCckRate)
2163 priv->CurCCKRSSI = priv->RSSI;
2167 priv->CurCCKRSSI = 0;
2170 // Boundary checking.
2171 // TODO: The overflow condition does happen, if we want to fix,
2172 // we shall recalculate thresholds first.
2173 if(priv->UndecoratedSmoothedSS > 100)
2175 // printk("UndecoratedSmoothedSS(%d) overflow, SignalStrength(%d)\n", priv->UndecoratedSmoothedSS, priv->SignalStrength);
2177 if(priv->UndecoratedSmoothedSS < 0)
2179 // printk("UndecoratedSmoothedSS(%d) underflow, SignalStrength(%d)\n", priv->UndecoratedSmoothedSS, priv->SignalStrength);
2186 /* This is rough RX isr handling routine*/
2187 void rtl8180_rx(struct net_device *dev)
2189 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2190 struct sk_buff *tmp_skb;
2192 //struct sk_buff *skb;
2196 unsigned char quality, signal;
2207 u8 LNA_gain[4]={02, 17, 29, 39};
2209 struct ieee80211_hdr *hdr;//by amy
2211 u8 bHwError = 0,bCRC = 0,bICV = 0;
2215 bool bCckRate = false;
2217 long SignalStrengthIndex = 0;//+by amy 080312
2218 // u8 SignalStrength = 0;
2219 struct ieee80211_rx_stats stats = {
2223 // .mac_time = jiffies,
2224 .freq = IEEE80211_24GHZ_BAND,
2227 stats.nic_type = NIC_8185B;
2230 //printk("receive frame!%d\n",count++);
2231 //if (!priv->rxbuffer) DMESG ("EE: NIC RX ack, but RX queue corrupted!");
2234 if ((*(priv->rxringtail)) & (1<<31)) {
2236 /* we have got an RX int, but the descriptor
2237 * we are pointing is empty*/
2239 priv->stats.rxnodata++;
2240 priv->ieee80211->stats.rx_errors++;
2242 /* if (! *(priv->rxring) & (1<<31)) {
2244 priv->stats.rxreset++;
2245 priv->rxringtail=priv->rxring;
2246 priv->rxbuffer=priv->rxbufferhead;
2251 /* Maybe it is possible that the NIC has skipped some descriptors or
2252 * it has reset its internal pointer to the beginning of the ring
2253 * we search for the first filled descriptor in the ring, or we break
2254 * putting again the pointer in the old location if we do not found any.
2255 * This is quite dangerous, what does happen if the nic writes
2256 * two descriptor (say A and B) when we have just checked the descriptor
2257 * A and we are going to check the descriptor B..This might happen if the
2258 * interrupt was dummy, there was not really filled descriptors and
2259 * the NIC didn't lose pointer
2262 //priv->stats.rxwrkaround++;
2264 tmp = priv->rxringtail;
2265 while (*(priv->rxringtail) & (1<<31)){
2267 priv->rxringtail+=4;
2269 if(priv->rxringtail >=
2270 (priv->rxring)+(priv->rxringcount )*4)
2271 priv->rxringtail=priv->rxring;
2273 priv->rxbuffer=(priv->rxbuffer->next);
2275 if(priv->rxringtail == tmp ){
2276 //DMESG("EE: Could not find RX pointer");
2277 priv->stats.rxnopointer++;
2284 tmp = priv->rxringtail;
2286 if(tmp == priv->rxring)
2287 //tmp = priv->rxring + (priv->rxringcount )*rx_desc_size; xiong-2006-11-15
2288 tmp = priv->rxring + (priv->rxringcount - 1)*rx_desc_size;
2290 tmp -= rx_desc_size;
2292 if(! (*tmp & (1<<31)))
2294 }while(tmp != priv->rxring);
2296 if(tmp2) priv->rxringtail = tmp2;
2301 /* while there are filled descriptors */
2302 while(!(*(priv->rxringtail) & (1<<31))){
2303 if(*(priv->rxringtail) & (1<<26))
2304 DMESGW("RX buffer overflow");
2305 if(*(priv->rxringtail) & (1<<12))
2306 priv->stats.rxicverr++;
2308 if(*(priv->rxringtail) & (1<<27)){
2309 priv->stats.rxdmafail++;
2310 //DMESG("EE: RX DMA FAILED at buffer pointed by descriptor %x",(u32)priv->rxringtail);
2314 pci_dma_sync_single_for_cpu(priv->pdev,
2315 priv->rxbuffer->dma,
2316 priv->rxbuffersize * \
2318 PCI_DMA_FROMDEVICE);
2320 first = *(priv->rxringtail) & (1<<29) ? 1:0;
2321 if(first) priv->rx_prevlen=0;
2323 last = *(priv->rxringtail) & (1<<28) ? 1:0;
2325 lastlen=((*priv->rxringtail) &0xfff);
2327 /* if the last descriptor (that should
2328 * tell us the total packet len) tell
2329 * us something less than the descriptors
2330 * len we had until now, then there is some
2332 * workaround to prevent kernel panic
2334 if(lastlen < priv->rx_prevlen)
2337 len=lastlen-priv->rx_prevlen;
2339 if(*(priv->rxringtail) & (1<<13)) {
2340 //lastlen=((*priv->rxringtail) &0xfff);
2341 if ((*(priv->rxringtail) & 0xfff) <500)
2342 priv->stats.rxcrcerrmin++;
2343 else if ((*(priv->rxringtail) & 0x0fff) >1000)
2344 priv->stats.rxcrcerrmax++;
2346 priv->stats.rxcrcerrmid++;
2351 len = priv->rxbuffersize;
2355 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
2357 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
2365 priv->rx_prevlen+=len;
2367 if(priv->rx_prevlen > MAX_FRAG_THRESHOLD + 100){
2368 /* HW is probably passing several buggy frames
2369 * without FD or LD flag set.
2370 * Throw this garbage away to prevent skb
2373 if(!priv->rx_skb_complete)
2374 dev_kfree_skb_any(priv->rx_skb);
2375 priv->rx_skb_complete = 1;
2378 #ifdef DEBUG_RX_FRAG
2379 DMESG("Iteration.. len %x",len);
2380 if(first) DMESG ("First descriptor");
2381 if(last) DMESG("Last descriptor");
2384 #ifdef DEBUG_RX_VERBOSE
2385 print_buffer( priv->rxbuffer->buf, len);
2388 signal=(unsigned char)(((*(priv->rxringtail+3))& (0x00ff0000))>>16);
2389 signal=(signal&0xfe)>>1; // Modify by hikaru 6.6
2391 quality=(unsigned char)((*(priv->rxringtail+3)) & (0xff));
2393 stats.mac_time[0] = *(priv->rxringtail+1);
2394 stats.mac_time[1] = *(priv->rxringtail+2);
2395 rxpower =((char)(((*(priv->rxringtail+4))& (0x00ff0000))>>16))/2 - 42;
2396 RSSI = ((u8)(((*(priv->rxringtail+3)) & (0x0000ff00))>> 8)) & (0x7f);
2398 rate=((*(priv->rxringtail)) &
2399 ((1<<23)|(1<<22)|(1<<21)|(1<<20)))>>20;
2401 stats.rate = rtl8180_rate2rate(rate);
2403 Antenna = (((*(priv->rxringtail +3))& (0x00008000)) == 0 )? 0:1 ;
2404 // printk("in rtl8180_rx():Antenna is %d\n",Antenna);
2405 //by amy for antenna
2406 if(!rtl8180_IsWirelessBMode(stats.rate))
2409 RxAGC_dBm = rxpower+1; //bias
2413 RxAGC_dBm = signal;//bit 0 discard
2415 LNA = (u8) (RxAGC_dBm & 0x60 ) >> 5 ; //bit 6~ bit 5
2416 BB = (u8) (RxAGC_dBm & 0x1F); // bit 4 ~ bit 0
2418 RxAGC_dBm = -( LNA_gain[LNA] + (BB *2) ); //Pin_11b=-(LNA_gain+BB_gain) (dBm)
2420 RxAGC_dBm +=4; //bias
2423 if(RxAGC_dBm & 0x80) //absolute value
2424 RXAGC= ~(RxAGC_dBm)+1;
2425 bCckRate = rtl8180_IsWirelessBMode(stats.rate);
2426 // Translate RXAGC into 1-100.
2427 if(!rtl8180_IsWirelessBMode(stats.rate))
2433 RXAGC=(90-RXAGC)*100/65;
2441 RXAGC=(95-RXAGC)*100/65;
2443 priv->SignalStrength = (u8)RXAGC;
2444 priv->RecvSignalPower = RxAGC_dBm ; // It can use directly by SD3 CMLin
2445 priv->RxPower = rxpower;
2448 // SQ translation formular is provided by SD3 DZ. 2006.06.27, by rcnjko.
2450 quality = 1;//0; //0 will cause epc to show signal zero , walk aroud now;
2451 else if(quality < 27)
2454 quality = 127 - quality;
2455 priv->SignalQuality = quality;
2456 if(!priv->card_8185)
2457 printk("check your card type\n");
2459 stats.signal = (u8)quality;//priv->wstats.qual.level = priv->SignalStrength;
2460 stats.signalstrength = RXAGC;
2461 if(stats.signalstrength > 100)
2462 stats.signalstrength = 100;
2463 stats.signalstrength = (stats.signalstrength * 70)/100 + 30;
2464 // printk("==========================>rx : RXAGC is %d,signalstrength is %d\n",RXAGC,stats.signalstrength);
2465 stats.rssi = priv->wstats.qual.qual = priv->SignalQuality;
2466 stats.noise = priv->wstats.qual.noise = 100 - priv ->wstats.qual.qual;
2468 bHwError = (((*(priv->rxringtail))& (0x00000fff)) == 4080)| (((*(priv->rxringtail))& (0x04000000)) != 0 )
2469 | (((*(priv->rxringtail))& (0x08000000)) != 0 )| (((~(*(priv->rxringtail)))& (0x10000000)) != 0 )| (((~(*(priv->rxringtail)))& (0x20000000)) != 0 );
2470 bCRC = ((*(priv->rxringtail)) & (0x00002000)) >> 13;
2471 bICV = ((*(priv->rxringtail)) & (0x00001000)) >> 12;
2472 hdr = (struct ieee80211_hdr *)priv->rxbuffer->buf;
2473 fc = le16_to_cpu(hdr->frame_ctl);
2474 type = WLAN_FC_GET_TYPE(fc);
2476 if((IEEE80211_FTYPE_CTL != type) &&
2477 (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3))
2478 && (!bHwError) && (!bCRC)&& (!bICV))
2481 // Perform signal smoothing for dynamic mechanism on demand.
2482 // This is different with PerformSignalSmoothing8185 in smoothing fomula.
2483 // No dramatic adjustion is apply because dynamic mechanism need some degree
2484 // of correctness. 2007.01.23, by shien chang.
2485 PerformUndecoratedSignalSmoothing8185(priv,bCckRate);
2487 // For good-looking singal strength.
2489 SignalStrengthIndex = NetgearSignalStrengthTranslate(
2490 priv->LastSignalStrengthInPercent,
2491 priv->SignalStrength);
2493 priv->LastSignalStrengthInPercent = SignalStrengthIndex;
2494 priv->Stats_SignalStrength = TranslateToDbm8185((u8)SignalStrengthIndex);
2496 // We need more correct power of received packets and the "SignalStrength" of RxStats is beautified,
2497 // so we record the correct power here.
2499 priv->Stats_SignalQuality =(long) (priv->Stats_SignalQuality * 5 + (long)priv->SignalQuality + 5) / 6;
2500 priv->Stats_RecvSignalPower = (long)(priv->Stats_RecvSignalPower * 5 + priv->RecvSignalPower -1) / 6;
2502 // Figure out which antenna that received the lasted packet.
2503 priv->LastRxPktAntenna = Antenna ? 1 : 0; // 0: aux, 1: main.
2505 SwAntennaDiversityRxOk8185(dev, priv->SignalStrength);
2508 //by amy for antenna
2517 if(!priv->rx_skb_complete){
2518 /* seems that HW sometimes fails to reiceve and
2519 doesn't provide the last descriptor */
2521 DMESG("going to free incomplete skb");
2523 dev_kfree_skb_any(priv->rx_skb);
2524 priv->stats.rxnolast++;
2526 DMESG("free incomplete skb OK");
2529 /* support for prism header has been originally added by Christian */
2530 if(priv->prism_hdr && priv->ieee80211->iw_mode == IW_MODE_MONITOR){
2533 priv->rx_skb = dev_alloc_skb(len+2+PRISM_HDR_SIZE);
2534 if(! priv->rx_skb) goto drop;
2536 prism_hdr = (u32*) skb_put(priv->rx_skb,PRISM_HDR_SIZE);
2537 prism_hdr[0]=htonl(0x80211001); //version
2538 prism_hdr[1]=htonl(0x40); //length
2539 prism_hdr[2]=htonl(stats.mac_time[1]); //mactime (HIGH)
2540 prism_hdr[3]=htonl(stats.mac_time[0]); //mactime (LOW)
2541 rdtsc(prism_hdr[5], prism_hdr[4]); //hostime (LOW+HIGH)
2542 prism_hdr[4]=htonl(prism_hdr[4]); //Byte-Order aendern
2543 prism_hdr[5]=htonl(prism_hdr[5]); //Byte-Order aendern
2544 prism_hdr[6]=0x00; //phytype
2545 prism_hdr[7]=htonl(priv->chan); //channel
2546 prism_hdr[8]=htonl(stats.rate); //datarate
2547 prism_hdr[9]=0x00; //antenna
2548 prism_hdr[10]=0x00; //priority
2549 prism_hdr[11]=0x00; //ssi_type
2550 prism_hdr[12]=htonl(stats.signal); //ssi_signal
2551 prism_hdr[13]=htonl(stats.noise); //ssi_noise
2552 prism_hdr[14]=0x00; //preamble
2553 prism_hdr[15]=0x00; //encoding
2557 priv->rx_skb = dev_alloc_skb(len+2);
2558 if( !priv->rx_skb) goto drop;
2560 DMESG("Alloc initial skb %x",len+2);
2564 priv->rx_skb_complete=0;
2565 priv->rx_skb->dev=dev;
2567 /* if we are here we should have already RXed
2569 * If we get here and the skb is not allocated then
2570 * we have just throw out garbage (skb not allocated)
2571 * and we are still rxing garbage....
2573 if(!priv->rx_skb_complete){
2575 tmp_skb= dev_alloc_skb(priv->rx_skb->len +len+2);
2577 if(!tmp_skb) goto drop;
2581 DMESG("Realloc skb %x",len+2);
2585 DMESG("going copy prev frag %x",priv->rx_skb->len);
2587 memcpy(skb_put(tmp_skb,priv->rx_skb->len),
2591 DMESG("skb copy prev frag complete");
2594 dev_kfree_skb_any(priv->rx_skb);
2596 DMESG("prev skb free ok");
2599 priv->rx_skb=tmp_skb;
2603 DMESG("going to copy current payload %x",len);
2605 if(!priv->rx_skb_complete) {
2607 memcpy(skb_put(priv->rx_skb,len),
2608 (((unsigned char *)priv->rxbuffer->buf) + 2),len);
2610 memcpy(skb_put(priv->rx_skb,len),
2611 priv->rxbuffer->buf,len);
2615 DMESG("current fragment skb copy complete");
2618 if(last && !priv->rx_skb_complete){
2621 DMESG("Got last fragment");
2624 if(priv->rx_skb->len > 4)
2625 skb_trim(priv->rx_skb,priv->rx_skb->len-4);
2627 DMESG("yanked out crc, passing to the upper layer");
2630 #ifndef RX_DONT_PASS_UL
2631 if(!ieee80211_rx(priv->ieee80211,
2632 priv->rx_skb, &stats)){
2634 DMESGW("Packet not consumed");
2636 #endif // RX_DONT_PASS_UL
2638 dev_kfree_skb_any(priv->rx_skb);
2639 #ifndef RX_DONT_PASS_UL
2647 priv->rx_skb_complete=1;
2652 pci_dma_sync_single_for_device(priv->pdev,
2653 priv->rxbuffer->dma,
2654 priv->rxbuffersize * \
2656 PCI_DMA_FROMDEVICE);
2659 drop: // this is used when we have not enought mem
2661 /* restore the descriptor */
2662 *(priv->rxringtail+2)=priv->rxbuffer->dma;
2663 *(priv->rxringtail)=*(priv->rxringtail) &~ 0xfff;
2664 *(priv->rxringtail)=
2665 *(priv->rxringtail) | priv->rxbuffersize;
2667 *(priv->rxringtail)=
2668 *(priv->rxringtail) | (1<<31);
2674 DMESG("Current descriptor: %x",(u32)priv->rxringtail);
2676 //unsigned long flags;
2677 //spin_lock_irqsave(&priv->irq_lock,flags);
2679 priv->rxringtail+=rx_desc_size;
2680 if(priv->rxringtail >=
2681 (priv->rxring)+(priv->rxringcount )*rx_desc_size)
2682 priv->rxringtail=priv->rxring;
2684 //spin_unlock_irqrestore(&priv->irq_lock,flags);
2687 priv->rxbuffer=(priv->rxbuffer->next);
2693 // if(get_curr_tx_free_desc(dev,priority))
2694 // ieee80211_sta_ps_sleep(priv->ieee80211, &tmp, &tmp2);
2701 void rtl8180_dma_kick(struct net_device *dev, int priority)
2703 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2705 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2712 write_nic_byte(dev,TX_DMA_POLLING,
2713 (1<< TX_DMA_POLLING_LOWPRIORITY_SHIFT) |
2714 priv->dma_poll_mask);
2719 write_nic_byte(dev,TX_DMA_POLLING,
2720 (1<< TX_DMA_POLLING_NORMPRIORITY_SHIFT) |
2721 priv->dma_poll_mask);
2726 write_nic_byte(dev,TX_DMA_POLLING,
2727 (1<< TX_DMA_POLLING_HIPRIORITY_SHIFT) |
2728 priv->dma_poll_mask);
2733 write_nic_byte(dev, TX_DMA_POLLING,
2734 (1 << (priority + 1)) | priv->dma_poll_mask);
2735 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2737 force_pci_posting(dev);
2741 void rtl8180_tx_queues_stop(struct net_device *dev)
2743 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2744 u8 dma_poll_mask = (1<<TX_DMA_STOP_LOWPRIORITY_SHIFT);
2745 dma_poll_mask |= (1<<TX_DMA_STOP_HIPRIORITY_SHIFT);
2746 dma_poll_mask |= (1<<TX_DMA_STOP_NORMPRIORITY_SHIFT);
2747 dma_poll_mask |= (1<<TX_DMA_STOP_BEACON_SHIFT);
2749 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2750 write_nic_byte(dev,TX_DMA_POLLING,dma_poll_mask);
2751 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2755 void rtl8180_data_hard_stop(struct net_device *dev)
2757 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2759 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2760 priv->dma_poll_stop_mask |= TPPOLLSTOP_AC_VIQ;
2761 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
2762 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2766 void rtl8180_data_hard_resume(struct net_device *dev)
2768 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2770 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2771 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_AC_VIQ);
2772 write_nic_byte(dev,TPPollStop, priv->dma_poll_stop_mask);
2773 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
2777 /* this function TX data frames when the ieee80211 stack requires this.
2778 * It checks also if we need to stop the ieee tx queue, eventually do it
2780 void rtl8180_hard_data_xmit(struct sk_buff *skb,struct net_device *dev, int
2783 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2785 struct ieee80211_hdr_3addr *h = (struct ieee80211_hdr_3addr *) skb->data;
2786 short morefrag = (h->frame_ctl) & IEEE80211_FCTL_MOREFRAGS;
2787 unsigned long flags;
2789 //static int count = 0;
2791 mode = priv->ieee80211->iw_mode;
2793 rate = ieeerate2rtlrate(rate);
2795 * This function doesn't require lock because we make
2796 * sure it's called with the tx_lock already acquired.
2797 * this come from the kernel's hard_xmit callback (trought
2798 * the ieee stack, or from the try_wake_queue (again trought
2801 priority = AC2Q(skb->priority);
2802 spin_lock_irqsave(&priv->tx_lock,flags);
2804 if(priv->ieee80211->bHwRadioOff)
2806 spin_unlock_irqrestore(&priv->tx_lock,flags);
2811 //printk(KERN_WARNING "priority = %d@%d\n", priority, count++);
2812 if (!check_nic_enought_desc(dev, priority)){
2813 //DMESG("Error: no descriptor left by previous TX (avail %d) ",
2814 // get_curr_tx_free_desc(dev, priority));
2815 DMESGW("Error: no descriptor left by previous TX (avail %d) ",
2816 get_curr_tx_free_desc(dev, priority));
2817 //printk(KERN_WARNING "==============================================================> \n");
2818 ieee80211_stop_queue(priv->ieee80211);
2820 rtl8180_tx(dev, skb->data, skb->len, priority, morefrag,0,rate);
2821 if (!check_nic_enought_desc(dev, priority))
2822 ieee80211_stop_queue(priv->ieee80211);
2824 //dev_kfree_skb_any(skb);
2825 spin_unlock_irqrestore(&priv->tx_lock,flags);
2829 /* This is a rough attempt to TX a frame
2830 * This is called by the ieee 80211 stack to TX management frames.
2831 * If the ring is full packet are dropped (for data frame the queue
2832 * is stopped before this can happen). For this reason it is better
2833 * if the descriptors are larger than the largest management frame
2834 * we intend to TX: i'm unsure what the HW does if it will not found
2835 * the last fragment of a frame because it has been dropped...
2836 * Since queues for Management and Data frames are different we
2837 * might use a different lock than tx_lock (for example mgmt_tx_lock)
2839 /* these function may loops if invoked with 0 descriptors or 0 len buffer*/
2840 int rtl8180_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
2842 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2844 unsigned long flags;
2848 priority = MANAGE_PRIORITY;
2850 spin_lock_irqsave(&priv->tx_lock,flags);
2852 if(priv->ieee80211->bHwRadioOff)
2854 spin_unlock_irqrestore(&priv->tx_lock,flags);
2856 dev_kfree_skb_any(skb);
2857 return NETDEV_TX_OK;
2860 rtl8180_tx(dev, skb->data, skb->len, priority,
2861 0, 0,ieeerate2rtlrate(priv->ieee80211->basic_rate));
2863 priv->ieee80211->stats.tx_bytes+=skb->len;
2864 priv->ieee80211->stats.tx_packets++;
2865 spin_unlock_irqrestore(&priv->tx_lock,flags);
2867 dev_kfree_skb_any(skb);
2868 return NETDEV_TX_OK;
2871 // longpre 144+48 shortpre 72+24
2872 u16 rtl8180_len2duration(u32 len, short rate,short* ext)
2881 duration = ((len+4)<<4) /0x2;
2882 drift = ((len+4)<<4) % 0x2;
2883 if(drift ==0 ) break;
2889 duration = ((len+4)<<4) /0x4;
2890 drift = ((len+4)<<4) % 0x4;
2891 if(drift ==0 ) break;
2897 duration = ((len+4)<<4) /0xb;
2898 drift = ((len+4)<<4) % 0xb;
2907 duration = ((len+4)<<4) /0x16;
2908 drift = ((len+4)<<4) % 0x16;
2922 void rtl8180_prepare_beacon(struct net_device *dev)
2925 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2927 struct sk_buff *skb;
2929 u16 word = read_nic_word(dev, BcnItv);
2930 word &= ~BcnItv_BcnItv; // clear Bcn_Itv
2931 word |= cpu_to_le16(priv->ieee80211->current_network.beacon_interval);//0x64;
2932 write_nic_word(dev, BcnItv, word);
2935 skb = ieee80211_get_beacon(priv->ieee80211);
2937 rtl8180_tx(dev,skb->data,skb->len,BEACON_PRIORITY,
2938 0,0,ieeerate2rtlrate(priv->ieee80211->basic_rate));
2939 dev_kfree_skb_any(skb);
2942 //DMESG("size %x",len);
2943 if(*tail & (1<<31)){
2945 //DMESG("No more beacon TX desc");
2949 //while(! (*tail & (1<<31))){
2950 *tail= 0; // zeroes header
2952 *tail = *tail| (1<<29) ; //fist segment of the packet
2953 *tail = (*tail) | (1<<28); // last segment
2954 // *tail = *tail | (1<<18); // this is a beacon frame
2955 *(tail+3)=*(tail+3) &~ 0xfff;
2956 *(tail+3)=*(tail+3) | len; // buffer lenght
2958 // zeroes the second 32-bits dword of the descriptor
2960 *tail = *tail | (rate << 24);
2962 duration = rtl8180_len2duration(len,rate,&ext);
2964 *(tail+1) = *(tail+1) | ((duration & 0x7fff)<<16);
2966 *tail = *tail | (1<<31);
2967 //^ descriptor ready to be txed
2968 if((tail - begin)/8 == priv->txbeaconcount-1)
2976 /* This function do the real dirty work: it enqueues a TX command
2977 * descriptor in the ring buffer, copyes the frame in a TX buffer
2978 * and kicks the NIC to ensure it does the DMA transfer.
2980 short rtl8180_tx(struct net_device *dev, u8* txbuf, int len, int priority,
2981 short morefrag, short descfrag, int rate)
2983 struct r8180_priv *priv = ieee80211_priv(dev);
2984 u32 *tail,*temp_tail;
2995 struct buffer* buflist;
2996 //unsigned long flags;
2997 struct ieee80211_hdr_3addr *frag_hdr = (struct ieee80211_hdr_3addr *)txbuf;
2999 u8 bUseShortPreamble = 0;
3003 //u8 RetryLimit = 0;
3006 u16 ThisFrameTime = 0;
3007 u16 TxDescDuration = 0;
3008 u8 ownbit_flag = false; //added by david woo for sync Tx, 2007.12.14
3011 case MANAGE_PRIORITY:
3012 tail=priv->txmapringtail;
3013 begin=priv->txmapring;
3014 buflist = priv->txmapbufstail;
3015 count = priv->txringcount;
3019 tail=priv->txbkpringtail;
3020 begin=priv->txbkpring;
3021 buflist = priv->txbkpbufstail;
3022 count = priv->txringcount;
3026 tail=priv->txbepringtail;
3027 begin=priv->txbepring;
3028 buflist = priv->txbepbufstail;
3029 count = priv->txringcount;
3033 tail=priv->txvipringtail;
3034 begin=priv->txvipring;
3035 buflist = priv->txvipbufstail;
3036 count = priv->txringcount;
3040 tail=priv->txvopringtail;
3041 begin=priv->txvopring;
3042 buflist = priv->txvopbufstail;
3043 count = priv->txringcount;
3047 tail=priv->txhpringtail;
3048 begin=priv->txhpring;
3049 buflist = priv->txhpbufstail;
3050 count = priv->txringcount;
3053 case BEACON_PRIORITY:
3054 tail=priv->txbeaconringtail;
3055 begin=priv->txbeaconring;
3056 buflist = priv->txbeaconbufstail;
3057 count = priv->txbeaconcount;
3065 //printk("in rtl8180_tx(): rate is %d\n",priv->ieee80211->rate);
3067 memcpy(&dest, frag_hdr->addr1, ETH_ALEN);
3068 if (is_multicast_ether_addr(dest) ||
3069 is_broadcast_ether_addr(dest))
3076 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate), 0, bUseShortPreamble);
3077 TxDescDuration = ThisFrameTime;
3078 } else {// Unicast packet
3082 //YJ,add,080828,for Keep alive
3083 priv->NumTxUnicast++;
3085 // Figure out ACK rate according to BSS basic rate and Tx rate, 2006.03.08 by rcnjko.
3086 //AckRate = ComputeAckRate( pMgntInfo->mBrates, (u1Byte)(pTcb->DataRate) );
3087 // Figure out ACK time according to the AckRate and assume long preamble is used on receiver, 2006.03.08, by rcnjko.
3088 //AckTime = ComputeTxTime( sAckCtsLng/8, AckRate, FALSE, FALSE);
3089 //For simplicity, just use the 1M basic rate
3090 //AckTime = ComputeTxTime(14, 540,0, 0); // AckCTSLng = 14 use 1M bps send
3091 AckTime = ComputeTxTime(14, 10,0, 0); // AckCTSLng = 14 use 1M bps send
3092 //AckTime = ComputeTxTime(14, 2,false, false); // AckCTSLng = 14 use 1M bps send
3094 if ( ((len + sCrcLng) > priv->rts) && priv->rts )
3096 u16 RtsTime, CtsTime;
3101 // Rate and time required for RTS.
3102 RtsTime = ComputeTxTime( sAckCtsLng/8,priv->ieee80211->basic_rate, 0, 0);
3103 // Rate and time required for CTS.
3104 CtsTime = ComputeTxTime(14, 10,0, 0); // AckCTSLng = 14 use 1M bps send
3106 // Figure out time required to transmit this frame.
3107 ThisFrameTime = ComputeTxTime(len + sCrcLng,
3108 rtl8180_rate2rate(rate),
3112 // RTS-CTS-ThisFrame-ACK.
3113 RtsDur = CtsTime + ThisFrameTime + AckTime + 3*aSifsTime;
3115 TxDescDuration = RtsTime + RtsDur;
3117 else {// Normal case.
3122 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate), 0, bUseShortPreamble);
3123 TxDescDuration = ThisFrameTime + aSifsTime + AckTime;
3126 if(!(frag_hdr->frame_ctl & IEEE80211_FCTL_MOREFRAGS)) { //no more fragment
3128 Duration = aSifsTime + AckTime;
3129 } else { // One or more fragments remained.
3131 NextFragTime = ComputeTxTime( len + sCrcLng, //pretend following packet length equal current packet
3132 rtl8180_rate2rate(rate),
3134 bUseShortPreamble );
3136 //ThisFrag-ACk-NextFrag-ACK.
3137 Duration = NextFragTime + 3*aSifsTime + 2*AckTime;
3140 } // End of Unicast packet
3142 frag_hdr->duration_id = Duration;
3145 buflen=priv->txbuffsize;
3148 //printk("================================>buflen = %d, remain = %d!\n", buflen,remain);
3150 #ifdef DEBUG_TX_FRAG
3151 DMESG("TX iteration");
3154 DMESG("TX: filling descriptor %x",(u32)tail);
3158 DMESGE("TX buffer error, cannot TX frames. pri %d.", priority);
3159 //spin_unlock_irqrestore(&priv->tx_lock,flags);
3164 if( (*tail & (1<<31)) && (priority != BEACON_PRIORITY)){
3166 DMESGW("No more TX desc, returning %x of %x",
3168 priv->stats.txrdu++;
3169 #ifdef DEBUG_TX_DESC
3170 check_tx_ring(dev,priority);
3171 // netif_stop_queue(dev);
3172 // netif_carrier_off(dev);
3174 // spin_unlock_irqrestore(&priv->tx_lock,flags);
3180 *tail= 0; // zeroes header
3187 if(priv->card_8185){
3188 //FIXME: this should be triggered by HW encryption parameters.
3189 *tail |= (1<<15); //no encrypt
3190 // *tail |= (1<<30); //raise int when completed
3192 // *tail = *tail | (1<<16);
3193 if(remain==len && !descfrag) {
3194 ownbit_flag = false; //added by david woo,2007.12.14
3195 #ifdef DEBUG_TX_FRAG
3196 DMESG("First descriptor");
3198 *tail = *tail| (1<<29) ; //fist segment of the packet
3199 *tail = *tail |(len);
3204 for(i=0;i<buflen&& remain >0;i++,remain--){
3205 ((u8*)buf)[i]=txbuf[i]; //copy data into descriptor pointed DMAble buffer
3206 if(remain == 4 && i+4 >= buflen) break;
3207 /* ensure the last desc has at least 4 bytes payload */
3211 *(tail+3)=*(tail+3) &~ 0xfff;
3212 *(tail+3)=*(tail+3) | i; // buffer lenght
3213 // Use short preamble or not
3214 if (priv->ieee80211->current_network.capability&WLAN_CAPABILITY_SHORT_PREAMBLE)
3215 if (priv->plcp_preamble_mode==1 && rate!=0) // short mode now, not long!
3216 // *tail |= (1<<16); // enable short preamble mode.
3222 if(bRTSEnable) //rts enable
3224 *tail |= ((ieeerate2rtlrate(priv->ieee80211->basic_rate))<<19);//RTS RATE
3225 *tail |= (1<<23);//rts enable
3226 *(tail+1) |=(RtsDur&0xffff);//RTS Duration
3228 *(tail+3) |= ((TxDescDuration&0xffff)<<16); //DURATION
3229 // *(tail+3) |= (0xe6<<16);
3230 *(tail+5) |= (11<<8);//(priv->retry_data<<8); //retry lim ;
3232 *tail = *tail | ((rate&0xf) << 24);
3233 //DMESG("rate %d",rate);
3235 if(priv->card_8185){
3238 *(tail+5)&= ~(1<<24); /* tx ant 0 */
3240 *(tail+5) &= ~(1<<23); /* random tx agc 23-16 */
3241 *(tail+5) |= (1<<22)|(1<<21)|(1<<20)|(1<<19)|(1<<18)|(1<<17)|(1<<16);
3244 ~((1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(1<<10)|(1<<9)|(1<<8));
3245 *(tail+5) |= (7<<8); // Max retry limit
3247 *(tail+5) &= ~((1<<7)|(1<<6)|(1<<5)|(1<<4)|(1<<3)|(1<<2)|(1<<1)|(1<<0));
3248 *(tail+5) |= (8<<4); // Max contention window
3249 *(tail+6) |= 4; // Min contention window
3254 /* hw_plcp_len is not used for rtl8180 chip */
3256 if(priv->card_8185 == 0 || !priv->hw_plcp_len){
3258 duration = rtl8180_len2duration(len,
3263 DMESG("PLCP duration %d",duration );
3264 //DMESG("drift %d",drift);
3265 DMESG("extension %s", (ext==1) ? "on":"off");
3267 *(tail+1) = *(tail+1) | ((duration & 0x7fff)<<16);
3268 if(ext) *(tail+1) = *(tail+1) |(1<<31); //plcp length extension
3271 if(morefrag) *tail = (*tail) | (1<<17); // more fragment
3272 if(!remain) *tail = (*tail) | (1<<28); // last segment of frame
3274 #ifdef DEBUG_TX_FRAG
3275 if(!remain)DMESG("Last descriptor");
3276 if(morefrag)DMESG("More frag");
3278 *(tail+5) = *(tail+5)|(2<<27);
3279 *(tail+7) = *(tail+7)|(1<<4);
3284 *tail = *tail | (1<<31); // descriptor ready to be txed
3287 #ifdef DEBUG_TX_DESC2
3288 printk("tx desc is:\n");
3289 DMESG("%8x %8x %8x %8x %8x %8x %8x %8x", tail[0], tail[1], tail[2], tail[3],
3290 tail[4], tail[5], tail[6], tail[7]);
3293 if((tail - begin)/8 == count-1)
3299 buflist=buflist->next;
3304 case MANAGE_PRIORITY:
3305 priv->txmapringtail=tail;
3306 priv->txmapbufstail=buflist;
3310 priv->txbkpringtail=tail;
3311 priv->txbkpbufstail=buflist;
3315 priv->txbepringtail=tail;
3316 priv->txbepbufstail=buflist;
3320 priv->txvipringtail=tail;
3321 priv->txvipbufstail=buflist;
3325 priv->txvopringtail=tail;
3326 priv->txvopbufstail=buflist;
3330 priv->txhpringtail=tail;
3331 priv->txhpbufstail = buflist;
3334 case BEACON_PRIORITY:
3335 /* the HW seems to be happy with the 1st
3336 * descriptor filled and the 2nd empty...
3337 * So always update descriptor 1 and never
3340 // priv->txbeaconringtail=tail;
3341 // priv->txbeaconbufstail=buflist;
3347 //rtl8180_dma_kick(dev,priority);
3349 *temp_tail = *temp_tail | (1<<31); // descriptor ready to be txed
3350 rtl8180_dma_kick(dev,priority);
3351 //spin_unlock_irqrestore(&priv->tx_lock,flags);
3358 void rtl8180_irq_rx_tasklet(struct r8180_priv * priv);
3361 void rtl8180_link_change(struct net_device *dev)
3363 struct r8180_priv *priv = ieee80211_priv(dev);
3364 u16 beacon_interval;
3366 struct ieee80211_network *net = &priv->ieee80211->current_network;
3367 // rtl8180_adapter_start(dev);
3368 rtl8180_update_msr(dev);
3371 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
3373 write_nic_dword(dev,BSSID,((u32*)net->bssid)[0]);
3374 write_nic_word(dev,BSSID+4,((u16*)net->bssid)[2]);
3377 beacon_interval = read_nic_dword(dev,BEACON_INTERVAL);
3378 beacon_interval &= ~ BEACON_INTERVAL_MASK;
3379 beacon_interval |= net->beacon_interval;
3380 write_nic_dword(dev, BEACON_INTERVAL, beacon_interval);
3382 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
3386 u16 atim = read_nic_dword(dev,ATIM);
3387 u16 = u16 &~ ATIM_MASK;
3388 u16 = u16 | beacon->atim;
3391 if (net->capability & WLAN_CAPABILITY_PRIVACY) {
3393 DMESG("Enabling hardware WEP support");
3394 rtl8180_set_hw_wep(dev);
3395 priv->ieee80211->host_encrypt=0;
3396 priv->ieee80211->host_decrypt=0;
3398 #ifndef CONFIG_IEEE80211_NOWEP
3400 priv->ieee80211->host_encrypt=1;
3401 priv->ieee80211->host_decrypt=1;
3405 #ifndef CONFIG_IEEE80211_NOWEP
3407 priv->ieee80211->host_encrypt=0;
3408 priv->ieee80211->host_decrypt=0;
3415 rtl8180_set_chan(dev, priv->chan);
3420 void rtl8180_rq_tx_ack(struct net_device *dev){
3422 struct r8180_priv *priv = ieee80211_priv(dev);
3423 // printk("====================>%s\n",__func__);
3424 write_nic_byte(dev,CONFIG4,read_nic_byte(dev,CONFIG4)|CONFIG4_PWRMGT);
3425 priv->ack_tx_to_ieee = 1;
3428 short rtl8180_is_tx_queue_empty(struct net_device *dev){
3430 struct r8180_priv *priv = ieee80211_priv(dev);
3433 for (d = priv->txmapring;
3434 d < priv->txmapring + priv->txringcount;d+=8)
3435 if(*d & (1<<31)) return 0;
3437 for (d = priv->txbkpring;
3438 d < priv->txbkpring + priv->txringcount;d+=8)
3439 if(*d & (1<<31)) return 0;
3441 for (d = priv->txbepring;
3442 d < priv->txbepring + priv->txringcount;d+=8)
3443 if(*d & (1<<31)) return 0;
3445 for (d = priv->txvipring;
3446 d < priv->txvipring + priv->txringcount;d+=8)
3447 if(*d & (1<<31)) return 0;
3449 for (d = priv->txvopring;
3450 d < priv->txvopring + priv->txringcount;d+=8)
3451 if(*d & (1<<31)) return 0;
3453 for (d = priv->txhpring;
3454 d < priv->txhpring + priv->txringcount;d+=8)
3455 if(*d & (1<<31)) return 0;
3458 /* FIXME FIXME 5msecs is random */
3459 #define HW_WAKE_DELAY 5
3461 void rtl8180_hw_wakeup(struct net_device *dev)
3463 unsigned long flags;
3465 struct r8180_priv *priv = ieee80211_priv(dev);
3467 spin_lock_irqsave(&priv->ps_lock,flags);
3468 //DMESG("Waken up!");
3469 write_nic_byte(dev,CONFIG4,read_nic_byte(dev,CONFIG4)&~CONFIG4_PWRMGT);
3472 priv->rf_wakeup(dev);
3473 // mdelay(HW_WAKE_DELAY);
3474 spin_unlock_irqrestore(&priv->ps_lock,flags);
3477 void rtl8180_hw_sleep_down(struct net_device *dev)
3479 unsigned long flags;
3481 struct r8180_priv *priv = ieee80211_priv(dev);
3483 spin_lock_irqsave(&priv->ps_lock,flags);
3487 priv->rf_sleep(dev);
3488 spin_unlock_irqrestore(&priv->ps_lock,flags);
3492 void rtl8180_hw_sleep(struct net_device *dev, u32 th, u32 tl)
3495 struct r8180_priv *priv = ieee80211_priv(dev);
3498 unsigned long flags;
3500 spin_lock_irqsave(&priv->ps_lock,flags);
3502 /* Writing HW register with 0 equals to disable
3503 * the timer, that is not really what we want
3505 tl -= MSECS(4+16+7);
3507 //if(tl == 0) tl = 1;
3509 /* FIXME HACK FIXME HACK */
3510 // force_pci_posting(dev);
3513 // rb = read_nic_dword(dev, TSFTR);
3515 /* If the interval in witch we are requested to sleep is too
3516 * short then give up and remain awake
3518 if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME))
3519 ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
3520 spin_unlock_irqrestore(&priv->ps_lock,flags);
3521 printk("too short to sleep\n");
3525 // write_nic_dword(dev, TimerInt, tl);
3526 // rb = read_nic_dword(dev, TSFTR);
3528 u32 tmp = (tl>rb)?(tl-rb):(rb-tl);
3532 priv->DozePeriodInPast2Sec += jiffies_to_msecs(tmp);
3534 queue_delayed_work(priv->ieee80211->wq, &priv->ieee80211->hw_wakeup_wq, tmp); //as tl may be less than rb
3536 /* if we suspect the TimerInt is gone beyond tl
3537 * while setting it, then give up
3540 if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))||
3541 ((tl < rb) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))) {
3542 spin_unlock_irqrestore(&priv->ps_lock,flags);
3546 // if(priv->rf_sleep)
3547 // priv->rf_sleep(dev);
3549 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_sleep_wq);
3550 spin_unlock_irqrestore(&priv->ps_lock,flags);
3554 //void rtl8180_wmm_param_update(struct net_device *dev,u8 *ac_param)
3555 void rtl8180_wmm_param_update(struct work_struct * work)
3557 struct ieee80211_device * ieee = container_of(work, struct ieee80211_device,wmm_param_update_wq);
3558 //struct r8180_priv *priv = (struct r8180_priv*)(ieee->priv);
3559 struct net_device *dev = ieee->dev;
3560 u8 *ac_param = (u8 *)(ieee->current_network.wmm_param);
3561 u8 mode = ieee->current_network.mode;
3567 if(!ieee->current_network.QoS_Enable){
3568 //legacy ac_xx_param update
3569 AcParam.longData = 0;
3570 AcParam.f.AciAifsn.f.AIFSN = 2; // Follow 802.11 DIFS.
3571 AcParam.f.AciAifsn.f.ACM = 0;
3572 AcParam.f.Ecw.f.ECWmin = 3; // Follow 802.11 CWmin.
3573 AcParam.f.Ecw.f.ECWmax = 7; // Follow 802.11 CWmax.
3574 AcParam.f.TXOPLimit = 0;
3575 for(eACI = 0; eACI < AC_MAX; eACI++){
3576 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
3580 pAcParam = (PAC_PARAM)(&AcParam);
3581 // Retrive paramters to udpate.
3582 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN *(((mode&IEEE_G) == IEEE_G)?9:20) + aSifsTime;
3583 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit))<<AC_PARAM_TXOP_LIMIT_OFFSET)|
3584 (((u32)(pAcParam->f.Ecw.f.ECWmax))<<AC_PARAM_ECW_MAX_OFFSET)|
3585 (((u32)(pAcParam->f.Ecw.f.ECWmin))<<AC_PARAM_ECW_MIN_OFFSET)|
3586 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
3589 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
3593 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
3597 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
3601 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
3605 printk(KERN_WARNING "SetHwReg8185():invalid ACI: %d!\n", eACI);
3613 for(i = 0; i < AC_MAX; i++){
3614 //AcParam.longData = 0;
3615 pAcParam = (AC_PARAM * )ac_param;
3621 // Retrive paramters to udpate.
3622 eACI = pAcParam->f.AciAifsn.f.ACI;
3623 //Mode G/A: slotTimeTimer = 9; Mode B: 20
3624 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G)?9:20) + aSifsTime;
3625 u4bAcParam = ( (((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
3626 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
3627 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
3628 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
3632 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
3636 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
3640 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
3644 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
3648 printk(KERN_WARNING "SetHwReg8185(): invalid ACI: %d !\n", eACI);
3652 ac_param += (sizeof(AC_PARAM));
3656 void rtl8180_tx_irq_wq(struct work_struct *work);
3657 void rtl8180_restart_wq(struct work_struct *work);
3658 //void rtl8180_rq_tx_ack(struct work_struct *work);
3659 void rtl8180_watch_dog_wq(struct work_struct *work);
3660 void rtl8180_hw_wakeup_wq(struct work_struct *work);
3661 void rtl8180_hw_sleep_wq(struct work_struct *work);
3662 void rtl8180_sw_antenna_wq(struct work_struct *work);
3663 void rtl8180_watch_dog(struct net_device *dev);
3665 void watch_dog_adaptive(unsigned long data)
3667 struct r8180_priv* priv = ieee80211_priv((struct net_device *)data);
3668 // DMESG("---->watch_dog_adaptive()\n");
3671 DMESG("<----watch_dog_adaptive():driver is not up!\n");
3675 // queue_work(priv->ieee80211->wq,&priv->ieee80211->watch_dog_wq);
3678 // Tx High Power Mechanism.
3680 if(CheckHighPower((struct net_device *)data))
3682 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->tx_pw_wq);
3686 // Tx Power Tracking on 87SE.
3688 //if( priv->bTxPowerTrack ) //lzm mod 080826
3689 if( CheckTxPwrTracking((struct net_device *)data));
3690 TxPwrTracking87SE((struct net_device *)data);
3693 // Perform DIG immediately.
3695 if(CheckDig((struct net_device *)data) == true)
3697 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_dig_wq);
3702 rtl8180_watch_dog((struct net_device *)data);
3705 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->GPIOChangeRFWorkItem);
3707 priv->watch_dog_timer.expires = jiffies + MSECS(IEEE80211_WATCH_DOG_TIME);
3708 add_timer(&priv->watch_dog_timer);
3709 // DMESG("<----watch_dog_adaptive()\n");
3713 static CHANNEL_LIST ChannelPlan[] = {
3714 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64},19}, //FCC
3715 {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC
3716 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI
3717 {{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.
3718 {{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.
3719 {{14,36,40,44,48,52,56,60,64},9}, //MKK
3720 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14, 36,40,44,48,52,56,60,64},22},//MKK1
3721 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //Israel.
3722 {{1,2,3,4,5,6,7,8,9,10,11,12,13,34,38,42,46},17}, // For 11a , TELEC
3723 {{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
3724 {{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
3727 static void rtl8180_set_channel_map(u8 channel_plan, struct ieee80211_device *ieee)
3732 ieee->MinPassiveChnlNum=MAX_CHANNEL_NUMBER+1;
3733 ieee->IbssStartChnl=0;
3735 switch (channel_plan)
3737 case COUNTRY_CODE_FCC:
3738 case COUNTRY_CODE_IC:
3739 case COUNTRY_CODE_ETSI:
3740 case COUNTRY_CODE_SPAIN:
3741 case COUNTRY_CODE_FRANCE:
3742 case COUNTRY_CODE_MKK:
3743 case COUNTRY_CODE_MKK1:
3744 case COUNTRY_CODE_ISRAEL:
3745 case COUNTRY_CODE_TELEC:
3748 ieee->bGlobalDomain = false;
3749 if (ChannelPlan[channel_plan].Len != 0){
3750 // Clear old channel map
3751 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
3752 // Set new channel map
3753 for (i=0;i<ChannelPlan[channel_plan].Len;i++)
3755 if(ChannelPlan[channel_plan].Channel[i] <= 14)
3756 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
3761 case COUNTRY_CODE_GLOBAL_DOMAIN:
3763 GET_DOT11D_INFO(ieee)->bEnabled = 0;
3765 ieee->bGlobalDomain = true;
3768 case COUNTRY_CODE_WORLD_WIDE_13_INDEX://lzm add 080826
3770 ieee->MinPassiveChnlNum=12;
3771 ieee->IbssStartChnl= 10;
3777 ieee->bGlobalDomain = false;
3778 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
3781 GET_DOT11D_INFO(ieee)->channel_map[i] = 1;
3788 //Add for RF power on power off by lizhaoming 080512
3789 void GPIOChangeRFWorkItemCallBack(struct work_struct *work);
3792 static void rtl8180_statistics_init(struct Stats *pstats)
3794 memset(pstats, 0, sizeof(struct Stats));
3796 static void rtl8180_link_detect_init(plink_detect_t plink_detect)
3798 memset(plink_detect, 0, sizeof(link_detect_t));
3799 plink_detect->SlotNum = DEFAULT_SLOT_NUM;
3803 short rtl8180_init(struct net_device *dev)
3805 struct r8180_priv *priv = ieee80211_priv(dev);
3815 for(i=0;i<0xFF;i++) {
3817 printk("\n[%x]: ", i/16);
3818 printk("\t%4.4x", eprom_read(dev,i));
3821 priv->channel_plan = eprom_read(dev, EEPROM_COUNTRY_CODE>>1) & 0xFF;
3822 if(priv->channel_plan > COUNTRY_CODE_GLOBAL_DOMAIN){
3823 printk("rtl8180_init:Error channel plan! Set to default.\n");
3824 priv->channel_plan = 0;
3826 //priv->channel_plan = 9; //Global Domain
3828 DMESG("Channel plan is %d\n",priv->channel_plan);
3829 rtl8180_set_channel_map(priv->channel_plan, priv->ieee80211);
3831 //memcpy(priv->stats,0,sizeof(struct Stats));
3833 //FIXME: these constants are placed in a bad pleace.
3834 priv->txbuffsize = 2048;//1024;
3835 priv->txringcount = 32;//32;
3836 priv->rxbuffersize = 2048;//1024;
3837 priv->rxringcount = 64;//32;
3838 priv->txbeaconcount = 2;
3839 priv->rx_skb_complete = 1;
3840 //priv->txnp_pending.ispending=0;
3841 /* ^^ the SKB does not containt a partial RXed
3845 priv->RegThreeWireMode = HW_THREE_WIRE_SI;
3847 //Add for RF power on power off by lizhaoming 080512
3848 priv->RFChangeInProgress = false;
3849 priv->SetRFPowerStateInProgress = false;
3850 priv->RFProgType = 0;
3851 priv->bInHctTest = false;
3853 priv->irq_enabled=0;
3855 //YJ,modified,080828
3857 priv->stats.rxdmafail=0;
3858 priv->stats.txrdu=0;
3859 priv->stats.rxrdu=0;
3860 priv->stats.rxnolast=0;
3861 priv->stats.rxnodata=0;
3862 //priv->stats.rxreset=0;
3863 //priv->stats.rxwrkaround=0;
3864 priv->stats.rxnopointer=0;
3865 priv->stats.txnperr=0;
3866 priv->stats.txresumed=0;
3867 priv->stats.rxerr=0;
3868 priv->stats.rxoverflow=0;
3869 priv->stats.rxint=0;
3870 priv->stats.txnpokint=0;
3871 priv->stats.txhpokint=0;
3872 priv->stats.txhperr=0;
3874 priv->stats.shints=0;
3875 priv->stats.txoverflow=0;
3876 priv->stats.txbeacon=0;
3877 priv->stats.txbeaconerr=0;
3878 priv->stats.txlperr=0;
3879 priv->stats.txlpokint=0;
3880 priv->stats.txretry=0;//tony 20060601
3881 priv->stats.rxcrcerrmin=0;
3882 priv->stats.rxcrcerrmid=0;
3883 priv->stats.rxcrcerrmax=0;
3884 priv->stats.rxicverr=0;
3886 rtl8180_statistics_init(&priv->stats);
3887 rtl8180_link_detect_init(&priv->link_detect);
3889 //YJ,modified,080828,end
3892 priv->ack_tx_to_ieee = 0;
3893 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
3894 priv->ieee80211->iw_mode = IW_MODE_INFRA;
3895 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
3896 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
3897 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;
3898 priv->ieee80211->active_scan = 1;
3899 priv->ieee80211->rate = 110; //11 mbps
3900 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION;
3901 priv->ieee80211->host_encrypt = 1;
3902 priv->ieee80211->host_decrypt = 1;
3903 priv->ieee80211->sta_wake_up = rtl8180_hw_wakeup;
3904 priv->ieee80211->ps_request_tx_ack = rtl8180_rq_tx_ack;
3905 priv->ieee80211->enter_sleep_state = rtl8180_hw_sleep;
3906 priv->ieee80211->ps_is_queue_empty = rtl8180_is_tx_queue_empty;
3908 priv->hw_wep = hwwep;
3911 priv->retry_rts = DEFAULT_RETRY_RTS;
3912 priv->retry_data = DEFAULT_RETRY_DATA;
3913 priv->RFChangeInProgress = false;
3914 priv->SetRFPowerStateInProgress = false;
3915 priv->RFProgType = 0;
3916 priv->bInHctTest = false;
3917 priv->bInactivePs = true;//false;
3918 priv->ieee80211->bInactivePs = priv->bInactivePs;
3919 priv->bSwRfProcessing = false;
3920 priv->eRFPowerState = eRfOff;
3921 priv->RfOffReason = 0;
3922 priv->LedStrategy = SW_LED_MODE0;
3923 //priv->NumRxOkInPeriod = 0; //YJ,del,080828
3924 //priv->NumTxOkInPeriod = 0; //YJ,del,080828
3925 priv->TxPollingTimes = 0;//lzm add 080826
3926 priv->bLeisurePs = true;
3927 priv->dot11PowerSaveMode = eActive;
3928 //by amy for antenna
3929 priv->AdMinCheckPeriod = 5;
3930 priv->AdMaxCheckPeriod = 10;
3931 // Lower signal strength threshold to fit the HW participation in antenna diversity. +by amy 080312
3932 priv->AdMaxRxSsThreshold = 30;//60->30
3933 priv->AdRxSsThreshold = 20;//50->20
3934 priv->AdCheckPeriod = priv->AdMinCheckPeriod;
3935 priv->AdTickCount = 0;
3936 priv->AdRxSignalStrength = -1;
3937 priv->RegSwAntennaDiversityMechanism = 0;
3938 priv->RegDefaultAntenna = 0;
3939 priv->SignalStrength = 0;
3940 priv->AdRxOkCnt = 0;
3941 priv->CurrAntennaIndex = 0;
3942 priv->AdRxSsBeforeSwitched = 0;
3943 init_timer(&priv->SwAntennaDiversityTimer);
3944 priv->SwAntennaDiversityTimer.data = (unsigned long)dev;
3945 priv->SwAntennaDiversityTimer.function = (void *)SwAntennaDiversityTimerCallback;
3946 //by amy for antenna
3948 priv->bDigMechanism = 1;
3949 priv->InitialGain = 6;
3950 priv->bXtalCalibration = false;
3951 priv->XtalCal_Xin = 0;
3952 priv->XtalCal_Xout = 0;
3953 priv->bTxPowerTrack = false;
3954 priv->ThermalMeter = 0;
3955 priv->FalseAlarmRegValue = 0;
3956 priv->RegDigOfdmFaUpTh = 0xc; // Upper threhold of OFDM false alarm, which is used in DIG.
3957 priv->DIG_NumberFallbackVote = 0;
3958 priv->DIG_NumberUpgradeVote = 0;
3959 priv->LastSignalStrengthInPercent = 0;
3960 priv->Stats_SignalStrength = 0;
3961 priv->LastRxPktAntenna = 0;
3962 priv->SignalQuality = 0; // in 0-100 index.
3963 priv->Stats_SignalQuality = 0;
3964 priv->RecvSignalPower = 0; // in dBm.
3965 priv->Stats_RecvSignalPower = 0;
3966 priv->AdMainAntennaRxOkCnt = 0;
3967 priv->AdAuxAntennaRxOkCnt = 0;
3968 priv->bHWAdSwitched = false;
3969 priv->bRegHighPowerMechanism = true;
3970 priv->RegHiPwrUpperTh = 77;
3971 priv->RegHiPwrLowerTh = 75;
3972 priv->RegRSSIHiPwrUpperTh = 70;
3973 priv->RegRSSIHiPwrLowerTh = 20;
3974 priv->bCurCCKPkt = false;
3975 priv->UndecoratedSmoothedSS = -1;
3976 priv->bToUpdateTxPwr = false;
3977 priv->CurCCKRSSI = 0;
3981 priv->NumTxOkTotal = 0;
3982 priv->NumTxUnicast = 0;
3983 priv->keepAliveLevel = DEFAULT_KEEP_ALIVE_LEVEL;
3984 priv->PowerProfile = POWER_PROFILE_AC;
3986 //by amy for rate adaptive
3987 priv->CurrRetryCnt=0;
3988 priv->LastRetryCnt=0;
3989 priv->LastTxokCnt=0;
3990 priv->LastRxokCnt=0;
3991 priv->LastRetryRate=0;
3994 priv->CurrRetryRate=0;
3995 priv->TryupingCount=0;
3996 priv->TryupingCountNoData=0;
3997 priv->TryDownCountLowData=0;
3998 priv->LastTxOKBytes=0;
3999 priv->LastFailTxRate=0;
4000 priv->LastFailTxRateSS=0;
4001 priv->FailTxRateCount=0;
4002 priv->LastTxThroughput=0;
4003 priv->NumTxOkBytesTotal=0;
4004 priv->ForcedDataRate = 0;
4005 priv->RegBModeGainStage = 1;
4007 //by amy for rate adaptive
4009 priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
4010 spin_lock_init(&priv->irq_lock);
4011 spin_lock_init(&priv->irq_th_lock);
4012 spin_lock_init(&priv->tx_lock);
4013 spin_lock_init(&priv->ps_lock);
4014 spin_lock_init(&priv->rf_ps_lock);
4015 sema_init(&priv->wx_sem,1);
4016 sema_init(&priv->rf_state,1);
4017 INIT_WORK(&priv->reset_wq,(void*) rtl8180_restart_wq);
4018 INIT_WORK(&priv->tx_irq_wq,(void*) rtl8180_tx_irq_wq);
4019 INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8180_hw_wakeup_wq);
4020 INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8180_hw_sleep_wq);
4021 //INIT_DELAYED_WORK(&priv->ieee80211->watch_dog_wq,(void*) rtl8180_watch_dog_wq);
4022 //INIT_DELAYED_WORK(&priv->ieee80211->sw_antenna_wq,(void*) rtl8180_sw_antenna_wq);
4023 INIT_WORK(&priv->ieee80211->wmm_param_update_wq,(void*) rtl8180_wmm_param_update);
4024 INIT_DELAYED_WORK(&priv->ieee80211->rate_adapter_wq,(void*)rtl8180_rate_adapter);//+by amy 080312
4025 INIT_DELAYED_WORK(&priv->ieee80211->hw_dig_wq,(void*)rtl8180_hw_dig_wq);//+by amy 080312
4026 INIT_DELAYED_WORK(&priv->ieee80211->tx_pw_wq,(void*)rtl8180_tx_pw_wq);//+by amy 080312
4028 //add for RF power on power off by lizhaoming 080512
4029 INIT_DELAYED_WORK(&priv->ieee80211->GPIOChangeRFWorkItem,(void*) GPIOChangeRFWorkItemCallBack);
4030 //INIT_WORK(&priv->reset_wq,(void*) rtl8180_restart_wq,dev);
4032 tasklet_init(&priv->irq_rx_tasklet,
4033 (void(*)(unsigned long)) rtl8180_irq_rx_tasklet,
4034 (unsigned long)priv);
4036 init_timer(&priv->watch_dog_timer);
4037 priv->watch_dog_timer.data = (unsigned long)dev;
4038 priv->watch_dog_timer.function = watch_dog_adaptive;
4042 //by amy for rate adaptive
4043 init_timer(&priv->rateadapter_timer);
4044 priv->rateadapter_timer.data = (unsigned long)dev;
4045 priv->rateadapter_timer.function = timer_rate_adaptive;
4046 priv->RateAdaptivePeriod= RATE_ADAPTIVE_TIMER_PERIOD;
4047 priv->bEnhanceTxPwr=false;
4048 //by amy for rate adaptive
4050 //priv->ieee80211->func =
4051 // kmalloc(sizeof(struct ieee80211_helper_functions),GFP_KERNEL);
4052 //memset(priv->ieee80211->func, 0,
4053 // sizeof(struct ieee80211_helper_functions));
4055 priv->ieee80211->softmac_hard_start_xmit = rtl8180_hard_start_xmit;
4056 priv->ieee80211->set_chan = rtl8180_set_chan;
4057 priv->ieee80211->link_change = rtl8180_link_change;
4058 priv->ieee80211->softmac_data_hard_start_xmit = rtl8180_hard_data_xmit;
4059 priv->ieee80211->data_hard_stop = rtl8180_data_hard_stop;
4060 priv->ieee80211->data_hard_resume = rtl8180_data_hard_resume;
4062 priv->ieee80211->init_wmmparam_flag = 0;
4064 priv->ieee80211->start_send_beacons = rtl8180_start_tx_beacon;
4065 priv->ieee80211->stop_send_beacons = rtl8180_beacon_tx_disable;
4066 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
4068 priv->MWIEnable = 0;
4070 priv->ShortRetryLimit = 7;
4071 priv->LongRetryLimit = 7;
4072 priv->EarlyRxThreshold = 7;
4074 priv->CSMethod = (0x01 << 29);
4076 priv->TransmitConfig =
4077 1<<TCR_DurProcMode_OFFSET | //for RTL8185B, duration setting by HW
4078 (7<<TCR_MXDMA_OFFSET) | // Max DMA Burst Size per Tx DMA Burst, 7: reservied.
4079 (priv->ShortRetryLimit<<TCR_SRL_OFFSET) | // Short retry limit
4080 (priv->LongRetryLimit<<TCR_LRL_OFFSET) | // Long retry limit
4081 (0 ? TCR_SAT : 0); // FALSE: HW provies PLCP length and LENGEXT, TURE: SW proiveds them
4083 priv->ReceiveConfig =
4085 RCR_AMF | RCR_ADF | //accept management/data
4086 RCR_ACF | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko.
4087 RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC
4088 //RCR_AICV | RCR_ACRC32 | //accept ICV/CRC error packet
4089 (7<<RCR_MXDMA_OFFSET) | // Max DMA Burst Size per Rx DMA Burst, 7: unlimited.
4090 (priv->EarlyRxThreshold<<RCR_FIFO_OFFSET) | // Rx FIFO Threshold, 7: No Rx threshold.
4091 (priv->EarlyRxThreshold == 7 ? RCR_ONLYERLPKT:0);
4093 priv->IntrMask = IMR_TMGDOK | IMR_TBDER | IMR_THPDER |
4094 IMR_THPDER | IMR_THPDOK |
4095 IMR_TVODER | IMR_TVODOK |
4096 IMR_TVIDER | IMR_TVIDOK |
4097 IMR_TBEDER | IMR_TBEDOK |
4098 IMR_TBKDER | IMR_TBKDOK |
4099 IMR_RDU | // To handle the defragmentation not enough Rx descriptors case. Annie, 2006-03-27.
4101 IMR_RQoSOK; // <NOTE> ROK and RQoSOK are mutually exclusive, so, we must handle RQoSOK interrupt to receive QoS frames, 2005.12.09, by rcnjko.
4103 priv->InitialGain = 6;
4105 hw_version =( read_nic_dword(dev, TCR) & TCR_HWVERID_MASK)>>TCR_HWVERID_SHIFT;
4107 switch (hw_version){
4108 case HW_VERID_R8185B_B:
4109 priv->card_8185 = VERSION_8187S_C;
4110 DMESG("MAC controller is a RTL8187SE b/g");
4113 case HW_VERID_R8185_ABC:
4114 DMESG("MAC controller is a RTL8185 b/g");
4115 priv->card_8185 = 1;
4116 /* you should not find a card with 8225 PHY ver < C*/
4120 case HW_VERID_R8185_D:
4121 DMESG("MAC controller is a RTL8185 b/g (V. D)");
4122 priv->card_8185 = 2;
4123 /* you should not find a card with 8225 PHY ver < C*/
4127 case HW_VERID_R8180_ABCD:
4128 DMESG("MAC controller is a RTL8180");
4129 priv->card_8185 = 0;
4132 case HW_VERID_R8180_F:
4133 DMESG("MAC controller is a RTL8180 (v. F)");
4134 priv->card_8185 = 0;
4138 DMESGW("MAC chip not recognized: version %x. Assuming RTL8180",hw_version);
4139 priv->card_8185 = 0;
4143 if(priv->card_8185){
4144 priv->ieee80211->modulation |= IEEE80211_OFDM_MODULATION;
4145 priv->ieee80211->short_slot = 1;
4147 /* you should not found any 8185 Ver B Card */
4148 priv->card_8185_Bversion = 0;
4151 priv->card_type = PCI;
4152 DMESG("This is a PCI NIC");
4153 priv->enable_gpio0 = 0;
4155 //by amy for antenna
4156 usValue = eprom_read(dev, EEPROM_SW_REVD_OFFSET);
4157 DMESG("usValue is 0x%x\n",usValue);
4158 //3Read AntennaDiversity
4159 // SW Antenna Diversity.
4160 if( (usValue & EEPROM_SW_AD_MASK) != EEPROM_SW_AD_ENABLE )
4162 priv->EEPROMSwAntennaDiversity = false;
4163 //printk("EEPROM Disable SW Antenna Diversity\n");
4167 priv->EEPROMSwAntennaDiversity = true;
4168 //printk("EEPROM Enable SW Antenna Diversity\n");
4170 // Default Antenna to use.
4171 if( (usValue & EEPROM_DEF_ANT_MASK) != EEPROM_DEF_ANT_1 )
4173 priv->EEPROMDefaultAntenna1 = false;
4174 //printk("EEPROM Default Antenna 0\n");
4178 priv->EEPROMDefaultAntenna1 = true;
4179 //printk("EEPROM Default Antenna 1\n");
4183 // Antenna diversity mechanism. Added by Roger, 2007.11.05.
4185 if( priv->RegSwAntennaDiversityMechanism == 0 ) // Auto
4186 {// 0: default from EEPROM.
4187 priv->bSwAntennaDiverity = priv->EEPROMSwAntennaDiversity;
4190 {// 1:disable antenna diversity, 2: enable antenna diversity.
4191 priv->bSwAntennaDiverity = ((priv->RegSwAntennaDiversityMechanism == 1)? false : true);
4193 //printk("bSwAntennaDiverity = %d\n", priv->bSwAntennaDiverity);
4197 // Default antenna settings. Added by Roger, 2007.11.05.
4199 if( priv->RegDefaultAntenna == 0)
4200 {// 0: default from EEPROM.
4201 priv->bDefaultAntenna1 = priv->EEPROMDefaultAntenna1;
4204 {// 1: main, 2: aux.
4205 priv->bDefaultAntenna1 = ((priv->RegDefaultAntenna== 2) ? true : false);
4207 //printk("bDefaultAntenna1 = %d\n", priv->bDefaultAntenna1);
4208 //by amy for antenna
4209 /* rtl8185 can calc plcp len in HW.*/
4210 priv->hw_plcp_len = 1;
4212 priv->plcp_preamble_mode = 2;
4213 /*the eeprom type is stored in RCR register bit #6 */
4214 if (RCR_9356SEL & read_nic_dword(dev, RCR)){
4215 priv->epromtype=EPROM_93c56;
4216 //DMESG("Reported EEPROM chip is a 93c56 (2Kbit)");
4218 priv->epromtype=EPROM_93c46;
4219 //DMESG("Reported EEPROM chip is a 93c46 (1Kbit)");
4222 dev->dev_addr[0]=eprom_read(dev,MAC_ADR) & 0xff;
4223 dev->dev_addr[1]=(eprom_read(dev,MAC_ADR) & 0xff00)>>8;
4224 dev->dev_addr[2]=eprom_read(dev,MAC_ADR+1) & 0xff;
4225 dev->dev_addr[3]=(eprom_read(dev,MAC_ADR+1) & 0xff00)>>8;
4226 dev->dev_addr[4]=eprom_read(dev,MAC_ADR+2) & 0xff;
4227 dev->dev_addr[5]=(eprom_read(dev,MAC_ADR+2) & 0xff00)>>8;
4228 //DMESG("Card MAC address is "MAC_FMT, MAC_ARG(dev->dev_addr));
4231 for(i=1,j=0; i<14; i+=2,j++){
4233 word = eprom_read(dev,EPROM_TXPW_CH1_2 + j);
4234 priv->chtxpwr[i]=word & 0xff;
4235 priv->chtxpwr[i+1]=(word & 0xff00)>>8;
4237 DMESG("tx word %x:%x",j,word);
4238 DMESG("ch %d pwr %x",i,priv->chtxpwr[i]);
4239 DMESG("ch %d pwr %x",i+1,priv->chtxpwr[i+1]);
4242 if(priv->card_8185){
4243 for(i=1,j=0; i<14; i+=2,j++){
4245 word = eprom_read(dev,EPROM_TXPW_OFDM_CH1_2 + j);
4246 priv->chtxpwr_ofdm[i]=word & 0xff;
4247 priv->chtxpwr_ofdm[i+1]=(word & 0xff00)>>8;
4249 DMESG("ofdm tx word %x:%x",j,word);
4250 DMESG("ofdm ch %d pwr %x",i,priv->chtxpwr_ofdm[i]);
4251 DMESG("ofdm ch %d pwr %x",i+1,priv->chtxpwr_ofdm[i+1]);
4256 //3Read crystal calibtration and thermal meter indication on 87SE.
4258 // By SD3 SY's request. Added by Roger, 2007.12.11.
4260 tmpu16 = eprom_read(dev, EEPROM_RSV>>1);
4262 //printk("ReadAdapterInfo8185(): EEPROM_RSV(%04x)\n", tmpu16);
4264 // Crystal calibration for Xin and Xout resp.
4265 priv->XtalCal_Xout = tmpu16 & EEPROM_XTAL_CAL_XOUT_MASK; // 0~7.5pF
4266 priv->XtalCal_Xin = (tmpu16 & EEPROM_XTAL_CAL_XIN_MASK)>>4; // 0~7.5pF
4267 if((tmpu16 & EEPROM_XTAL_CAL_ENABLE)>>12)
4268 priv->bXtalCalibration = true;
4270 // Thermal meter reference indication.
4271 priv->ThermalMeter = (u8)((tmpu16 & EEPROM_THERMAL_METER_MASK)>>8);
4272 if((tmpu16 & EEPROM_THERMAL_METER_ENABLE)>>13)
4273 priv->bTxPowerTrack = true;
4276 word = eprom_read(dev,EPROM_TXPW_BASE);
4277 priv->cck_txpwr_base = word & 0xf;
4278 priv->ofdm_txpwr_base = (word>>4) & 0xf;
4280 version = eprom_read(dev,EPROM_VERSION);
4281 DMESG("EEPROM version %x",version);
4282 if( (!priv->card_8185) && version < 0x0101){
4283 DMESG ("EEPROM version too old, assuming defaults");
4284 DMESG ("If you see this message *plase* send your \
4285 DMESG output to andreamrl@tiscali.it THANKS");
4289 priv->cs_treshold=0xc;
4291 priv->rf_chip=RFCHIPID_PHILIPS;
4293 if(!priv->card_8185){
4294 u8 rfparam = eprom_read(dev,RF_PARAM);
4295 DMESG("RfParam: %x",rfparam);
4297 priv->digphy = rfparam & (1<<RF_PARAM_DIGPHY_SHIFT) ? 0:1;
4298 priv->antb = rfparam & (1<<RF_PARAM_ANTBDEFAULT_SHIFT) ? 1:0;
4300 priv->rcr_csense = (rfparam & RF_PARAM_CARRIERSENSE_MASK) >>
4301 RF_PARAM_CARRIERSENSE_SHIFT;
4304 (read_nic_byte(dev,CONFIG2)&(1<<CONFIG2_ANTENNA_SHIFT)) ? 1:0;
4306 priv->rcr_csense = 3;
4309 priv->cs_treshold = (eprom_read(dev,ENERGY_TRESHOLD)&0xff00) >>8;
4311 priv->rf_chip = 0xff & eprom_read(dev,RFCHIPID);
4314 priv->rf_chip = RF_ZEBRA4;
4315 priv->rf_sleep = rtl8225z4_rf_sleep;
4316 priv->rf_wakeup = rtl8225z4_rf_wakeup;
4317 //DMESG("Card reports RF frontend Realtek 8225z2");
4318 //DMESGW("This driver has EXPERIMENTAL support for this chipset.");
4319 //DMESGW("use it with care and at your own risk and");
4320 DMESGW("**PLEASE** REPORT SUCCESSFUL/UNSUCCESSFUL TO Realtek!");
4322 priv->rf_close = rtl8225z2_rf_close;
4323 priv->rf_init = rtl8225z2_rf_init;
4324 priv->rf_set_chan = rtl8225z2_rf_set_chan;
4325 priv->rf_set_sens = NULL;
4326 //priv->rf_sleep = rtl8225_rf_sleep;
4327 //priv->rf_wakeup = rtl8225_rf_wakeup;
4331 if(!priv->card_8185){
4333 DMESG ("Antenna B is default antenna");
4335 DMESG ("Antenna A is default antenna");
4338 DMESG ("Antenna diversity is enabled");
4340 DMESG("Antenna diversity is disabled");
4342 DMESG("Carrier sense %d",priv->rcr_csense);
4345 if (0!=alloc_rx_desc_ring(dev, priv->rxbuffersize, priv->rxringcount))
4348 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4349 TX_MANAGEPRIORITY_RING_ADDR))
4352 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4353 TX_BKPRIORITY_RING_ADDR))
4356 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4357 TX_BEPRIORITY_RING_ADDR))
4360 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4361 TX_VIPRIORITY_RING_ADDR))
4364 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4365 TX_VOPRIORITY_RING_ADDR))
4368 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
4369 TX_HIGHPRIORITY_RING_ADDR))
4372 if (0!=alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txbeaconcount,
4373 TX_BEACON_RING_ADDR))
4377 //priv->beacon_buf=NULL;
4379 if(!priv->card_8185){
4381 if(read_nic_byte(dev, CONFIG0) & (1<<CONFIG0_WEP40_SHIFT))
4382 DMESG ("40-bit WEP is supported in hardware");
4384 DMESG ("40-bit WEP is NOT supported in hardware");
4386 if(read_nic_byte(dev,CONFIG0) & (1<<CONFIG0_WEP104_SHIFT))
4387 DMESG ("104-bit WEP is supported in hardware");
4389 DMESG ("104-bit WEP is NOT supported in hardware");
4391 #if !defined(SA_SHIRQ)
4392 if(request_irq(dev->irq, (void *)rtl8180_interrupt, IRQF_SHARED, dev->name, dev)){
4394 if(request_irq(dev->irq, (void *)rtl8180_interrupt, SA_SHIRQ, dev->name, dev)){
4396 DMESGE("Error allocating IRQ %d",dev->irq);
4400 DMESG("IRQ %d",dev->irq);
4412 void rtl8180_no_hw_wep(struct net_device *dev)
4414 struct r8180_priv *priv = ieee80211_priv(dev);
4416 if(!priv->card_8185)
4420 security = read_nic_byte(dev, SECURITY);
4421 security &=~(1<<SECURITY_WEP_TX_ENABLE_SHIFT);
4422 security &=~(1<<SECURITY_WEP_RX_ENABLE_SHIFT);
4424 write_nic_byte(dev, SECURITY, security);
4431 write_nic_dword(dev,TX_CONF,read_nic_dword(dev,TX_CONF) |
4432 (1<<TX_NOICV_SHIFT) );
4434 // priv->ieee80211->hw_wep=0;
4438 void rtl8180_set_hw_wep(struct net_device *dev)
4440 struct r8180_priv *priv = ieee80211_priv(dev);
4445 pgreg=read_nic_byte(dev, PGSELECT);
4446 write_nic_byte(dev, PGSELECT, pgreg &~ (1<<PGSELECT_PG_SHIFT));
4448 key0_word4 = read_nic_dword(dev, KEY0+4+4+4);
4449 key0_word4 &= ~ 0xff;
4450 key0_word4 |= priv->key0[3]& 0xff;
4451 write_nic_dword(dev,KEY0,(priv->key0[0]));
4452 write_nic_dword(dev,KEY0+4,(priv->key0[1]));
4453 write_nic_dword(dev,KEY0+4+4,(priv->key0[2]));
4454 write_nic_dword(dev,KEY0+4+4+4,(key0_word4));
4457 TX_CONF,read_nic_dword(dev,TX_CONF) &~(1<<TX_NOICV_SHIFT));
4460 security = read_nic_byte(dev,SECURITY);
4461 security |= (1<<SECURITY_WEP_TX_ENABLE_SHIFT);
4462 security |= (1<<SECURITY_WEP_RX_ENABLE_SHIFT);
4463 security &= ~ SECURITY_ENCRYP_MASK;
4464 security |= (SECURITY_ENCRYP_104<<SECURITY_ENCRYP_SHIFT);
4466 write_nic_byte(dev, SECURITY, security);
4468 DMESG("key %x %x %x %x",read_nic_dword(dev,KEY0+4+4+4),
4469 read_nic_dword(dev,KEY0+4+4),read_nic_dword(dev,KEY0+4),
4470 read_nic_dword(dev,KEY0));
4472 //priv->ieee80211->hw_wep=1;
4476 void rtl8185_rf_pins_enable(struct net_device *dev)
4479 // tmp = read_nic_word(dev, RFPinsEnable);
4480 write_nic_word(dev, RFPinsEnable, 0x1fff);// | tmp);
4481 // write_nic_word(dev, RFPinsEnable,7 | tmp);
4485 void rtl8185_set_anaparam2(struct net_device *dev, u32 a)
4489 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
4491 conf3 = read_nic_byte(dev, CONFIG3);
4492 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
4493 write_nic_dword(dev, ANAPARAM2, a);
4495 conf3 = read_nic_byte(dev, CONFIG3);
4496 write_nic_byte(dev, CONFIG3, conf3 &~(1<<CONFIG3_ANAPARAM_W_SHIFT));
4497 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
4502 void rtl8180_set_anaparam(struct net_device *dev, u32 a)
4506 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
4508 conf3 = read_nic_byte(dev, CONFIG3);
4509 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
4510 write_nic_dword(dev, ANAPARAM, a);
4512 conf3 = read_nic_byte(dev, CONFIG3);
4513 write_nic_byte(dev, CONFIG3, conf3 &~(1<<CONFIG3_ANAPARAM_W_SHIFT));
4514 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
4518 void rtl8185_tx_antenna(struct net_device *dev, u8 ant)
4520 write_nic_byte(dev, TX_ANTENNA, ant);
4521 force_pci_posting(dev);
4526 void rtl8185_write_phy(struct net_device *dev, u8 adr, u32 data)
4534 phyw= ((data<<8) | adr);
4537 write_nic_dword(dev, PHY_ADR, phyw);
4539 //read_nic_dword(dev, PHY_ADR);
4541 write_nic_dword(dev, PHY_ADR, 0xffffff7f & phyw);
4542 phyr = read_nic_byte(dev, PHY_READ);
4543 if(phyr == (data&0xff)) break;
4547 // Note that, we must write 0xff7c after 0x7d-0x7f to write BB register.
4548 write_nic_byte(dev, 0x7f, ((phyw & 0xff000000) >> 24));
4549 write_nic_byte(dev, 0x7e, ((phyw & 0x00ff0000) >> 16));
4550 write_nic_byte(dev, 0x7d, ((phyw & 0x0000ff00) >> 8));
4551 write_nic_byte(dev, 0x7c, ((phyw & 0x000000ff) ));
4553 /* this is ok to fail when we write AGC table. check for AGC table might be
4554 * done by masking with 0x7f instead of 0xff
4556 //if(phyr != (data&0xff)) DMESGW("Phy write timeout %x %x %x", phyr, data,adr);
4560 inline void write_phy_ofdm (struct net_device *dev, u8 adr, u32 data)
4563 rtl8185_write_phy(dev, adr, data);
4567 void write_phy_cck (struct net_device *dev, u8 adr, u32 data)
4570 rtl8185_write_phy(dev, adr, data | 0x10000);
4575 * I hope this is enougth
4578 void write_phy(struct net_device *dev, u8 adr, u8 data)
4585 phy |= 0x80; /* this should enable writing */
4588 //PHY_ADR, PHY_R and PHY_W are contig and treated as one dword
4589 write_nic_dword(dev,PHY_ADR, phy);
4594 write_nic_dword(dev,PHY_ADR, phy);
4595 for(i=0;i<MAX_PHY;i++){
4596 phy=read_nic_dword(dev,PHY_ADR);
4597 phy= phy & 0xff0000;
4599 if(phy == data){ //SUCCESS!
4600 force_pci_posting(dev);
4601 mdelay(3); //random value
4603 DMESG("Phy wr %x,%x",adr,data);
4607 force_pci_posting(dev);
4608 mdelay(3); //random value
4611 DMESGW ("Phy writing %x %x failed!", adr,data);
4614 void rtl8185_set_rate(struct net_device *dev)
4618 int basic_rate,min_rr_rate,max_rr_rate;
4620 // struct r8180_priv *priv = ieee80211_priv(dev);
4622 //if (ieee80211_is_54g(priv->ieee80211->current_network) &&
4623 // priv->ieee80211->state == IEEE80211_LINKED){
4624 basic_rate = ieeerate2rtlrate(240);
4625 min_rr_rate = ieeerate2rtlrate(60);
4626 max_rr_rate = ieeerate2rtlrate(240);
4630 // basic_rate = ieeerate2rtlrate(20);
4631 // min_rr_rate = ieeerate2rtlrate(10);
4632 // max_rr_rate = ieeerate2rtlrate(110);
4635 write_nic_byte(dev, RESP_RATE,
4636 max_rr_rate<<MAX_RESP_RATE_SHIFT| min_rr_rate<<MIN_RESP_RATE_SHIFT);
4638 word = read_nic_word(dev, BRSR);
4639 word &= ~BRSR_MBR_8185;
4642 for(i=0;i<=basic_rate;i++)
4645 write_nic_word(dev, BRSR, word);
4646 //DMESG("RR:%x BRSR: %x", read_nic_byte(dev,RESP_RATE),read_nic_word(dev,BRSR));
4651 void rtl8180_adapter_start(struct net_device *dev)
4653 struct r8180_priv *priv = ieee80211_priv(dev);
4659 rtl8180_rtx_disable(dev);
4662 /* seems that 0xffff or 0xafff will cause
4663 * HW interrupt line crash
4666 //priv->irq_mask = 0xafff;
4667 // priv->irq_mask = 0x4fcf;
4669 /* enable beacon timeout, beacon TX ok and err
4670 * LP tx ok and err, HP TX ok and err, NP TX ok and err,
4671 * RX ok and ERR, and GP timer */
4672 priv->irq_mask = 0x6fcf;
4674 priv->dma_poll_mask = 0;
4676 rtl8180_beacon_tx_disable(dev);
4678 if(priv->card_type == CARDBUS ){
4679 config3=read_nic_byte(dev, CONFIG3);
4680 write_nic_byte(dev,CONFIG3,config3 | CONFIG3_FuncRegEn);
4681 write_nic_word(dev,FEMR, FEMR_INTR | FEMR_WKUP | FEMR_GWAKE |
4682 read_nic_word(dev, FEMR));
4684 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
4685 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
4686 write_nic_word(dev, MAC4, ((u32*)dev->dev_addr)[1] & 0xffff );
4687 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
4689 rtl8180_update_msr(dev);
4691 if(!priv->card_8185){
4692 anaparam = eprom_read(dev,EPROM_ANAPARAM_ADDRLWORD);
4693 anaparam |= eprom_read(dev,EPROM_ANAPARAM_ADDRHWORD)<<16;
4695 rtl8180_set_anaparam(dev,anaparam);
4697 /* These might be unnecessary since we do in rx_enable / tx_enable */
4700 /*set_nic_rxring(dev);
4701 set_nic_txring(dev);*/
4703 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
4706 The following is very strange. seems to be that 1 means test mode,
4707 but we need to acknolwledges the nic when a packet is ready
4708 altought we set it to 0
4712 CONFIG2, read_nic_byte(dev,CONFIG2) &~\
4713 (1<<CONFIG2_DMA_POLLING_MODE_SHIFT));
4714 //^the nic isn't in test mode
4717 CONFIG2, read_nic_byte(dev,CONFIG2)|(1<<4));
4719 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
4721 write_nic_dword(dev,INT_TIMEOUT,0);
4722 #ifdef DEBUG_REGISTERS
4723 rtl8180_dump_reg(dev);
4726 if(!priv->card_8185)
4729 experimental - this might be needed to calibrate AGC,
4730 anyway it shouldn't hurt
4732 write_nic_byte(dev, CONFIG5,
4733 read_nic_byte(dev, CONFIG5) | (1<<AGCRESET_SHIFT));
4734 read_nic_byte(dev, CONFIG5);
4736 write_nic_byte(dev, CONFIG5,
4737 read_nic_byte(dev, CONFIG5) &~ (1<<AGCRESET_SHIFT));
4740 write_nic_byte(dev, WPA_CONFIG, 0);
4741 //write_nic_byte(dev, TESTR, 0xd);
4744 rtl8180_no_hw_wep(dev);
4746 if(priv->card_8185){
4747 rtl8185_set_rate(dev);
4748 write_nic_byte(dev, RATE_FALLBACK, 0x81);
4749 // write_nic_byte(dev, 0xdf, 0x15);
4751 word = read_nic_word(dev, BRSR);
4753 word &= ~BRSR_BPLCP;
4754 word |= ieeerate2rtlrate(priv->ieee80211->basic_rate);
4758 write_nic_word(dev, BRSR, word);
4762 if(priv->card_8185){
4763 write_nic_byte(dev, GP_ENABLE,read_nic_byte(dev, GP_ENABLE) & ~(1<<6));
4765 //FIXME cfg 3 ClkRun enable - isn't it ReadOnly ?
4766 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
4767 write_nic_byte(dev,CONFIG3, read_nic_byte(dev, CONFIG3)
4768 |(1<<CONFIG3_CLKRUN_SHIFT));
4769 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
4775 if(priv->rf_set_sens != NULL)
4776 priv->rf_set_sens(dev,priv->sens);
4777 rtl8180_irq_enable(dev);
4779 netif_start_queue(dev);
4780 /*DMESG ("lfree %d",get_curr_tx_free_desc(dev,LOW_PRIORITY));
4782 DMESG ("nfree %d",get_curr_tx_free_desc(dev,NORM_PRIORITY));
4784 DMESG ("hfree %d",get_curr_tx_free_desc(dev,HI_PRIORITY));
4785 if(check_nic_enought_desc(dev,NORM_PRIORITY)) DMESG("NORM OK");
4786 if(check_nic_enought_desc(dev,HI_PRIORITY)) DMESG("HI OK");
4787 if(check_nic_enought_desc(dev,LOW_PRIORITY)) DMESG("LOW OK");*/
4792 /* this configures registers for beacon tx and enables it via
4793 * rtl8180_beacon_tx_enable(). rtl8180_beacon_tx_disable() might
4794 * be used to stop beacon transmission
4796 void rtl8180_start_tx_beacon(struct net_device *dev)
4798 // struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
4800 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
4802 DMESG("Enabling beacon TX");
4803 //write_nic_byte(dev, 0x42,0xe6);// TCR
4804 // set_nic_txring(dev);
4805 // fix_tx_fifo(dev);
4806 rtl8180_prepare_beacon(dev);
4807 rtl8180_irq_disable(dev);
4808 rtl8180_beacon_tx_enable(dev);
4810 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
4811 //write_nic_byte(dev,0x9d,0x20); //DMA Poll
4812 //write_nic_word(dev,0x7a,0);
4813 //write_nic_word(dev,0x7a,0x8000);
4816 word = read_nic_word(dev, BcnItv);
4817 word &= ~BcnItv_BcnItv; // clear Bcn_Itv
4818 word |= priv->ieee80211->current_network.beacon_interval;//0x64;
4819 write_nic_word(dev, BcnItv, word);
4822 word = read_nic_word(dev, AtimWnd) &~ AtimWnd_AtimWnd;
4823 write_nic_word(dev, AtimWnd,word);// word |=
4824 //priv->ieee80211->current_network.atim_window);
4826 word = read_nic_word(dev, BintrItv);
4827 word &= ~BintrItv_BintrItv;
4828 word |= 1000;/*priv->ieee80211->current_network.beacon_interval *
4829 ((priv->txbeaconcount > 1)?(priv->txbeaconcount-1):1);
4830 // FIXME: check if correct ^^ worked with 0x3e8;
4832 write_nic_word(dev, BintrItv, word);
4835 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
4837 // rtl8180_beacon_tx_enable(dev);
4838 rtl8185b_irq_enable(dev);
4839 /* VV !!!!!!!!!! VV*/
4841 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
4842 write_nic_byte(dev,0x9d,0x00);
4843 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);
4845 // DMESG("ring %x %x", priv->txlpringdma,read_nic_dword(dev,TLPDA));
4851 /***************************************************************************
4852 -------------------------------NET STUFF---------------------------
4853 ***************************************************************************/
4854 static struct net_device_stats *rtl8180_stats(struct net_device *dev)
4856 struct r8180_priv *priv = ieee80211_priv(dev);
4858 return &priv->ieee80211->stats;
4861 // Change current and default preamble mode.
4862 // 2005.01.06, by rcnjko.
4865 MgntActSet_802_11_PowerSaveMode(
4866 struct r8180_priv *priv,
4871 // Currently, we do not change power save mode on IBSS mode.
4872 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
4878 // <RJ_NOTE> If we make HW to fill up the PwrMgt bit for us,
4879 // some AP will not response to our mgnt frames with PwrMgt bit set,
4880 // e.g. cannot associate the AP.
4881 // So I commented out it. 2005.02.16, by rcnjko.
4883 // // Change device's power save mode.
4884 // Adapter->HalFunc.SetPSModeHandler( Adapter, rtPsMode );
4886 // Update power save mode configured.
4887 // priv->dot11PowerSaveMode = rtPsMode;
4888 priv->ieee80211->ps = rtPsMode;
4889 // Determine ListenInterval.
4891 if(priv->dot11PowerSaveMode == eMaxPs)
4893 priv->ieee80211->ListenInterval = 10;
4897 priv->ieee80211->ListenInterval = 2;
4903 //================================================================================
4904 // Leisure Power Save in linked state.
4905 //================================================================================
4909 // Enter the leisure power save mode.
4913 struct r8180_priv *priv
4916 if (priv->bLeisurePs)
4918 if (priv->ieee80211->ps == IEEE80211_PS_DISABLED)
4920 //printk("----Enter PS\n");
4921 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST);//IEEE80211_PS_ENABLE
4929 // Leave the leisure power save mode.
4933 struct r8180_priv *priv
4936 if (priv->bLeisurePs)
4938 if (priv->ieee80211->ps != IEEE80211_PS_DISABLED)
4940 //printk("----Leave PS\n");
4941 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_DISABLED);
4946 void rtl8180_hw_wakeup_wq (struct work_struct *work)
4948 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
4949 // struct ieee80211_device * ieee = (struct ieee80211_device*)
4950 // container_of(work, struct ieee80211_device, watch_dog_wq);
4951 struct delayed_work *dwork = to_delayed_work(work);
4952 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq);
4953 struct net_device *dev = ieee->dev;
4955 // printk("dev is %d\n",dev);
4956 // printk("&*&(^*(&(&=========>%s()\n", __func__);
4957 rtl8180_hw_wakeup(dev);
4961 void rtl8180_hw_sleep_wq (struct work_struct *work)
4963 // struct r8180_priv *priv = container_of(work, struct r8180_priv, watch_dog_wq);
4964 // struct ieee80211_device * ieee = (struct ieee80211_device*)
4965 // container_of(work, struct ieee80211_device, watch_dog_wq);
4966 struct delayed_work *dwork = to_delayed_work(work);
4967 struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq);
4968 struct net_device *dev = ieee->dev;
4970 rtl8180_hw_sleep_down(dev);
4973 //YJ,add,080828,for KeepAlive
4974 static void MgntLinkKeepAlive(struct r8180_priv *priv )
4976 if (priv->keepAliveLevel == 0)
4979 if(priv->ieee80211->state == IEEE80211_LINKED)
4984 //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);
4986 if ( (priv->keepAliveLevel== 2) ||
4987 (priv->link_detect.LastNumTxUnicast == priv->NumTxUnicast &&
4988 priv->link_detect.LastNumRxUnicast == priv->ieee80211->NumRxUnicast )
4991 priv->link_detect.IdleCount++;
4994 // Send a Keep-Alive packet packet to AP if we had been idle for a while.
4996 if(priv->link_detect.IdleCount >= ((KEEP_ALIVE_INTERVAL / CHECK_FOR_HANG_PERIOD)-1) )
4998 priv->link_detect.IdleCount = 0;
4999 ieee80211_sta_ps_send_null_frame(priv->ieee80211, false);
5004 priv->link_detect.IdleCount = 0;
5006 priv->link_detect.LastNumTxUnicast = priv->NumTxUnicast;
5007 priv->link_detect.LastNumRxUnicast = priv->ieee80211->NumRxUnicast;
5010 //YJ,add,080828,for KeepAlive,end
5012 static u8 read_acadapter_file(char *filename);
5013 void rtl8180_watch_dog(struct net_device *dev)
5015 struct r8180_priv *priv = ieee80211_priv(dev);
5016 bool bEnterPS = false;
5017 bool bBusyTraffic = false;
5022 if(priv->ieee80211->actscanning == false){
5023 if((priv->ieee80211->iw_mode != IW_MODE_ADHOC) && (priv->ieee80211->state == IEEE80211_NOLINK) && (priv->ieee80211->beinretry == false) && (priv->eRFPowerState == eRfOn)){
5028 //YJ,add,080828,for link state check
5029 if((priv->ieee80211->state == IEEE80211_LINKED) && (priv->ieee80211->iw_mode == IW_MODE_INFRA)){
5030 SlotIndex = (priv->link_detect.SlotIndex++) % priv->link_detect.SlotNum;
5031 priv->link_detect.RxFrameNum[SlotIndex] = priv->ieee80211->NumRxDataInPeriod + priv->ieee80211->NumRxBcnInPeriod;
5032 for( i=0; i<priv->link_detect.SlotNum; i++ )
5033 TotalRxNum+= priv->link_detect.RxFrameNum[i];
5034 //printk("&&&&&=== TotalRxNum = %d\n", TotalRxNum);
5035 if(TotalRxNum == 0){
5036 priv->ieee80211->state = IEEE80211_ASSOCIATING;
5037 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
5041 //YJ,add,080828,for KeepAlive
5042 MgntLinkKeepAlive(priv);
5044 //YJ,add,080828,for LPS
5046 if(priv->PowerProfile == POWER_PROFILE_BATTERY )
5048 //Turn on LeisurePS on battery power
5049 //printk("!!!!!On battery power\n");
5050 priv->bLeisurePs = true;
5052 else if(priv->PowerProfile == POWER_PROFILE_AC )
5054 // Turn off LeisurePS on AC power
5055 //printk("----On AC power\n");
5056 LeisurePSLeave(priv);
5057 priv->bLeisurePs= false;
5063 if(priv->ieee80211->state == IEEE80211_LINKED){
5064 if( priv->NumRxOkInPeriod> 666 ||
5065 priv->NumTxOkInPeriod > 666 ) {
5066 bBusyTraffic = true;
5068 if((priv->ieee80211->NumRxData + priv->NumTxOkInPeriod)<8) {
5072 LeisurePSEnter(priv);
5075 LeisurePSLeave(priv);
5079 LeisurePSLeave(priv);
5082 priv->NumRxOkInPeriod = 0;
5083 priv->NumTxOkInPeriod = 0;
5084 priv->ieee80211->NumRxData = 0;
5087 if(priv->ieee80211->state == IEEE80211_LINKED){
5088 priv->link_detect.NumRxOkInPeriod = priv->ieee80211->NumRxDataInPeriod;
5089 //printk("TxOk=%d RxOk=%d\n", priv->link_detect.NumTxOkInPeriod, priv->link_detect.NumRxOkInPeriod);
5090 if( priv->link_detect.NumRxOkInPeriod> 666 ||
5091 priv->link_detect.NumTxOkInPeriod> 666 ) {
5092 bBusyTraffic = true;
5094 if(((priv->link_detect.NumRxOkInPeriod + priv->link_detect.NumTxOkInPeriod) > 8)
5095 || (priv->link_detect.NumRxOkInPeriod > 2)) {
5103 LeisurePSEnter(priv);
5106 LeisurePSLeave(priv);
5110 LeisurePSLeave(priv);
5113 priv->link_detect.bBusyTraffic = bBusyTraffic;
5114 priv->link_detect.NumRxOkInPeriod = 0;
5115 priv->link_detect.NumTxOkInPeriod = 0;
5116 priv->ieee80211->NumRxDataInPeriod = 0;
5117 priv->ieee80211->NumRxBcnInPeriod = 0;
5120 int _rtl8180_up(struct net_device *dev)
5122 struct r8180_priv *priv = ieee80211_priv(dev);
5127 DMESG("Bringing up iface");
5128 rtl8185b_adapter_start(dev);
5129 rtl8185b_rx_enable(dev);
5130 rtl8185b_tx_enable(dev);
5132 if(priv->bInactivePs){
5133 if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
5139 timer_rate_adaptive((unsigned long)dev);
5142 watch_dog_adaptive((unsigned long)dev);
5144 if(priv->bSwAntennaDiverity)
5145 SwAntennaDiversityTimerCallback(dev);
5148 ieee80211_softmac_start_protocol(priv->ieee80211);
5150 //Add for RF power on power off by lizhaoming 080512
5151 // priv->eRFPowerState = eRfOn;
5152 // printk("\n--------Start queue_work:GPIOChangeRFWorkItem");
5153 // queue_delayed_work(priv->ieee80211->wq,&priv->ieee80211->GPIOChangeRFWorkItem,1000);
5159 int rtl8180_open(struct net_device *dev)
5161 struct r8180_priv *priv = ieee80211_priv(dev);
5164 down(&priv->wx_sem);
5165 ret = rtl8180_up(dev);
5172 int rtl8180_up(struct net_device *dev)
5174 struct r8180_priv *priv = ieee80211_priv(dev);
5176 if (priv->up == 1) return -1;
5178 return _rtl8180_up(dev);
5182 int rtl8180_close(struct net_device *dev)
5184 struct r8180_priv *priv = ieee80211_priv(dev);
5187 down(&priv->wx_sem);
5188 ret = rtl8180_down(dev);
5195 int rtl8180_down(struct net_device *dev)
5197 struct r8180_priv *priv = ieee80211_priv(dev);
5199 if (priv->up == 0) return -1;
5203 ieee80211_softmac_stop_protocol(priv->ieee80211);
5205 if (!netif_queue_stopped(dev))
5206 netif_stop_queue(dev);
5207 rtl8180_rtx_disable(dev);
5208 rtl8180_irq_disable(dev);
5209 del_timer_sync(&priv->watch_dog_timer);
5210 //cancel_delayed_work(&priv->ieee80211->watch_dog_wq);
5212 del_timer_sync(&priv->rateadapter_timer);
5213 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
5215 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
5216 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
5217 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
5218 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
5219 del_timer_sync(&priv->SwAntennaDiversityTimer);
5220 SetZebraRFPowerState8185(dev,eRfOff);
5221 //ieee80211_softmac_stop_protocol(priv->ieee80211);
5222 memset(&(priv->ieee80211->current_network),0,sizeof(struct ieee80211_network));
5223 priv->ieee80211->state = IEEE80211_NOLINK;
5227 void rtl8180_restart_wq(struct work_struct *work)
5229 struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
5230 struct net_device *dev = priv->dev;
5232 down(&priv->wx_sem);
5234 rtl8180_commit(dev);
5239 void rtl8180_restart(struct net_device *dev)
5241 struct r8180_priv *priv = ieee80211_priv(dev);
5242 //rtl8180_commit(dev);
5243 schedule_work(&priv->reset_wq);
5244 //DMESG("TXTIMEOUT");
5248 void rtl8180_commit(struct net_device *dev)
5250 struct r8180_priv *priv = ieee80211_priv(dev);
5252 if (priv->up == 0) return ;
5254 del_timer_sync(&priv->watch_dog_timer);
5255 //cancel_delayed_work(&priv->ieee80211->watch_dog_wq);
5257 //by amy for rate adaptive
5258 del_timer_sync(&priv->rateadapter_timer);
5259 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
5260 //by amy for rate adaptive
5262 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
5263 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
5264 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
5265 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
5266 del_timer_sync(&priv->SwAntennaDiversityTimer);
5267 ieee80211_softmac_stop_protocol(priv->ieee80211);
5268 rtl8180_irq_disable(dev);
5269 rtl8180_rtx_disable(dev);
5274 static void r8180_set_multicast(struct net_device *dev)
5276 struct r8180_priv *priv = ieee80211_priv(dev);
5279 //down(&priv->wx_sem);
5281 promisc = (dev->flags & IFF_PROMISC) ? 1:0;
5283 if (promisc != priv->promisc)
5284 rtl8180_restart(dev);
5286 priv->promisc = promisc;
5288 //up(&priv->wx_sem);
5292 /* this is called by the kernel when it needs to TX a 802.3 encapsulated frame*/
5293 int rtl8180_8023_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
5295 struct r8180_priv *priv = ieee80211_priv(dev);
5297 unsigned long flags;
5299 spin_lock_irqsave(&priv->tx_lock,flags);
5300 ret = ieee80211_r8180_8023_hardstartxmit(skb,priv->ieee80211);
5301 spin_unlock_irqrestore(&priv->tx_lock,flags);
5306 int r8180_set_mac_adr(struct net_device *dev, void *mac)
5308 struct r8180_priv *priv = ieee80211_priv(dev);
5309 struct sockaddr *addr = mac;
5311 down(&priv->wx_sem);
5313 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
5315 if(priv->ieee80211->iw_mode == IW_MODE_MASTER)
5316 memcpy(priv->ieee80211->current_network.bssid, dev->dev_addr, ETH_ALEN);
5328 /* based on ipw2200 driver */
5329 int rtl8180_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
5331 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
5333 struct iwreq *wrq = (struct iwreq *) rq;
5336 case RTL_IOCTL_WPA_SUPPLICANT:
5337 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
5349 /****************************************************************************
5350 -----------------------------PCI STUFF---------------------------
5351 *****************************************************************************/
5353 static const struct net_device_ops rtl8180_netdev_ops = {
5354 .ndo_open = rtl8180_open,
5355 .ndo_stop = rtl8180_close,
5356 .ndo_get_stats = rtl8180_stats,
5357 .ndo_tx_timeout = rtl8180_restart,
5358 .ndo_do_ioctl = rtl8180_ioctl,
5359 .ndo_set_multicast_list = r8180_set_multicast,
5360 .ndo_set_mac_address = r8180_set_mac_adr,
5361 .ndo_validate_addr = eth_validate_addr,
5362 .ndo_change_mtu = eth_change_mtu,
5363 .ndo_start_xmit = ieee80211_xmit,
5366 static int __devinit rtl8180_pci_probe(struct pci_dev *pdev,
5367 const struct pci_device_id *id)
5369 unsigned long ioaddr = 0;
5370 struct net_device *dev = NULL;
5371 struct r8180_priv *priv= NULL;
5375 unsigned long pmem_start, pmem_len, pmem_flags;
5377 DMESG("Configuring chip resources");
5379 if( pci_enable_device (pdev) ){
5380 DMESG("Failed to enable PCI device");
5384 pci_set_master(pdev);
5385 //pci_set_wmi(pdev);
5386 pci_set_dma_mask(pdev, 0xffffff00ULL);
5387 pci_set_consistent_dma_mask(pdev,0xffffff00ULL);
5388 dev = alloc_ieee80211(sizeof(struct r8180_priv));
5391 priv = ieee80211_priv(dev);
5392 priv->ieee80211 = netdev_priv(dev);
5394 pci_set_drvdata(pdev, dev);
5395 SET_NETDEV_DEV(dev, &pdev->dev);
5397 priv = ieee80211_priv(dev);
5398 // memset(priv,0,sizeof(struct r8180_priv));
5403 pmem_start = pci_resource_start(pdev, 1);
5404 pmem_len = pci_resource_len(pdev, 1);
5405 pmem_flags = pci_resource_flags (pdev, 1);
5407 if (!(pmem_flags & IORESOURCE_MEM)) {
5408 DMESG("region #1 not a MMIO resource, aborting");
5412 //DMESG("Memory mapped space @ 0x%08lx ", pmem_start);
5413 if( ! request_mem_region(pmem_start, pmem_len, RTL8180_MODULE_NAME)) {
5414 DMESG("request_mem_region failed!");
5419 ioaddr = (unsigned long)ioremap_nocache( pmem_start, pmem_len);
5420 if( ioaddr == (unsigned long)NULL ){
5421 DMESG("ioremap failed!");
5422 // release_mem_region( pmem_start, pmem_len );
5426 dev->mem_start = ioaddr; // shared mem start
5427 dev->mem_end = ioaddr + pci_resource_len(pdev, 0); // shared mem end
5430 //pci_read_config_byte(pdev, 0x05, ptr);
5431 //pci_write_config_byte(pdev, 0x05, (*ptr) & (~0x04));
5432 pci_read_config_byte(pdev, 0x05, &unit);
5433 pci_write_config_byte(pdev, 0x05, unit & (~0x04));
5435 dev->irq = pdev->irq;
5438 dev->netdev_ops = &rtl8180_netdev_ops;
5439 dev->wireless_handlers = &r8180_wx_handlers_def;
5441 dev->type=ARPHRD_ETHER;
5442 dev->watchdog_timeo = HZ*3; //added by david woo, 2007.12.13
5444 if (dev_alloc_name(dev, ifname) < 0){
5445 DMESG("Oops: devname already taken! Trying wlan%%d...\n");
5447 // ifname = "ath%d";
5448 dev_alloc_name(dev, ifname);
5452 if(rtl8180_init(dev)!=0){
5453 DMESG("Initialization failed");
5457 netif_carrier_off(dev);
5459 register_netdev(dev);
5461 rtl8180_proc_init_one(dev);
5463 DMESG("Driver probe completed\n");
5468 if( dev->mem_start != (unsigned long)NULL ){
5469 iounmap( (void *)dev->mem_start );
5470 release_mem_region( pci_resource_start(pdev, 1),
5471 pci_resource_len(pdev, 1) );
5479 free_irq(dev->irq, dev);
5482 free_ieee80211(dev);
5485 pci_disable_device(pdev);
5487 DMESG("wlan driver load failed\n");
5488 pci_set_drvdata(pdev, NULL);
5494 static void __devexit rtl8180_pci_remove(struct pci_dev *pdev)
5496 struct r8180_priv *priv;
5497 struct net_device *dev = pci_get_drvdata(pdev);
5500 unregister_netdev(dev);
5502 priv=ieee80211_priv(dev);
5504 rtl8180_proc_remove_one(dev);
5506 priv->rf_close(dev);
5508 //rtl8180_rtx_disable(dev);
5509 //rtl8180_irq_disable(dev);
5511 //write_nic_word(dev,INTA,read_nic_word(dev,INTA));
5512 //force_pci_posting(dev);
5517 DMESG("Freeing irq %d",dev->irq);
5518 free_irq(dev->irq, dev);
5523 free_rx_desc_ring(dev);
5524 free_tx_desc_rings(dev);
5525 // free_beacon_desc_ring(dev,priv->txbeaconcount);
5527 if( dev->mem_start != (unsigned long)NULL ){
5528 iounmap( (void *)dev->mem_start );
5529 release_mem_region( pci_resource_start(pdev, 1),
5530 pci_resource_len(pdev, 1) );
5533 free_ieee80211(dev);
5535 pci_disable_device(pdev);
5537 DMESG("wlan driver removed\n");
5541 /* fun with the built-in ieee80211 stack... */
5542 extern int ieee80211_crypto_init(void);
5543 extern void ieee80211_crypto_deinit(void);
5544 extern int ieee80211_crypto_tkip_init(void);
5545 extern void ieee80211_crypto_tkip_exit(void);
5546 extern int ieee80211_crypto_ccmp_init(void);
5547 extern void ieee80211_crypto_ccmp_exit(void);
5548 extern int ieee80211_crypto_wep_init(void);
5549 extern void ieee80211_crypto_wep_exit(void);
5551 static int __init rtl8180_pci_module_init(void)
5555 ret = ieee80211_crypto_init();
5557 printk(KERN_ERR "ieee80211_crypto_init() failed %d\n", ret);
5560 ret = ieee80211_crypto_tkip_init();
5562 printk(KERN_ERR "ieee80211_crypto_tkip_init() failed %d\n", ret);
5565 ret = ieee80211_crypto_ccmp_init();
5567 printk(KERN_ERR "ieee80211_crypto_ccmp_init() failed %d\n", ret);
5570 ret = ieee80211_crypto_wep_init();
5572 printk(KERN_ERR "ieee80211_crypto_wep_init() failed %d\n", ret);
5576 printk(KERN_INFO "\nLinux kernel driver for RTL8180 \
5577 / RTL8185 based WLAN cards\n");
5578 printk(KERN_INFO "Copyright (c) 2004-2005, Andrea Merello\n");
5579 DMESG("Initializing module");
5580 DMESG("Wireless extensions version %d", WIRELESS_EXT);
5581 rtl8180_proc_module_init();
5583 if(0!=pci_register_driver(&rtl8180_pci_driver))
5584 //if(0!=pci_module_init(&rtl8180_pci_driver))
5586 DMESG("No device found");
5587 /*pci_unregister_driver (&rtl8180_pci_driver);*/
5594 static void __exit rtl8180_pci_module_exit(void)
5596 pci_unregister_driver (&rtl8180_pci_driver);
5597 rtl8180_proc_module_remove();
5598 ieee80211_crypto_tkip_exit();
5599 ieee80211_crypto_ccmp_exit();
5600 ieee80211_crypto_wep_exit();
5601 ieee80211_crypto_deinit();
5606 void rtl8180_try_wake_queue(struct net_device *dev, int pri)
5608 unsigned long flags;
5610 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
5612 spin_lock_irqsave(&priv->tx_lock,flags);
5613 enough_desc = check_nic_enought_desc(dev,pri);
5614 spin_unlock_irqrestore(&priv->tx_lock,flags);
5617 ieee80211_wake_queue(priv->ieee80211);
5620 /*****************************************************************************
5621 -----------------------------IRQ STUFF---------------------------
5622 ******************************************************************************/
5624 void rtl8180_tx_isr(struct net_device *dev, int pri,short error)
5626 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
5628 u32 *tail; //tail virtual addr
5629 u32 *head; //head virtual addr
5630 u32 *begin;//start of ring virtual addr
5631 u32 *nicv; //nic pointer virtual addr
5632 // u32 *txdv; //packet just TXed
5633 u32 nic; //nic pointer physical addr
5634 u32 nicbegin;// start of ring physical addr
5637 /* physical addr are ok on 32 bits since we set DMA mask*/
5642 if (error) priv->stats.txretry++; //tony 20060601
5643 spin_lock_irqsave(&priv->tx_lock,flag);
5645 case MANAGE_PRIORITY:
5646 tail = priv->txmapringtail;
5647 begin = priv->txmapring;
5648 head = priv->txmapringhead;
5649 nic = read_nic_dword(dev,TX_MANAGEPRIORITY_RING_ADDR);
5650 nicbegin = priv->txmapringdma;
5654 tail = priv->txbkpringtail;
5655 begin = priv->txbkpring;
5656 head = priv->txbkpringhead;
5657 nic = read_nic_dword(dev,TX_BKPRIORITY_RING_ADDR);
5658 nicbegin = priv->txbkpringdma;
5662 tail = priv->txbepringtail;
5663 begin = priv->txbepring;
5664 head = priv->txbepringhead;
5665 nic = read_nic_dword(dev,TX_BEPRIORITY_RING_ADDR);
5666 nicbegin = priv->txbepringdma;
5670 tail = priv->txvipringtail;
5671 begin = priv->txvipring;
5672 head = priv->txvipringhead;
5673 nic = read_nic_dword(dev,TX_VIPRIORITY_RING_ADDR);
5674 nicbegin = priv->txvipringdma;
5678 tail = priv->txvopringtail;
5679 begin = priv->txvopring;
5680 head = priv->txvopringhead;
5681 nic = read_nic_dword(dev,TX_VOPRIORITY_RING_ADDR);
5682 nicbegin = priv->txvopringdma;
5686 tail = priv->txhpringtail;
5687 begin = priv->txhpring;
5688 head = priv->txhpringhead;
5689 nic = read_nic_dword(dev,TX_HIGHPRIORITY_RING_ADDR);
5690 nicbegin = priv->txhpringdma;
5694 spin_unlock_irqrestore(&priv->tx_lock,flag);
5697 /* DMESG("%x %s %x %x",((int)nic & 0xfff)/8/4,
5698 *(priv->txnpring + ((int)nic&0xfff)/4/8) & (1<<31) ? "filled" : "empty",
5699 (priv->txnpringtail - priv->txnpring)/8,(priv->txnpringhead -
5702 //nicv = (u32*) ((nic - nicbegin) + (int)begin);
5703 nicv = (u32*) ((nic - nicbegin) + (u8*)begin);
5704 if((head <= tail && (nicv > tail || nicv < head)) ||
5705 (head > tail && (nicv > tail && nicv < head))){
5707 DMESGW("nic has lost pointer");
5708 #ifdef DEBUG_TX_DESC
5709 //check_tx_ring(dev,NORM_PRIORITY);
5710 check_tx_ring(dev,pri);
5712 spin_unlock_irqrestore(&priv->tx_lock,flag);
5713 rtl8180_restart(dev);
5717 /* we check all the descriptors between the head and the nic,
5718 * but not the currenly pointed by the nic (the next to be txed)
5719 * and the previous of the pointed (might be in process ??)
5721 //if (head == nic) return;
5722 //DMESG("%x %x",head,nic);
5723 offs = (nic - nicbegin);
5724 //DMESG("%x %x %x",nic ,(u32)nicbegin, (int)nic -nicbegin);
5728 hd = (head - begin) /8;
5733 j = offs + (priv->txringcount -1 -hd);
5734 // j= priv->txringcount -1- (hd - offs);
5742 // printk("+++++++++++++check status desc\n");
5743 if((*head) & (1<<31))
5745 if(((*head)&(0x10000000)) != 0){
5746 // printk("++++++++++++++last desc,retry count is %d\n",((*head) & (0x000000ff)));
5747 priv->CurrRetryCnt += (u16)((*head) & (0x000000ff));
5751 priv->NumTxOkTotal++;
5752 // printk("NumTxOkTotal is %d\n",priv->NumTxOkTotal++);
5755 // printk("in function %s:curr_retry_count is %d\n",__func__,((*head) & (0x000000ff)));
5758 priv->NumTxOkBytesTotal += (*(head+3)) & (0x00000fff);
5760 // printk("in function %s:curr_txokbyte_count is %d\n",__func__,(*(head+3)) & (0x00000fff));
5761 *head = *head &~ (1<<31);
5763 if((head - begin)/8 == priv->txringcount-1)
5771 txdv = begin + (priv->txringcount -1)*8;
5775 txed = !(txdv[0] &(1<<31));
5778 if(!(txdv[0] & (1<<15))) error = 1;
5779 //if(!(txdv[0] & (1<<30))) error = 1;
5780 if(error)DMESG("%x",txdv[0]);
5783 //DMESG("%x",txdv[0]);
5784 /* the head has been moved to the last certainly TXed
5785 * (or at least processed by the nic) packet.
5786 * The driver take forcefully owning of all these packets
5787 * If the packet previous of the nic pointer has been
5788 * processed this doesn't matter: it will be checked
5789 * here at the next round. Anyway if no more packet are
5790 * TXed no memory leak occour at all.
5794 case MANAGE_PRIORITY:
5795 priv->txmapringhead = head;
5796 //printk("1==========================================> priority check!\n");
5797 if(priv->ack_tx_to_ieee){
5798 // try to implement power-save mode 2008.1.22
5799 // printk("2==========================================> priority check!\n");
5801 if(rtl8180_is_tx_queue_empty(dev)){
5802 // printk("tx queue empty, after send null sleep packet, try to sleep !\n");
5803 priv->ack_tx_to_ieee = 0;
5804 ieee80211_ps_tx_ack(priv->ieee80211,!error);
5811 priv->txbkpringhead = head;
5815 priv->txbepringhead = head;
5819 priv->txvipringhead = head;
5823 priv->txvopringhead = head;
5827 priv->txhpringhead = head;
5831 /*DMESG("%x %x %x", (priv->txnpringhead - priv->txnpring) /8 ,
5832 (priv->txnpringtail - priv->txnpring) /8,
5836 spin_unlock_irqrestore(&priv->tx_lock,flag);
5840 void rtl8180_tx_irq_wq(struct work_struct *work)
5842 //struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
5843 struct delayed_work *dwork = to_delayed_work(work);
5844 struct ieee80211_device * ieee = (struct ieee80211_device*)
5845 container_of(dwork, struct ieee80211_device, watch_dog_wq);
5846 struct net_device *dev = ieee->dev;
5848 rtl8180_tx_isr(dev,MANAGE_PRIORITY,0);
5850 irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs)
5852 struct net_device *dev = (struct net_device *) netdev;
5853 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
5854 unsigned long flags;
5857 /* We should return IRQ_NONE, but for now let me keep this */
5858 if(priv->irq_enabled == 0) return IRQ_HANDLED;
5860 spin_lock_irqsave(&priv->irq_th_lock,flags);
5863 inta = read_nic_dword(dev, ISR);// & priv->IntrMask;
5864 write_nic_dword(dev,ISR,inta); // reset int situation
5866 priv->stats.shints++;
5868 //DMESG("Enter interrupt, ISR value = 0x%08x", inta);
5871 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
5874 most probably we can safely return IRQ_NONE,
5875 but for now is better to avoid problems
5881 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
5887 DMESG("NIC irq %x",inta);
5889 //priv->irqpending = inta;
5892 if(!netif_running(dev)) {
5893 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
5897 if(inta & ISR_TimeOut){
5898 write_nic_dword(dev, TimerInt, 0);
5899 //DMESG("=================>waking up");
5900 // rtl8180_hw_wakeup(dev);
5903 if(inta & ISR_TBDOK){
5904 priv->stats.txbeacon++;
5907 if(inta & ISR_TBDER){
5908 priv->stats.txbeaconerr++;
5911 if(inta & IMR_TMGDOK ) {
5912 // priv->NumTxOkTotal++;
5913 rtl8180_tx_isr(dev,MANAGE_PRIORITY,0);
5914 // schedule_work(&priv->tx_irq_wq);
5918 if(inta & ISR_THPDER){
5920 DMESG ("TX high priority ERR");
5922 priv->stats.txhperr++;
5923 rtl8180_tx_isr(dev,HI_PRIORITY,1);
5924 priv->ieee80211->stats.tx_errors++;
5927 if(inta & ISR_THPDOK){ //High priority tx ok
5929 DMESG ("TX high priority OK");
5931 // priv->NumTxOkTotal++;
5932 //priv->NumTxOkInPeriod++; //YJ,del,080828
5933 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
5934 priv->stats.txhpokint++;
5935 rtl8180_tx_isr(dev,HI_PRIORITY,0);
5938 if(inta & ISR_RER) {
5939 priv->stats.rxerr++;
5941 DMESGW("RX error int");
5944 if(inta & ISR_TBKDER){ //corresponding to BK_PRIORITY
5945 priv->stats.txbkperr++;
5946 priv->ieee80211->stats.tx_errors++;
5948 DMESGW("TX bkp error int");
5950 //tasklet_schedule(&priv->irq_tx_tasklet);
5951 rtl8180_tx_isr(dev,BK_PRIORITY,1);
5952 rtl8180_try_wake_queue(dev, BE_PRIORITY);
5955 if(inta & ISR_TBEDER){ //corresponding to BE_PRIORITY
5956 priv->stats.txbeperr++;
5957 priv->ieee80211->stats.tx_errors++;
5959 DMESGW("TX bep error int");
5961 rtl8180_tx_isr(dev,BE_PRIORITY,1);
5962 //tasklet_schedule(&priv->irq_tx_tasklet);
5963 rtl8180_try_wake_queue(dev, BE_PRIORITY);
5965 if(inta & ISR_TNPDER){ //corresponding to VO_PRIORITY
5966 priv->stats.txnperr++;
5967 priv->ieee80211->stats.tx_errors++;
5969 DMESGW("TX np error int");
5971 //tasklet_schedule(&priv->irq_tx_tasklet);
5972 rtl8180_tx_isr(dev,NORM_PRIORITY,1);
5973 rtl8180_try_wake_queue(dev, NORM_PRIORITY);
5976 if(inta & ISR_TLPDER){ //corresponding to VI_PRIORITY
5977 priv->stats.txlperr++;
5978 priv->ieee80211->stats.tx_errors++;
5980 DMESGW("TX lp error int");
5982 rtl8180_tx_isr(dev,LOW_PRIORITY,1);
5983 //tasklet_schedule(&priv->irq_tx_tasklet);
5984 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
5989 DMESG("Frame arrived !");
5991 //priv->NumRxOkInPeriod++; //YJ,del,080828
5992 priv->stats.rxint++;
5993 tasklet_schedule(&priv->irq_rx_tasklet);
5996 if(inta & ISR_RQoSOK ){
5998 DMESG("QoS Frame arrived !");
6000 //priv->NumRxOkInPeriod++; //YJ,del,080828
6001 priv->stats.rxint++;
6002 tasklet_schedule(&priv->irq_rx_tasklet);
6004 if(inta & ISR_BcnInt) {
6005 //DMESG("Preparing Beacons");
6006 rtl8180_prepare_beacon(dev);
6011 DMESGW("No RX descriptor available");
6012 priv->stats.rxrdu++;
6014 tasklet_schedule(&priv->irq_rx_tasklet);
6015 /*queue_work(priv->workqueue ,&priv->restart_work);*/
6018 if(inta & ISR_RXFOVW){
6020 DMESGW("RX fifo overflow");
6022 priv->stats.rxoverflow++;
6023 tasklet_schedule(&priv->irq_rx_tasklet);
6024 //queue_work(priv->workqueue ,&priv->restart_work);
6027 if(inta & ISR_TXFOVW) priv->stats.txoverflow++;
6029 if(inta & ISR_TNPDOK){ //Normal priority tx ok
6031 DMESG ("TX normal priority OK");
6033 // priv->NumTxOkTotal++;
6034 //priv->NumTxOkInPeriod++; //YJ,del,080828
6035 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6036 // priv->ieee80211->stats.tx_packets++;
6037 priv->stats.txnpokint++;
6038 rtl8180_tx_isr(dev,NORM_PRIORITY,0);
6041 if(inta & ISR_TLPDOK){ //Low priority tx ok
6043 DMESG ("TX low priority OK");
6045 // priv->NumTxOkTotal++;
6046 //priv->NumTxOkInPeriod++; //YJ,del,080828
6047 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6048 // priv->ieee80211->stats.tx_packets++;
6049 priv->stats.txlpokint++;
6050 rtl8180_tx_isr(dev,LOW_PRIORITY,0);
6051 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
6054 if(inta & ISR_TBKDOK){ //corresponding to BK_PRIORITY
6055 priv->stats.txbkpokint++;
6057 DMESGW("TX bk priority ok");
6059 // priv->NumTxOkTotal++;
6060 //priv->NumTxOkInPeriod++; //YJ,del,080828
6061 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6062 rtl8180_tx_isr(dev,BK_PRIORITY,0);
6063 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6066 if(inta & ISR_TBEDOK){ //corresponding to BE_PRIORITY
6067 priv->stats.txbeperr++;
6069 DMESGW("TX be priority ok");
6071 // priv->NumTxOkTotal++;
6072 //priv->NumTxOkInPeriod++; //YJ,del,080828
6073 priv->link_detect.NumTxOkInPeriod++; //YJ,add,080828
6074 rtl8180_tx_isr(dev,BE_PRIORITY,0);
6075 rtl8180_try_wake_queue(dev, BE_PRIORITY);
6077 force_pci_posting(dev);
6078 spin_unlock_irqrestore(&priv->irq_th_lock,flags);
6084 void rtl8180_irq_rx_tasklet(struct r8180_priv* priv)
6086 // unsigned long flags;
6088 /* spin_lock_irqsave(&priv->irq_lock, flags);
6089 priv->irq_mask &=~IMR_ROK;
6090 priv->irq_mask &=~IMR_RDU;
6092 rtl8180_irq_enable(priv->dev);
6093 spin_unlock_irqrestore(&priv->irq_lock, flags);
6095 rtl8180_rx(priv->dev);
6097 /* spin_lock_irqsave(&priv->irq_lock, flags);
6098 priv->irq_mask |= IMR_ROK;
6099 priv->irq_mask |= IMR_RDU;
6100 rtl8180_irq_enable(priv->dev);
6101 spin_unlock_irqrestore(&priv->irq_lock, flags);
6105 /****************************************************************************
6106 lizhaoming--------------------------- RF power on/power off -----------------
6107 *****************************************************************************/
6109 void GPIOChangeRFWorkItemCallBack(struct work_struct *work)
6111 //struct delayed_work *dwork = to_delayed_work(work);
6112 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, GPIOChangeRFWorkItem.work);
6113 struct net_device *dev = ieee->dev;
6114 struct r8180_priv *priv = ieee80211_priv(dev);
6119 RT_RF_POWER_STATE eRfPowerStateToSet;
6120 bool bActuallySet=false;
6123 static char *RadioPowerPath = "/etc/acpi/events/RadioPower.sh";
6124 static char *envp[] = {"HOME=/", "TERM=linux", "PATH=/usr/bin:/bin", NULL};
6125 static int readf_count = 0;
6126 //printk("============>%s in \n", __func__);
6129 if(readf_count % 10 == 0)
6130 priv->PowerProfile = read_acadapter_file("/proc/acpi/ac_adapter/AC0/state");
6132 readf_count = (readf_count+1)%0xffff;
6135 if(priv->up == 0)//driver stopped
6137 printk("\nDo nothing...");
6143 // We should turn off LED before polling FF51[4].
6146 btPSR = read_nic_byte(dev, PSR);
6147 write_nic_byte(dev, PSR, (btPSR & ~BIT3));
6149 //It need to delay 4us suggested by Jong, 2008-01-16
6152 //HW radio On/Off according to the value of FF51[4](config0)
6153 btConfig0 = btPSR = read_nic_byte(dev, CONFIG0);
6156 write_nic_byte(dev, PSR, btPSR| BIT3);
6158 eRfPowerStateToSet = (btConfig0 & BIT4) ? eRfOn : eRfOff;
6160 if((priv->ieee80211->bHwRadioOff == true) && (eRfPowerStateToSet == eRfOn))
6162 priv->ieee80211->bHwRadioOff = false;
6163 bActuallySet = true;
6165 else if((priv->ieee80211->bHwRadioOff == false) && (eRfPowerStateToSet == eRfOff))
6167 priv->ieee80211->bHwRadioOff = true;
6168 bActuallySet = true;
6173 MgntActSet_RF_State(dev, eRfPowerStateToSet, RF_CHANGE_BY_HW);
6175 /* To update the UI status for Power status changed */
6176 if(priv->ieee80211->bHwRadioOff == true)
6179 //if(!priv->RfOffReason)
6182 // argv[1] = "RFOFF";
6184 argv[0] = RadioPowerPath;
6187 call_usermodehelper(RadioPowerPath,argv,envp,1);
6194 static u8 read_acadapter_file(char *filename)
6202 mm_segment_t old_fs = get_fs();
6205 fd = sys_open(filename, O_RDONLY, 0);
6207 while (sys_read(fd, buf, 1) == 1)
6222 // printk("%s \n", ret);
6225 if(strncmp(ret, "off-line",8) == 0)
6233 /***************************************************************************
6234 ------------------- module init / exit stubs ----------------
6235 ****************************************************************************/
6236 module_init(rtl8180_pci_module_init);
6237 module_exit(rtl8180_pci_module_exit);