2 * This is part of rtl818x pci OpenSource driver - v 0.1
3 * Copyright (C) Andrea Merello 2004-2005 <andrea.merello@gmail.com>
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.
26 * Power management interface routines.
27 * Written by Mariusz Matuszek.
30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #undef RX_DONT_PASS_UL
35 #include <linux/slab.h>
36 #include <linux/syscalls.h>
37 #include <linux/eeprom_93cx6.h>
38 #include <linux/interrupt.h>
39 #include <linux/proc_fs.h>
40 #include <linux/seq_file.h>
44 #include "r8180_rtl8225.h" /* RTL8225 Radio frontend */
45 #include "r8180_93cx6.h" /* Card EEPROM */
49 #include "ieee80211/dot11d.h"
51 static struct pci_device_id rtl8180_pci_id_tbl[] = {
53 .vendor = PCI_VENDOR_ID_REALTEK,
55 .subvendor = PCI_ANY_ID,
56 .subdevice = PCI_ANY_ID,
68 static char ifname[IFNAMSIZ] = "wlan%d";
71 MODULE_LICENSE("GPL");
72 MODULE_DEVICE_TABLE(pci, rtl8180_pci_id_tbl);
73 MODULE_AUTHOR("Andrea Merello <andrea.merello@gmail.com>");
74 MODULE_DESCRIPTION("Linux driver for Realtek RTL8187SE WiFi cards");
76 module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR);
77 module_param(hwwep, int, S_IRUGO|S_IWUSR);
79 MODULE_PARM_DESC(hwwep, " Try to use hardware WEP support. Still broken and not available on all cards");
81 static int rtl8180_pci_probe(struct pci_dev *pdev,
82 const struct pci_device_id *id);
84 static void rtl8180_pci_remove(struct pci_dev *pdev);
86 static void rtl8180_shutdown(struct pci_dev *pdev)
88 struct net_device *dev = pci_get_drvdata(pdev);
89 if (dev->netdev_ops->ndo_stop)
90 dev->netdev_ops->ndo_stop(dev);
91 pci_disable_device(pdev);
94 static int rtl8180_suspend(struct pci_dev *pdev, pm_message_t state)
96 struct net_device *dev = pci_get_drvdata(pdev);
98 if (!netif_running(dev))
101 if (dev->netdev_ops->ndo_stop)
102 dev->netdev_ops->ndo_stop(dev);
104 netif_device_detach(dev);
107 pci_save_state(pdev);
108 pci_disable_device(pdev);
109 pci_set_power_state(pdev, pci_choose_state(pdev, state));
113 static int rtl8180_resume(struct pci_dev *pdev)
115 struct net_device *dev = pci_get_drvdata(pdev);
119 pci_set_power_state(pdev, PCI_D0);
121 err = pci_enable_device(pdev);
123 dev_err(&pdev->dev, "pci_enable_device failed on resume\n");
128 pci_restore_state(pdev);
131 * Suspend/Resume resets the PCI configuration space, so we have to
132 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
133 * from interfering with C3 CPU state. pci_restore_state won't help
134 * here since it only restores the first 64 bytes pci config header.
136 pci_read_config_dword(pdev, 0x40, &val);
137 if ((val & 0x0000ff00) != 0)
138 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
140 if (!netif_running(dev))
143 if (dev->netdev_ops->ndo_open)
144 dev->netdev_ops->ndo_open(dev);
146 netif_device_attach(dev);
151 static struct pci_driver rtl8180_pci_driver = {
152 .name = RTL8180_MODULE_NAME,
153 .id_table = rtl8180_pci_id_tbl,
154 .probe = rtl8180_pci_probe,
155 .remove = rtl8180_pci_remove,
156 .suspend = rtl8180_suspend,
157 .resume = rtl8180_resume,
158 .shutdown = rtl8180_shutdown,
161 u8 read_nic_byte(struct net_device *dev, int x)
163 return 0xff&readb((u8 __iomem *)dev->mem_start + x);
166 u32 read_nic_dword(struct net_device *dev, int x)
168 return readl((u8 __iomem *)dev->mem_start + x);
171 u16 read_nic_word(struct net_device *dev, int x)
173 return readw((u8 __iomem *)dev->mem_start + x);
176 void write_nic_byte(struct net_device *dev, int x, u8 y)
178 writeb(y, (u8 __iomem *)dev->mem_start + x);
182 void write_nic_dword(struct net_device *dev, int x, u32 y)
184 writel(y, (u8 __iomem *)dev->mem_start + x);
188 void write_nic_word(struct net_device *dev, int x, u16 y)
190 writew(y, (u8 __iomem *)dev->mem_start + x);
194 inline void force_pci_posting(struct net_device *dev)
196 read_nic_byte(dev, EPROM_CMD);
200 static irqreturn_t rtl8180_interrupt(int irq, void *netdev);
201 void set_nic_rxring(struct net_device *dev);
202 void set_nic_txring(struct net_device *dev);
203 static struct net_device_stats *rtl8180_stats(struct net_device *dev);
204 void rtl8180_commit(struct net_device *dev);
205 void rtl8180_start_tx_beacon(struct net_device *dev);
207 static struct proc_dir_entry *rtl8180_proc;
209 static int proc_get_registers(struct seq_file *m, void *v)
211 struct net_device *dev = m->private;
212 int i, n, max = 0xff;
214 /* This dump the current register page */
215 for (n = 0; n <= max;) {
216 seq_printf(m, "\nD: %2x > ", n);
218 for (i = 0; i < 16 && n <= max; i++, n++)
219 seq_printf(m, "%2x ", read_nic_byte(dev, n));
225 int get_curr_tx_free_desc(struct net_device *dev, int priority);
227 static int proc_get_stats_hw(struct seq_file *m, void *v)
232 static int proc_get_stats_rx(struct seq_file *m, void *v)
234 struct net_device *dev = m->private;
235 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
240 "RX CRC Error(0-500): %lu\n"
241 "RX CRC Error(500-1000): %lu\n"
242 "RX CRC Error(>1000): %lu\n"
243 "RX ICV Error: %lu\n",
246 priv->stats.rxcrcerrmin,
247 priv->stats.rxcrcerrmid,
248 priv->stats.rxcrcerrmax,
255 static int proc_get_stats_tx(struct seq_file *m, void *v)
257 struct net_device *dev = m->private;
258 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
259 unsigned long totalOK;
261 totalOK = priv->stats.txnpokint + priv->stats.txhpokint +
262 priv->stats.txlpokint;
268 "TX beacon OK: %lu\n"
269 "TX beacon error: %lu\n",
271 priv->stats.txnperr+priv->stats.txhperr+priv->stats.txlperr,
273 priv->stats.txbeacon,
274 priv->stats.txbeaconerr
280 static void rtl8180_proc_module_init(void)
282 DMESG("Initializing proc filesystem");
283 rtl8180_proc = proc_mkdir(RTL8180_MODULE_NAME, init_net.proc_net);
286 static void rtl8180_proc_module_remove(void)
288 remove_proc_entry(RTL8180_MODULE_NAME, init_net.proc_net);
291 static void rtl8180_proc_remove_one(struct net_device *dev)
293 remove_proc_subtree(dev->name, rtl8180_proc);
297 * seq_file wrappers for procfile show routines.
299 static int rtl8180_proc_open(struct inode *inode, struct file *file)
301 struct net_device *dev = proc_get_parent_data(inode);
302 int (*show)(struct seq_file *, void *) = PDE_DATA(inode);
304 return single_open(file, show, dev);
307 static const struct file_operations rtl8180_proc_fops = {
308 .open = rtl8180_proc_open,
311 .release = single_release,
315 * Table of proc files we need to create.
317 struct rtl8180_proc_file {
319 int (*show)(struct seq_file *, void *);
322 static const struct rtl8180_proc_file rtl8180_proc_files[] = {
323 { "stats-hw", &proc_get_stats_hw },
324 { "stats-rx", &proc_get_stats_rx },
325 { "stats-tx", &proc_get_stats_tx },
326 { "registers", &proc_get_registers },
330 static void rtl8180_proc_init_one(struct net_device *dev)
332 const struct rtl8180_proc_file *f;
333 struct proc_dir_entry *dir;
335 dir = proc_mkdir_data(dev->name, 0, rtl8180_proc, dev);
337 DMESGE("Unable to initialize /proc/net/r8180/%s\n", dev->name);
341 for (f = rtl8180_proc_files; f->name[0]; f++) {
342 if (!proc_create_data(f->name, S_IFREG | S_IRUGO, dir,
343 &rtl8180_proc_fops, f->show)) {
344 DMESGE("Unable to initialize /proc/net/r8180/%s/%s\n",
352 * FIXME: check if we can use some standard already-existent
353 * data type+functions in kernel.
356 static short buffer_add(struct buffer **buffer, u32 *buf, dma_addr_t dma,
357 struct buffer **bufferhead)
363 *buffer = kmalloc(sizeof(struct buffer), GFP_KERNEL);
365 if (*buffer == NULL) {
366 DMESGE("Failed to kmalloc head of TX/RX struct");
369 (*buffer)->next = *buffer;
370 (*buffer)->buf = buf;
371 (*buffer)->dma = dma;
372 if (bufferhead != NULL)
373 (*bufferhead) = (*buffer);
378 while (tmp->next != (*buffer))
380 tmp->next = kmalloc(sizeof(struct buffer), GFP_KERNEL);
381 if (tmp->next == NULL) {
382 DMESGE("Failed to kmalloc TX/RX struct");
385 tmp->next->buf = buf;
386 tmp->next->dma = dma;
387 tmp->next->next = *buffer;
392 static void buffer_free(struct net_device *dev, struct buffer **buffer, int len,
396 struct buffer *tmp, *next;
397 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
398 struct pci_dev *pdev = priv->pdev;
408 pci_free_consistent(pdev, len,
411 pci_unmap_single(pdev, tmp->dma,
412 len, PCI_DMA_FROMDEVICE);
417 } while (next != *buffer);
422 int get_curr_tx_free_desc(struct net_device *dev, int priority)
424 struct r8180_priv *priv = ieee80211_priv(dev);
430 case MANAGE_PRIORITY:
431 head = priv->txmapringhead;
432 tail = priv->txmapringtail;
435 head = priv->txbkpringhead;
436 tail = priv->txbkpringtail;
439 head = priv->txbepringhead;
440 tail = priv->txbepringtail;
443 head = priv->txvipringhead;
444 tail = priv->txvipringtail;
447 head = priv->txvopringhead;
448 tail = priv->txvopringtail;
451 head = priv->txhpringhead;
452 tail = priv->txhpringtail;
459 ret = priv->txringcount - (tail - head)/8;
461 ret = (head - tail)/8;
463 if (ret > priv->txringcount)
469 static short check_nic_enought_desc(struct net_device *dev, int priority)
471 struct r8180_priv *priv = ieee80211_priv(dev);
472 struct ieee80211_device *ieee = netdev_priv(dev);
476 requiredbyte = priv->ieee80211->fts +
477 sizeof(struct ieee80211_header_data);
479 if (ieee->current_network.QoS_Enable)
482 required = requiredbyte / (priv->txbuffsize-4);
484 if (requiredbyte % priv->txbuffsize)
487 /* for now we keep two free descriptor as a safety boundary
488 * between the tail and the head
491 return required + 2 < get_curr_tx_free_desc(dev, priority);
494 void fix_tx_fifo(struct net_device *dev)
496 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
500 for (tmp = priv->txmapring, i = 0;
501 i < priv->txringcount;
503 *tmp = *tmp & ~(1<<31);
506 for (tmp = priv->txbkpring, i = 0;
507 i < priv->txringcount;
509 *tmp = *tmp & ~(1<<31);
512 for (tmp = priv->txbepring, i = 0;
513 i < priv->txringcount;
515 *tmp = *tmp & ~(1<<31);
517 for (tmp = priv->txvipring, i = 0;
518 i < priv->txringcount;
520 *tmp = *tmp & ~(1<<31);
523 for (tmp = priv->txvopring, i = 0;
524 i < priv->txringcount;
526 *tmp = *tmp & ~(1<<31);
529 for (tmp = priv->txhpring, i = 0;
530 i < priv->txringcount;
532 *tmp = *tmp & ~(1<<31);
535 for (tmp = priv->txbeaconring, i = 0;
536 i < priv->txbeaconcount;
538 *tmp = *tmp & ~(1<<31);
541 priv->txmapringtail = priv->txmapring;
542 priv->txmapringhead = priv->txmapring;
543 priv->txmapbufstail = priv->txmapbufs;
545 priv->txbkpringtail = priv->txbkpring;
546 priv->txbkpringhead = priv->txbkpring;
547 priv->txbkpbufstail = priv->txbkpbufs;
549 priv->txbepringtail = priv->txbepring;
550 priv->txbepringhead = priv->txbepring;
551 priv->txbepbufstail = priv->txbepbufs;
553 priv->txvipringtail = priv->txvipring;
554 priv->txvipringhead = priv->txvipring;
555 priv->txvipbufstail = priv->txvipbufs;
557 priv->txvopringtail = priv->txvopring;
558 priv->txvopringhead = priv->txvopring;
559 priv->txvopbufstail = priv->txvopbufs;
561 priv->txhpringtail = priv->txhpring;
562 priv->txhpringhead = priv->txhpring;
563 priv->txhpbufstail = priv->txhpbufs;
565 priv->txbeaconringtail = priv->txbeaconring;
566 priv->txbeaconbufstail = priv->txbeaconbufs;
569 ieee80211_reset_queue(priv->ieee80211);
570 priv->ack_tx_to_ieee = 0;
573 void fix_rx_fifo(struct net_device *dev)
575 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
577 struct buffer *rxbuf;
580 rx_desc_size = 8; /* 4*8 = 32 bytes */
582 for (tmp = priv->rxring, rxbuf = priv->rxbufferhead;
583 (tmp < (priv->rxring)+(priv->rxringcount)*rx_desc_size);
584 tmp += rx_desc_size, rxbuf = rxbuf->next) {
585 *(tmp+2) = rxbuf->dma;
586 *tmp = *tmp & ~0xfff;
587 *tmp = *tmp | priv->rxbuffersize;
591 priv->rxringtail = priv->rxring;
592 priv->rxbuffer = priv->rxbufferhead;
593 priv->rx_skb_complete = 1;
597 static void rtl8180_irq_disable(struct net_device *dev)
599 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
601 write_nic_dword(dev, IMR, 0);
602 force_pci_posting(dev);
603 priv->irq_enabled = 0;
606 void rtl8180_set_mode(struct net_device *dev, int mode)
610 ecmd = read_nic_byte(dev, EPROM_CMD);
611 ecmd = ecmd & ~EPROM_CMD_OPERATING_MODE_MASK;
612 ecmd = ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
613 ecmd = ecmd & ~(1<<EPROM_CS_SHIFT);
614 ecmd = ecmd & ~(1<<EPROM_CK_SHIFT);
615 write_nic_byte(dev, EPROM_CMD, ecmd);
618 void rtl8180_beacon_tx_enable(struct net_device *dev);
620 void rtl8180_update_msr(struct net_device *dev)
622 struct r8180_priv *priv = ieee80211_priv(dev);
626 msr = read_nic_byte(dev, MSR);
627 msr &= ~MSR_LINK_MASK;
629 rxconf = read_nic_dword(dev, RX_CONF);
631 if (priv->ieee80211->state == IEEE80211_LINKED) {
632 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
633 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
634 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
635 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
636 else if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
637 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
639 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
640 rxconf |= (1<<RX_CHECK_BSSID_SHIFT);
643 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
644 rxconf &= ~(1<<RX_CHECK_BSSID_SHIFT);
647 write_nic_byte(dev, MSR, msr);
648 write_nic_dword(dev, RX_CONF, rxconf);
651 void rtl8180_set_chan(struct net_device *dev, short ch)
653 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
655 if ((ch > 14) || (ch < 1)) {
656 netdev_err(dev, "In %s: Invalid channel %d\n", __func__, ch);
661 priv->rf_set_chan(dev, priv->chan);
664 void set_nic_txring(struct net_device *dev)
666 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
668 write_nic_dword(dev, TX_MANAGEPRIORITY_RING_ADDR, priv->txmapringdma);
669 write_nic_dword(dev, TX_BKPRIORITY_RING_ADDR, priv->txbkpringdma);
670 write_nic_dword(dev, TX_BEPRIORITY_RING_ADDR, priv->txbepringdma);
671 write_nic_dword(dev, TX_VIPRIORITY_RING_ADDR, priv->txvipringdma);
672 write_nic_dword(dev, TX_VOPRIORITY_RING_ADDR, priv->txvopringdma);
673 write_nic_dword(dev, TX_HIGHPRIORITY_RING_ADDR, priv->txhpringdma);
674 write_nic_dword(dev, TX_BEACON_RING_ADDR, priv->txbeaconringdma);
677 void rtl8180_beacon_tx_enable(struct net_device *dev)
679 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
681 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
682 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_BQ);
683 write_nic_byte(dev, TPPollStop, priv->dma_poll_mask);
684 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
687 void rtl8180_beacon_tx_disable(struct net_device *dev)
689 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
691 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
692 priv->dma_poll_stop_mask |= TPPOLLSTOP_BQ;
693 write_nic_byte(dev, TPPollStop, priv->dma_poll_stop_mask);
694 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
698 void rtl8180_rtx_disable(struct net_device *dev)
701 struct r8180_priv *priv = ieee80211_priv(dev);
703 cmd = read_nic_byte(dev, CMD);
704 write_nic_byte(dev, CMD, cmd &
705 ~((1<<CMD_RX_ENABLE_SHIFT)|(1<<CMD_TX_ENABLE_SHIFT)));
706 force_pci_posting(dev);
709 if (!priv->rx_skb_complete)
710 dev_kfree_skb_any(priv->rx_skb);
713 static short alloc_tx_desc_ring(struct net_device *dev, int bufsize, int count,
719 dma_addr_t dma_desc, dma_tmp;
720 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
721 struct pci_dev *pdev = priv->pdev;
724 if ((bufsize & 0xfff) != bufsize) {
725 DMESGE("TX buffer allocation too large");
728 desc = (u32 *)pci_alloc_consistent(pdev,
729 sizeof(u32)*8*count+256, &dma_desc);
735 * descriptor's buffer must be 256 byte aligned
736 * we shouldn't be here, since we set DMA mask !
738 WARN(1, "DMA buffer is not aligned\n");
742 for (i = 0; i < count; i++) {
743 buf = (void *)pci_alloc_consistent(pdev, bufsize, &dma_tmp);
748 case TX_MANAGEPRIORITY_RING_ADDR:
749 if (-1 == buffer_add(&priv->txmapbufs,
750 buf, dma_tmp, NULL)) {
751 DMESGE("Unable to allocate mem for buffer NP");
755 case TX_BKPRIORITY_RING_ADDR:
756 if (-1 == buffer_add(&priv->txbkpbufs,
757 buf, dma_tmp, NULL)) {
758 DMESGE("Unable to allocate mem for buffer LP");
762 case TX_BEPRIORITY_RING_ADDR:
763 if (-1 == buffer_add(&priv->txbepbufs,
764 buf, dma_tmp, NULL)) {
765 DMESGE("Unable to allocate mem for buffer NP");
769 case TX_VIPRIORITY_RING_ADDR:
770 if (-1 == buffer_add(&priv->txvipbufs,
771 buf, dma_tmp, NULL)) {
772 DMESGE("Unable to allocate mem for buffer LP");
776 case TX_VOPRIORITY_RING_ADDR:
777 if (-1 == buffer_add(&priv->txvopbufs,
778 buf, dma_tmp, NULL)) {
779 DMESGE("Unable to allocate mem for buffer NP");
783 case TX_HIGHPRIORITY_RING_ADDR:
784 if (-1 == buffer_add(&priv->txhpbufs,
785 buf, dma_tmp, NULL)) {
786 DMESGE("Unable to allocate mem for buffer HP");
790 case TX_BEACON_RING_ADDR:
791 if (-1 == buffer_add(&priv->txbeaconbufs,
792 buf, dma_tmp, NULL)) {
793 DMESGE("Unable to allocate mem for buffer BP");
798 *tmp = *tmp & ~(1<<31); /* descriptor empty, owned by the drv */
799 *(tmp+2) = (u32)dma_tmp;
803 *(tmp+4) = (u32)dma_desc+((i+1)*8*4);
805 *(tmp+4) = (u32)dma_desc;
811 case TX_MANAGEPRIORITY_RING_ADDR:
812 priv->txmapringdma = dma_desc;
813 priv->txmapring = desc;
815 case TX_BKPRIORITY_RING_ADDR:
816 priv->txbkpringdma = dma_desc;
817 priv->txbkpring = desc;
819 case TX_BEPRIORITY_RING_ADDR:
820 priv->txbepringdma = dma_desc;
821 priv->txbepring = desc;
823 case TX_VIPRIORITY_RING_ADDR:
824 priv->txvipringdma = dma_desc;
825 priv->txvipring = desc;
827 case TX_VOPRIORITY_RING_ADDR:
828 priv->txvopringdma = dma_desc;
829 priv->txvopring = desc;
831 case TX_HIGHPRIORITY_RING_ADDR:
832 priv->txhpringdma = dma_desc;
833 priv->txhpring = desc;
835 case TX_BEACON_RING_ADDR:
836 priv->txbeaconringdma = dma_desc;
837 priv->txbeaconring = desc;
845 static void free_tx_desc_rings(struct net_device *dev)
847 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
848 struct pci_dev *pdev = priv->pdev;
849 int count = priv->txringcount;
851 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
852 priv->txmapring, priv->txmapringdma);
853 buffer_free(dev, &(priv->txmapbufs), priv->txbuffsize, 1);
855 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
856 priv->txbkpring, priv->txbkpringdma);
857 buffer_free(dev, &(priv->txbkpbufs), priv->txbuffsize, 1);
859 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
860 priv->txbepring, priv->txbepringdma);
861 buffer_free(dev, &(priv->txbepbufs), priv->txbuffsize, 1);
863 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
864 priv->txvipring, priv->txvipringdma);
865 buffer_free(dev, &(priv->txvipbufs), priv->txbuffsize, 1);
867 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
868 priv->txvopring, priv->txvopringdma);
869 buffer_free(dev, &(priv->txvopbufs), priv->txbuffsize, 1);
871 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
872 priv->txhpring, priv->txhpringdma);
873 buffer_free(dev, &(priv->txhpbufs), priv->txbuffsize, 1);
875 count = priv->txbeaconcount;
876 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
877 priv->txbeaconring, priv->txbeaconringdma);
878 buffer_free(dev, &(priv->txbeaconbufs), priv->txbuffsize, 1);
881 static void free_rx_desc_ring(struct net_device *dev)
883 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
884 struct pci_dev *pdev = priv->pdev;
885 int count = priv->rxringcount;
887 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
888 priv->rxring, priv->rxringdma);
890 buffer_free(dev, &(priv->rxbuffer), priv->rxbuffersize, 0);
893 static short alloc_rx_desc_ring(struct net_device *dev, u16 bufsize, int count)
898 dma_addr_t dma_desc, dma_tmp;
899 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
900 struct pci_dev *pdev = priv->pdev;
904 rx_desc_size = 8; /* 4*8 = 32 bytes */
906 if ((bufsize & 0xfff) != bufsize) {
907 DMESGE("RX buffer allocation too large");
911 desc = (u32 *)pci_alloc_consistent(pdev,
912 sizeof(u32) * rx_desc_size * count + 256, &dma_desc);
916 * descriptor's buffer must be 256 byte aligned
917 * should never happen since we specify the DMA mask
919 WARN(1, "DMA buffer is not aligned\n");
922 priv->rxringdma = dma_desc;
925 for (i = 0; i < count; i++) {
926 buf = kmalloc(bufsize * sizeof(u8), GFP_ATOMIC);
928 DMESGE("Failed to kmalloc RX buffer");
932 dma_tmp = pci_map_single(pdev, buf, bufsize * sizeof(u8),
934 if (pci_dma_mapping_error(pdev, dma_tmp))
936 if (-1 == buffer_add(&(priv->rxbuffer), buf, dma_tmp,
937 &(priv->rxbufferhead))) {
938 DMESGE("Unable to allocate mem RX buf");
941 *tmp = 0; /* zero pads the header of the descriptor */
942 *tmp = *tmp | (bufsize&0xfff);
943 *(tmp+2) = (u32)dma_tmp;
944 *tmp = *tmp | (1<<31); /* descriptor void, owned by the NIC */
946 tmp = tmp+rx_desc_size;
949 /* this is the last descriptor */
950 *(tmp - rx_desc_size) = *(tmp - rx_desc_size) | (1 << 30);
956 void set_nic_rxring(struct net_device *dev)
959 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
961 pgreg = read_nic_byte(dev, PGSELECT);
962 write_nic_byte(dev, PGSELECT, pgreg & ~(1<<PGSELECT_PG_SHIFT));
964 write_nic_dword(dev, RXRING_ADDR, priv->rxringdma);
967 void rtl8180_reset(struct net_device *dev)
971 rtl8180_irq_disable(dev);
973 cr = read_nic_byte(dev, CMD);
975 cr = cr | (1<<CMD_RST_SHIFT);
976 write_nic_byte(dev, CMD, cr);
978 force_pci_posting(dev);
982 if (read_nic_byte(dev, CMD) & (1<<CMD_RST_SHIFT))
983 DMESGW("Card reset timeout!");
985 DMESG("Card successfully reset");
987 rtl8180_set_mode(dev, EPROM_CMD_LOAD);
988 force_pci_posting(dev);
992 inline u16 ieeerate2rtlrate(int rate)
1024 static u16 rtl_rate[] = {10, 20, 55, 110, 60,
1025 90, 120, 180, 240, 360, 480, 540, 720};
1027 inline u16 rtl8180_rate2rate(short rate)
1031 return rtl_rate[rate];
1034 inline u8 rtl8180_IsWirelessBMode(u16 rate)
1036 if (((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220))
1042 u16 N_DBPSOfRate(u16 DataRate);
1044 static u16 ComputeTxTime(u16 FrameLength, u16 DataRate, u8 bManagementFrame,
1051 if (rtl8180_IsWirelessBMode(DataRate)) {
1052 if (bManagementFrame || !bShortPreamble || DataRate == 10)
1054 FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
1056 /* short preamble */
1057 FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
1059 if ((FrameLength*8 % (DataRate/10)) != 0) /* get the ceilling */
1061 } else { /* 802.11g DSSS-OFDM PLCP length field calculation. */
1062 N_DBPS = N_DBPSOfRate(DataRate);
1063 Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
1064 + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
1065 FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
1070 u16 N_DBPSOfRate(u16 DataRate)
1107 * For Netgear case, they want good-looking signal strength.
1109 static long NetgearSignalStrengthTranslate(long LastSS, long CurrSS)
1113 /* Step 1. Scale mapping. */
1114 if (CurrSS >= 71 && CurrSS <= 100)
1115 RetSS = 90 + ((CurrSS - 70) / 3);
1116 else if (CurrSS >= 41 && CurrSS <= 70)
1117 RetSS = 78 + ((CurrSS - 40) / 3);
1118 else if (CurrSS >= 31 && CurrSS <= 40)
1119 RetSS = 66 + (CurrSS - 30);
1120 else if (CurrSS >= 21 && CurrSS <= 30)
1121 RetSS = 54 + (CurrSS - 20);
1122 else if (CurrSS >= 5 && CurrSS <= 20)
1123 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
1124 else if (CurrSS == 4)
1126 else if (CurrSS == 3)
1128 else if (CurrSS == 2)
1130 else if (CurrSS == 1)
1135 /* Step 2. Smoothing. */
1137 RetSS = ((LastSS * 5) + (RetSS) + 5) / 6;
1143 * Translate 0-100 signal strength index into dBm.
1145 static long TranslateToDbm8185(u8 SignalStrengthIndex)
1149 /* Translate to dBm (x=0.5y-95). */
1150 SignalPower = (long)((SignalStrengthIndex + 1) >> 1);
1157 * Perform signal smoothing for dynamic mechanism.
1158 * This is different with PerformSignalSmoothing8185 in smoothing formula.
1159 * No dramatic adjustment is applied because dynamic mechanism need some
1160 * degree of correctness. Ported from 8187B.
1162 static void PerformUndecoratedSignalSmoothing8185(struct r8180_priv *priv,
1168 /* Determine the current packet is CCK rate. */
1169 priv->bCurCCKPkt = bCckRate;
1171 smoothedSS = priv->SignalStrength * 10;
1173 if (priv->UndecoratedSmoothedSS >= 0)
1174 smoothedSS = ((priv->UndecoratedSmoothedSS * 5) +
1177 priv->UndecoratedSmoothedSS = smoothedSS;
1179 smoothedRx = ((priv->UndecoratedSmoothedRxPower * 50) +
1180 (priv->RxPower * 11)) / 60;
1182 priv->UndecoratedSmoothedRxPower = smoothedRx;
1185 priv->CurCCKRSSI = priv->RSSI;
1187 priv->CurCCKRSSI = 0;
1192 * This is rough RX isr handling routine
1194 static void rtl8180_rx(struct net_device *dev)
1196 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1197 struct sk_buff *tmp_skb;
1201 unsigned char quality, signal;
1210 u8 LNA_gain[4] = {02, 17, 29, 39};
1212 struct ieee80211_hdr_4addr *hdr;
1214 u8 bHwError = 0, bCRC = 0, bICV = 0;
1215 bool bCckRate = false;
1217 long SignalStrengthIndex = 0;
1218 struct ieee80211_rx_stats stats = {
1222 .freq = IEEE80211_24GHZ_BAND,
1225 stats.nic_type = NIC_8185B;
1228 if ((*(priv->rxringtail)) & (1<<31)) {
1229 /* we have got an RX int, but the descriptor. we are pointing
1233 priv->stats.rxnodata++;
1234 priv->ieee80211->stats.rx_errors++;
1237 tmp = priv->rxringtail;
1239 if (tmp == priv->rxring)
1240 tmp = priv->rxring + (priv->rxringcount - 1) *
1243 tmp -= rx_desc_size;
1245 if (!(*tmp & (1<<31)))
1247 } while (tmp != priv->rxring);
1250 priv->rxringtail = tmp2;
1253 /* while there are filled descriptors */
1254 while (!(*(priv->rxringtail) & (1<<31))) {
1255 if (*(priv->rxringtail) & (1<<26))
1256 DMESGW("RX buffer overflow");
1257 if (*(priv->rxringtail) & (1<<12))
1258 priv->stats.rxicverr++;
1260 if (*(priv->rxringtail) & (1<<27)) {
1261 priv->stats.rxdmafail++;
1265 pci_dma_sync_single_for_cpu(priv->pdev,
1266 priv->rxbuffer->dma,
1267 priv->rxbuffersize * sizeof(u8),
1268 PCI_DMA_FROMDEVICE);
1270 first = *(priv->rxringtail) & (1<<29) ? 1 : 0;
1272 priv->rx_prevlen = 0;
1274 last = *(priv->rxringtail) & (1<<28) ? 1 : 0;
1276 lastlen = ((*priv->rxringtail) & 0xfff);
1278 /* if the last descriptor (that should tell us the total
1279 * packet len) tell us something less than the
1280 * descriptors len we had until now, then there is some
1282 * workaround to prevent kernel panic
1284 if (lastlen < priv->rx_prevlen)
1287 len = lastlen-priv->rx_prevlen;
1289 if (*(priv->rxringtail) & (1<<13)) {
1290 if ((*(priv->rxringtail) & 0xfff) < 500)
1291 priv->stats.rxcrcerrmin++;
1292 else if ((*(priv->rxringtail) & 0x0fff) > 1000)
1293 priv->stats.rxcrcerrmax++;
1295 priv->stats.rxcrcerrmid++;
1300 len = priv->rxbuffersize;
1303 if (first && last) {
1304 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
1306 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
1313 priv->rx_prevlen += len;
1315 if (priv->rx_prevlen > MAX_FRAG_THRESHOLD + 100) {
1316 /* HW is probably passing several buggy frames without
1317 * FD or LD flag set.
1318 * Throw this garbage away to prevent skb memory
1321 if (!priv->rx_skb_complete)
1322 dev_kfree_skb_any(priv->rx_skb);
1323 priv->rx_skb_complete = 1;
1326 signal = (unsigned char)((*(priv->rxringtail + 3) &
1328 signal = (signal & 0xfe) >> 1;
1330 quality = (unsigned char)((*(priv->rxringtail+3)) & (0xff));
1332 stats.mac_time[0] = *(priv->rxringtail+1);
1333 stats.mac_time[1] = *(priv->rxringtail+2);
1335 rxpower = ((char)((*(priv->rxringtail + 4) &
1336 0x00ff0000) >> 16)) / 2 - 42;
1338 RSSI = ((u8)((*(priv->rxringtail + 3) &
1339 0x0000ff00) >> 8)) & 0x7f;
1341 rate = ((*(priv->rxringtail)) &
1342 ((1<<23)|(1<<22)|(1<<21)|(1<<20)))>>20;
1344 stats.rate = rtl8180_rate2rate(rate);
1345 Antenna = (*(priv->rxringtail + 3) & 0x00008000) == 0 ? 0 : 1;
1346 if (!rtl8180_IsWirelessBMode(stats.rate)) { /* OFDM rate. */
1347 RxAGC_dBm = rxpower+1; /* bias */
1348 } else { /* CCK rate. */
1349 RxAGC_dBm = signal; /* bit 0 discard */
1351 LNA = (u8) (RxAGC_dBm & 0x60) >> 5; /* bit 6~ bit 5 */
1352 BB = (u8) (RxAGC_dBm & 0x1F); /* bit 4 ~ bit 0 */
1354 /* Pin_11b=-(LNA_gain+BB_gain) (dBm) */
1355 RxAGC_dBm = -(LNA_gain[LNA] + (BB * 2));
1357 RxAGC_dBm += 4; /* bias */
1360 if (RxAGC_dBm & 0x80) /* absolute value */
1361 RXAGC = ~(RxAGC_dBm)+1;
1362 bCckRate = rtl8180_IsWirelessBMode(stats.rate);
1363 /* Translate RXAGC into 1-100. */
1364 if (!rtl8180_IsWirelessBMode(stats.rate)) { /* OFDM rate. */
1367 else if (RXAGC < 25)
1369 RXAGC = (90-RXAGC)*100/65;
1370 } else { /* CCK rate. */
1373 else if (RXAGC < 30)
1375 RXAGC = (95-RXAGC)*100/65;
1377 priv->SignalStrength = (u8)RXAGC;
1378 priv->RecvSignalPower = RxAGC_dBm;
1379 priv->RxPower = rxpower;
1381 /* SQ translation formula is provided by SD3 DZ. 2006.06.27 */
1383 /* 0 causes epc to show signal zero, walk around now */
1385 else if (quality < 27)
1388 quality = 127 - quality;
1389 priv->SignalQuality = quality;
1391 stats.signal = (u8) quality;
1393 stats.signalstrength = RXAGC;
1394 if (stats.signalstrength > 100)
1395 stats.signalstrength = 100;
1396 stats.signalstrength = (stats.signalstrength * 70) / 100 + 30;
1397 stats.rssi = priv->wstats.qual.qual = priv->SignalQuality;
1398 stats.noise = priv->wstats.qual.noise =
1399 100 - priv->wstats.qual.qual;
1400 bHwError = (((*(priv->rxringtail)) & (0x00000fff)) == 4080) |
1401 (((*(priv->rxringtail)) & (0x04000000)) != 0) |
1402 (((*(priv->rxringtail)) & (0x08000000)) != 0) |
1403 (((~(*(priv->rxringtail))) & (0x10000000)) != 0) |
1404 (((~(*(priv->rxringtail))) & (0x20000000)) != 0);
1405 bCRC = ((*(priv->rxringtail)) & (0x00002000)) >> 13;
1406 bICV = ((*(priv->rxringtail)) & (0x00001000)) >> 12;
1407 hdr = (struct ieee80211_hdr_4addr *)priv->rxbuffer->buf;
1408 fc = le16_to_cpu(hdr->frame_ctl);
1409 type = WLAN_FC_GET_TYPE(fc);
1411 if (IEEE80211_FTYPE_CTL != type &&
1412 !bHwError && !bCRC && !bICV &&
1413 eqMacAddr(priv->ieee80211->current_network.bssid,
1414 fc & IEEE80211_FCTL_TODS ? hdr->addr1 :
1415 fc & IEEE80211_FCTL_FROMDS ? hdr->addr2 :
1418 /* Perform signal smoothing for dynamic
1419 * mechanism on demand. This is different
1420 * with PerformSignalSmoothing8185 in smoothing
1421 * fomula. No dramatic adjustion is apply
1422 * because dynamic mechanism need some degree
1423 * of correctness. */
1424 PerformUndecoratedSignalSmoothing8185(priv, bCckRate);
1426 /* For good-looking singal strength. */
1427 SignalStrengthIndex = NetgearSignalStrengthTranslate(
1428 priv->LastSignalStrengthInPercent,
1429 priv->SignalStrength);
1431 priv->LastSignalStrengthInPercent = SignalStrengthIndex;
1432 priv->Stats_SignalStrength =
1433 TranslateToDbm8185((u8)SignalStrengthIndex);
1436 * We need more correct power of received packets and
1437 * the "SignalStrength" of RxStats is beautified, so we
1438 * record the correct power here.
1441 priv->Stats_SignalQuality = (long)(
1442 priv->Stats_SignalQuality * 5 +
1443 (long)priv->SignalQuality + 5) / 6;
1445 priv->Stats_RecvSignalPower = (long)(
1446 priv->Stats_RecvSignalPower * 5 +
1447 priv->RecvSignalPower - 1) / 6;
1450 * Figure out which antenna received the last packet.
1453 priv->LastRxPktAntenna = Antenna ? 1 : 0;
1454 SwAntennaDiversityRxOk8185(dev, priv->SignalStrength);
1458 if (!priv->rx_skb_complete) {
1459 /* seems that HW sometimes fails to receive and
1460 * doesn't provide the last descriptor.
1462 dev_kfree_skb_any(priv->rx_skb);
1463 priv->stats.rxnolast++;
1465 priv->rx_skb = dev_alloc_skb(len+2);
1469 priv->rx_skb_complete = 0;
1470 priv->rx_skb->dev = dev;
1472 /* if we are here we should have already RXed the first
1474 * If we get here and the skb is not allocated then
1475 * we have just throw out garbage (skb not allocated)
1476 * and we are still rxing garbage....
1478 if (!priv->rx_skb_complete) {
1480 tmp_skb = dev_alloc_skb(
1481 priv->rx_skb->len + len + 2);
1488 memcpy(skb_put(tmp_skb, priv->rx_skb->len),
1492 dev_kfree_skb_any(priv->rx_skb);
1494 priv->rx_skb = tmp_skb;
1498 if (!priv->rx_skb_complete) {
1499 memcpy(skb_put(priv->rx_skb, len), ((unsigned char *)
1500 priv->rxbuffer->buf) + (padding ? 2 : 0), len);
1503 if (last && !priv->rx_skb_complete) {
1504 if (priv->rx_skb->len > 4)
1505 skb_trim(priv->rx_skb, priv->rx_skb->len-4);
1506 if (!ieee80211_rtl_rx(priv->ieee80211,
1507 priv->rx_skb, &stats))
1508 dev_kfree_skb_any(priv->rx_skb);
1509 priv->rx_skb_complete = 1;
1512 pci_dma_sync_single_for_device(priv->pdev,
1513 priv->rxbuffer->dma,
1514 priv->rxbuffersize * sizeof(u8),
1515 PCI_DMA_FROMDEVICE);
1517 drop: /* this is used when we have not enough mem */
1518 /* restore the descriptor */
1519 *(priv->rxringtail+2) = priv->rxbuffer->dma;
1520 *(priv->rxringtail) = *(priv->rxringtail) & ~0xfff;
1521 *(priv->rxringtail) =
1522 *(priv->rxringtail) | priv->rxbuffersize;
1524 *(priv->rxringtail) =
1525 *(priv->rxringtail) | (1<<31);
1527 priv->rxringtail += rx_desc_size;
1528 if (priv->rxringtail >=
1529 (priv->rxring)+(priv->rxringcount)*rx_desc_size)
1530 priv->rxringtail = priv->rxring;
1532 priv->rxbuffer = (priv->rxbuffer->next);
1537 static void rtl8180_dma_kick(struct net_device *dev, int priority)
1539 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1541 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1542 write_nic_byte(dev, TX_DMA_POLLING,
1543 (1 << (priority + 1)) | priv->dma_poll_mask);
1544 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1546 force_pci_posting(dev);
1549 static void rtl8180_data_hard_stop(struct net_device *dev)
1551 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1553 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1554 priv->dma_poll_stop_mask |= TPPOLLSTOP_AC_VIQ;
1555 write_nic_byte(dev, TPPollStop, priv->dma_poll_stop_mask);
1556 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1559 static void rtl8180_data_hard_resume(struct net_device *dev)
1561 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1563 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1564 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_AC_VIQ);
1565 write_nic_byte(dev, TPPollStop, priv->dma_poll_stop_mask);
1566 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1570 * This function TX data frames when the ieee80211 stack requires this.
1571 * It checks also if we need to stop the ieee tx queue, eventually do it
1573 static void rtl8180_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
1576 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1578 struct ieee80211_hdr_3addr *h = (struct ieee80211_hdr_3addr *)skb->data;
1579 bool morefrag = le16_to_cpu(h->frame_control) & IEEE80211_FCTL_MOREFRAGS;
1580 unsigned long flags;
1583 mode = priv->ieee80211->iw_mode;
1585 rate = ieeerate2rtlrate(rate);
1587 * This function doesn't require lock because we make sure it's called
1588 * with the tx_lock already acquired.
1589 * This come from the kernel's hard_xmit callback (through the ieee
1590 * stack, or from the try_wake_queue (again through the ieee stack.
1592 priority = AC2Q(skb->priority);
1593 spin_lock_irqsave(&priv->tx_lock, flags);
1595 if (priv->ieee80211->bHwRadioOff) {
1596 spin_unlock_irqrestore(&priv->tx_lock, flags);
1601 if (!check_nic_enought_desc(dev, priority)) {
1602 DMESGW("Error: no descriptor left by previous TX (avail %d) ",
1603 get_curr_tx_free_desc(dev, priority));
1604 ieee80211_rtl_stop_queue(priv->ieee80211);
1606 rtl8180_tx(dev, skb->data, skb->len, priority, morefrag, 0, rate);
1607 if (!check_nic_enought_desc(dev, priority))
1608 ieee80211_rtl_stop_queue(priv->ieee80211);
1610 spin_unlock_irqrestore(&priv->tx_lock, flags);
1614 * This is a rough attempt to TX a frame
1615 * This is called by the ieee 80211 stack to TX management frames.
1616 * If the ring is full packets are dropped (for data frame the queue
1617 * is stopped before this can happen). For this reason it is better
1618 * if the descriptors are larger than the largest management frame
1619 * we intend to TX: i'm unsure what the HW does if it will not find
1620 * the last fragment of a frame because it has been dropped...
1621 * Since queues for Management and Data frames are different we
1622 * might use a different lock than tx_lock (for example mgmt_tx_lock)
1624 /* these function may loop if invoked with 0 descriptors or 0 len buffer */
1625 static int rtl8180_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1627 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1628 unsigned long flags;
1631 priority = MANAGE_PRIORITY;
1633 spin_lock_irqsave(&priv->tx_lock, flags);
1635 if (priv->ieee80211->bHwRadioOff) {
1636 spin_unlock_irqrestore(&priv->tx_lock, flags);
1637 dev_kfree_skb_any(skb);
1638 return NETDEV_TX_OK;
1641 rtl8180_tx(dev, skb->data, skb->len, priority,
1642 0, 0, ieeerate2rtlrate(priv->ieee80211->basic_rate));
1644 priv->ieee80211->stats.tx_bytes += skb->len;
1645 priv->ieee80211->stats.tx_packets++;
1646 spin_unlock_irqrestore(&priv->tx_lock, flags);
1648 dev_kfree_skb_any(skb);
1649 return NETDEV_TX_OK;
1652 static void rtl8180_prepare_beacon(struct net_device *dev)
1654 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1655 struct sk_buff *skb;
1657 u16 word = read_nic_word(dev, BcnItv);
1658 word &= ~BcnItv_BcnItv; /* clear Bcn_Itv */
1661 word |= cpu_to_le16(priv->ieee80211->current_network.beacon_interval);
1663 write_nic_word(dev, BcnItv, word);
1665 skb = ieee80211_get_beacon(priv->ieee80211);
1667 rtl8180_tx(dev, skb->data, skb->len, BEACON_PRIORITY,
1668 0, 0, ieeerate2rtlrate(priv->ieee80211->basic_rate));
1669 dev_kfree_skb_any(skb);
1674 * This function do the real dirty work: it enqueues a TX command descriptor in
1675 * the ring buffer, copyes the frame in a TX buffer and kicks the NIC to ensure
1676 * it does the DMA transfer.
1678 short rtl8180_tx(struct net_device *dev, u8 *txbuf, int len, int priority,
1679 bool morefrag, short descfrag, int rate)
1681 struct r8180_priv *priv = ieee80211_priv(dev);
1682 u32 *tail, *temp_tail;
1689 struct buffer *buflist;
1690 struct ieee80211_hdr_3addr *frag_hdr =
1691 (struct ieee80211_hdr_3addr *)txbuf;
1693 u8 bUseShortPreamble = 0;
1698 u16 ThisFrameTime = 0;
1699 u16 TxDescDuration = 0;
1700 bool ownbit_flag = false;
1703 case MANAGE_PRIORITY:
1704 tail = priv->txmapringtail;
1705 begin = priv->txmapring;
1706 buflist = priv->txmapbufstail;
1707 count = priv->txringcount;
1710 tail = priv->txbkpringtail;
1711 begin = priv->txbkpring;
1712 buflist = priv->txbkpbufstail;
1713 count = priv->txringcount;
1716 tail = priv->txbepringtail;
1717 begin = priv->txbepring;
1718 buflist = priv->txbepbufstail;
1719 count = priv->txringcount;
1722 tail = priv->txvipringtail;
1723 begin = priv->txvipring;
1724 buflist = priv->txvipbufstail;
1725 count = priv->txringcount;
1728 tail = priv->txvopringtail;
1729 begin = priv->txvopring;
1730 buflist = priv->txvopbufstail;
1731 count = priv->txringcount;
1734 tail = priv->txhpringtail;
1735 begin = priv->txhpring;
1736 buflist = priv->txhpbufstail;
1737 count = priv->txringcount;
1739 case BEACON_PRIORITY:
1740 tail = priv->txbeaconringtail;
1741 begin = priv->txbeaconring;
1742 buflist = priv->txbeaconbufstail;
1743 count = priv->txbeaconcount;
1750 memcpy(&dest, frag_hdr->addr1, ETH_ALEN);
1751 if (is_multicast_ether_addr(dest)) {
1757 ThisFrameTime = ComputeTxTime(len + sCrcLng,
1758 rtl8180_rate2rate(rate), 0, bUseShortPreamble);
1759 TxDescDuration = ThisFrameTime;
1760 } else { /* Unicast packet */
1763 /* for Keep alive */
1764 priv->NumTxUnicast++;
1766 /* Figure out ACK rate according to BSS basic rate
1768 * AckCTSLng = 14 use 1M bps send
1770 AckTime = ComputeTxTime(14, 10, 0, 0);
1772 if (((len + sCrcLng) > priv->rts) && priv->rts) { /* RTS/CTS. */
1773 u16 RtsTime, CtsTime;
1777 /* Rate and time required for RTS. */
1778 RtsTime = ComputeTxTime(sAckCtsLng / 8,
1779 priv->ieee80211->basic_rate, 0, 0);
1781 /* Rate and time required for CTS.
1782 * AckCTSLng = 14 use 1M bps send
1784 CtsTime = ComputeTxTime(14, 10, 0, 0);
1786 /* Figure out time required to transmit this frame. */
1787 ThisFrameTime = ComputeTxTime(len + sCrcLng,
1788 rtl8180_rate2rate(rate), 0,
1791 /* RTS-CTS-ThisFrame-ACK. */
1792 RtsDur = CtsTime + ThisFrameTime +
1793 AckTime + 3 * aSifsTime;
1795 TxDescDuration = RtsTime + RtsDur;
1796 } else { /* Normal case. */
1801 ThisFrameTime = ComputeTxTime(len + sCrcLng,
1802 rtl8180_rate2rate(rate), 0, bUseShortPreamble);
1803 TxDescDuration = ThisFrameTime + aSifsTime + AckTime;
1806 if (!(le16_to_cpu(frag_hdr->frame_control) & IEEE80211_FCTL_MOREFRAGS)) {
1807 /* ThisFrame-ACK. */
1808 Duration = aSifsTime + AckTime;
1809 } else { /* One or more fragments remained. */
1812 /* pretend following packet length = current packet */
1813 NextFragTime = ComputeTxTime(len + sCrcLng,
1814 rtl8180_rate2rate(rate), 0, bUseShortPreamble);
1816 /* ThisFrag-ACk-NextFrag-ACK. */
1817 Duration = NextFragTime + 3 * aSifsTime + 2 * AckTime;
1820 } /* End of Unicast packet */
1822 frag_hdr->duration_id = Duration;
1824 buflen = priv->txbuffsize;
1828 while (remain != 0) {
1831 DMESGE("TX buffer error, cannot TX frames. pri %d.",
1837 if ((*tail & (1 << 31)) && (priority != BEACON_PRIORITY)) {
1838 DMESGW("No more TX desc, returning %x of %x",
1840 priv->stats.txrdu++;
1844 *tail = 0; /* zeroes header */
1851 /* FIXME: should be triggered by HW encryption parameters.*/
1852 *tail |= (1<<15); /* no encrypt */
1854 if (remain == len && !descfrag) {
1855 ownbit_flag = false;
1856 *tail = *tail | (1 << 29); /* first segment of packet */
1857 *tail = *tail | (len);
1862 for (i = 0; i < buflen && remain > 0; i++, remain--) {
1863 /* copy data into descriptor pointed DMAble buffer */
1864 ((u8 *)buf)[i] = txbuf[i];
1866 if (remain == 4 && i+4 >= buflen)
1868 /* ensure the last desc has at least 4 bytes payload */
1871 *(tail+3) = *(tail+3) & ~0xfff;
1872 *(tail+3) = *(tail+3) | i; /* buffer length */
1877 if (bRTSEnable) { /* rts enable */
1879 *tail |= (ieeerate2rtlrate(
1880 priv->ieee80211->basic_rate) << 19);
1882 *tail |= (1<<23); /* rts enable */
1883 *(tail+1) |= (RtsDur&0xffff); /* RTS Duration */
1885 *(tail+3) |= ((TxDescDuration&0xffff)<<16); /* DURATION */
1887 *(tail + 5) |= (11 << 8); /* retry lim; */
1889 *tail = *tail | ((rate&0xf) << 24);
1892 *tail = (*tail) | (1<<17); /* more fragment */
1894 *tail = (*tail) | (1<<28); /* last segment of frame */
1896 *(tail+5) = *(tail+5)|(2<<27);
1897 *(tail+7) = *(tail+7)|(1<<4);
1901 /* descriptor ready to be txed */
1904 if ((tail - begin)/8 == count-1)
1909 buflist = buflist->next;
1914 case MANAGE_PRIORITY:
1915 priv->txmapringtail = tail;
1916 priv->txmapbufstail = buflist;
1919 priv->txbkpringtail = tail;
1920 priv->txbkpbufstail = buflist;
1923 priv->txbepringtail = tail;
1924 priv->txbepbufstail = buflist;
1927 priv->txvipringtail = tail;
1928 priv->txvipbufstail = buflist;
1931 priv->txvopringtail = tail;
1932 priv->txvopbufstail = buflist;
1935 priv->txhpringtail = tail;
1936 priv->txhpbufstail = buflist;
1938 case BEACON_PRIORITY:
1940 * The HW seems to be happy with the 1st
1941 * descriptor filled and the 2nd empty...
1942 * So always update descriptor 1 and never
1948 *temp_tail = *temp_tail | (1<<31); /* descriptor ready to be txed */
1949 rtl8180_dma_kick(dev, priority);
1954 void rtl8180_irq_rx_tasklet(struct r8180_priv *priv);
1956 static void rtl8180_link_change(struct net_device *dev)
1958 struct r8180_priv *priv = ieee80211_priv(dev);
1959 u16 beacon_interval;
1960 struct ieee80211_network *net = &priv->ieee80211->current_network;
1962 rtl8180_update_msr(dev);
1964 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1966 write_nic_dword(dev, BSSID, ((u32 *)net->bssid)[0]);
1967 write_nic_word(dev, BSSID+4, ((u16 *)net->bssid)[2]);
1969 beacon_interval = read_nic_word(dev, BEACON_INTERVAL);
1970 beacon_interval &= ~BEACON_INTERVAL_MASK;
1971 beacon_interval |= net->beacon_interval;
1972 write_nic_word(dev, BEACON_INTERVAL, beacon_interval);
1974 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1976 rtl8180_set_chan(dev, priv->chan);
1979 static void rtl8180_rq_tx_ack(struct net_device *dev)
1982 struct r8180_priv *priv = ieee80211_priv(dev);
1984 write_nic_byte(dev, CONFIG4,
1985 read_nic_byte(dev, CONFIG4) | CONFIG4_PWRMGT);
1986 priv->ack_tx_to_ieee = 1;
1989 static short rtl8180_is_tx_queue_empty(struct net_device *dev)
1992 struct r8180_priv *priv = ieee80211_priv(dev);
1995 for (d = priv->txmapring;
1996 d < priv->txmapring + priv->txringcount; d += 8)
2000 for (d = priv->txbkpring;
2001 d < priv->txbkpring + priv->txringcount; d += 8)
2005 for (d = priv->txbepring;
2006 d < priv->txbepring + priv->txringcount; d += 8)
2010 for (d = priv->txvipring;
2011 d < priv->txvipring + priv->txringcount; d += 8)
2015 for (d = priv->txvopring;
2016 d < priv->txvopring + priv->txringcount; d += 8)
2020 for (d = priv->txhpring;
2021 d < priv->txhpring + priv->txringcount; d += 8)
2027 static void rtl8180_hw_wakeup(struct net_device *dev)
2029 unsigned long flags;
2030 struct r8180_priv *priv = ieee80211_priv(dev);
2032 spin_lock_irqsave(&priv->ps_lock, flags);
2033 write_nic_byte(dev, CONFIG4,
2034 read_nic_byte(dev, CONFIG4) & ~CONFIG4_PWRMGT);
2035 if (priv->rf_wakeup)
2036 priv->rf_wakeup(dev);
2037 spin_unlock_irqrestore(&priv->ps_lock, flags);
2040 static void rtl8180_hw_sleep_down(struct net_device *dev)
2042 unsigned long flags;
2043 struct r8180_priv *priv = ieee80211_priv(dev);
2045 spin_lock_irqsave(&priv->ps_lock, flags);
2047 priv->rf_sleep(dev);
2048 spin_unlock_irqrestore(&priv->ps_lock, flags);
2051 static void rtl8180_hw_sleep(struct net_device *dev, u32 th, u32 tl)
2053 struct r8180_priv *priv = ieee80211_priv(dev);
2055 unsigned long flags;
2057 spin_lock_irqsave(&priv->ps_lock, flags);
2060 * Writing HW register with 0 equals to disable
2061 * the timer, that is not really what we want
2063 tl -= MSECS(4+16+7);
2066 * If the interval in which we are requested to sleep is too
2067 * short then give up and remain awake
2069 if (((tl >= rb) && (tl-rb) <= MSECS(MIN_SLEEP_TIME))
2070 || ((rb > tl) && (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
2071 spin_unlock_irqrestore(&priv->ps_lock, flags);
2072 netdev_warn(dev, "too short to sleep\n");
2077 u32 tmp = (tl > rb) ? (tl-rb) : (rb-tl);
2079 priv->DozePeriodInPast2Sec += jiffies_to_msecs(tmp);
2080 /* as tl may be less than rb */
2081 queue_delayed_work(priv->ieee80211->wq,
2082 &priv->ieee80211->hw_wakeup_wq, tmp);
2085 * If we suspect the TimerInt is gone beyond tl
2086 * while setting it, then give up
2089 if (((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME))) ||
2090 ((tl < rb) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))) {
2091 spin_unlock_irqrestore(&priv->ps_lock, flags);
2095 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_sleep_wq);
2096 spin_unlock_irqrestore(&priv->ps_lock, flags);
2099 static void rtl8180_wmm_single_param_update(struct net_device *dev,
2100 u8 mode, AC_CODING eACI, PAC_PARAM param)
2105 /* Retrieve parameters to update. */
2106 /* Mode G/A: slotTimeTimer = 9; Mode B: 20 */
2107 u1bAIFS = param->f.AciAifsn.f.AIFSN * ((mode & IEEE_G) == IEEE_G ?
2108 9 : 20) + aSifsTime;
2109 u4bAcParam = (((u32)param->f.TXOPLimit << AC_PARAM_TXOP_LIMIT_OFFSET) |
2110 ((u32)param->f.Ecw.f.ECWmax << AC_PARAM_ECW_MAX_OFFSET) |
2111 ((u32)param->f.Ecw.f.ECWmin << AC_PARAM_ECW_MIN_OFFSET) |
2112 ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
2116 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
2119 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
2122 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
2125 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
2128 pr_warn("SetHwReg8185(): invalid ACI: %d!\n", eACI);
2133 static void rtl8180_wmm_param_update(struct work_struct *work)
2135 struct ieee80211_device *ieee = container_of(work,
2136 struct ieee80211_device, wmm_param_update_wq);
2137 struct net_device *dev = ieee->dev;
2138 u8 *ac_param = (u8 *)(ieee->current_network.wmm_param);
2139 u8 mode = ieee->current_network.mode;
2143 if (!ieee->current_network.QoS_Enable) {
2144 /* legacy ac_xx_param update */
2145 AcParam.longData = 0;
2146 AcParam.f.AciAifsn.f.AIFSN = 2; /* Follow 802.11 DIFS. */
2147 AcParam.f.AciAifsn.f.ACM = 0;
2148 AcParam.f.Ecw.f.ECWmin = 3; /* Follow 802.11 CWmin. */
2149 AcParam.f.Ecw.f.ECWmax = 7; /* Follow 802.11 CWmax. */
2150 AcParam.f.TXOPLimit = 0;
2152 for (eACI = 0; eACI < AC_MAX; eACI++) {
2153 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
2155 rtl8180_wmm_single_param_update(dev, mode, eACI,
2156 (PAC_PARAM)&AcParam);
2161 for (eACI = 0; eACI < AC_MAX; eACI++) {
2162 rtl8180_wmm_single_param_update(dev, mode,
2163 ((PAC_PARAM)ac_param)->f.AciAifsn.f.ACI,
2164 (PAC_PARAM)ac_param);
2166 ac_param += sizeof(AC_PARAM);
2170 void rtl8180_restart_wq(struct work_struct *work);
2171 void rtl8180_watch_dog_wq(struct work_struct *work);
2172 void rtl8180_hw_wakeup_wq(struct work_struct *work);
2173 void rtl8180_hw_sleep_wq(struct work_struct *work);
2174 void rtl8180_sw_antenna_wq(struct work_struct *work);
2175 void rtl8180_watch_dog(struct net_device *dev);
2177 static void watch_dog_adaptive(unsigned long data)
2179 struct r8180_priv *priv = ieee80211_priv((struct net_device *)data);
2182 DMESG("<----watch_dog_adaptive():driver is not up!\n");
2186 /* Tx High Power Mechanism. */
2187 if (CheckHighPower((struct net_device *)data))
2188 queue_work(priv->ieee80211->wq,
2189 (void *)&priv->ieee80211->tx_pw_wq);
2191 /* Tx Power Tracking on 87SE. */
2192 if (CheckTxPwrTracking((struct net_device *)data))
2193 TxPwrTracking87SE((struct net_device *)data);
2195 /* Perform DIG immediately. */
2196 if (CheckDig((struct net_device *)data))
2197 queue_work(priv->ieee80211->wq,
2198 (void *)&priv->ieee80211->hw_dig_wq);
2200 rtl8180_watch_dog((struct net_device *)data);
2202 queue_work(priv->ieee80211->wq,
2203 (void *)&priv->ieee80211->GPIOChangeRFWorkItem);
2205 priv->watch_dog_timer.expires = jiffies +
2206 MSECS(IEEE80211_WATCH_DOG_TIME);
2208 add_timer(&priv->watch_dog_timer);
2211 static struct rtl8187se_channel_list channel_plan_list[] = {
2213 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 36, 40,
2214 44, 48, 52, 56, 60, 64}, 19},
2217 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, 11},
2220 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40,
2221 44, 48, 52, 56, 60, 64}, 21},
2223 /* Spain. Change to ETSI. */
2224 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40,
2225 44, 48, 52, 56, 60, 64}, 21},
2227 /* France. Change to ETSI. */
2228 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40,
2229 44, 48, 52, 56, 60, 64}, 21},
2232 {{14, 36, 40, 44, 48, 52, 56, 60, 64}, 9},
2235 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 36,
2236 40, 44, 48, 52, 56, 60, 64}, 22},
2239 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 36, 40,
2240 44, 48, 52, 56, 60, 64}, 21},
2242 /* For 11a , TELEC */
2243 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 34, 38, 42, 46}, 17},
2245 /* For Global Domain. 1-11 active, 12-14 passive. */
2246 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, 14},
2248 /* world wide 13: ch1~ch11 active, ch12~13 passive */
2249 {{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, 13}
2252 static void rtl8180_set_channel_map(u8 channel_plan,
2253 struct ieee80211_device *ieee)
2257 ieee->MinPassiveChnlNum = MAX_CHANNEL_NUMBER+1;
2258 ieee->IbssStartChnl = 0;
2260 switch (channel_plan) {
2261 case COUNTRY_CODE_FCC:
2262 case COUNTRY_CODE_IC:
2263 case COUNTRY_CODE_ETSI:
2264 case COUNTRY_CODE_SPAIN:
2265 case COUNTRY_CODE_FRANCE:
2266 case COUNTRY_CODE_MKK:
2267 case COUNTRY_CODE_MKK1:
2268 case COUNTRY_CODE_ISRAEL:
2269 case COUNTRY_CODE_TELEC:
2272 ieee->bGlobalDomain = false;
2273 if (channel_plan_list[channel_plan].len != 0) {
2274 /* Clear old channel map */
2275 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
2276 /* Set new channel map */
2277 for (i = 0; i < channel_plan_list[channel_plan].len; i++) {
2278 if (channel_plan_list[channel_plan].channel[i] <= 14)
2279 GET_DOT11D_INFO(ieee)->channel_map[channel_plan_list[channel_plan].channel[i]] = 1;
2284 case COUNTRY_CODE_GLOBAL_DOMAIN:
2286 GET_DOT11D_INFO(ieee)->bEnabled = false;
2288 ieee->bGlobalDomain = true;
2291 case COUNTRY_CODE_WORLD_WIDE_13_INDEX:
2293 ieee->MinPassiveChnlNum = 12;
2294 ieee->IbssStartChnl = 10;
2300 ieee->bGlobalDomain = false;
2301 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
2302 for (i = 1; i <= 14; i++)
2303 GET_DOT11D_INFO(ieee)->channel_map[i] = 1;
2309 void GPIOChangeRFWorkItemCallBack(struct work_struct *work);
2311 static void rtl8180_statistics_init(struct stats *pstats)
2313 memset(pstats, 0, sizeof(struct stats));
2316 static void rtl8180_link_detect_init(struct link_detect_t *plink_detect)
2318 memset(plink_detect, 0, sizeof(struct link_detect_t));
2319 plink_detect->slot_num = DEFAULT_SLOT_NUM;
2322 static void rtl8187se_eeprom_register_read(struct eeprom_93cx6 *eeprom)
2324 struct net_device *dev = eeprom->data;
2325 u8 reg = read_nic_byte(dev, EPROM_CMD);
2327 eeprom->reg_data_in = reg & RTL818X_EEPROM_CMD_WRITE;
2328 eeprom->reg_data_out = reg & RTL818X_EEPROM_CMD_READ;
2329 eeprom->reg_data_clock = reg & RTL818X_EEPROM_CMD_CK;
2330 eeprom->reg_chip_select = reg & RTL818X_EEPROM_CMD_CS;
2333 static void rtl8187se_eeprom_register_write(struct eeprom_93cx6 *eeprom)
2335 struct net_device *dev = eeprom->data;
2338 if (eeprom->reg_data_in)
2339 reg |= RTL818X_EEPROM_CMD_WRITE;
2340 if (eeprom->reg_data_out)
2341 reg |= RTL818X_EEPROM_CMD_READ;
2342 if (eeprom->reg_data_clock)
2343 reg |= RTL818X_EEPROM_CMD_CK;
2344 if (eeprom->reg_chip_select)
2345 reg |= RTL818X_EEPROM_CMD_CS;
2347 write_nic_byte(dev, EPROM_CMD, reg);
2348 read_nic_byte(dev, EPROM_CMD);
2352 static short rtl8180_init(struct net_device *dev)
2354 struct r8180_priv *priv = ieee80211_priv(dev);
2359 struct eeprom_93cx6 eeprom;
2363 eeprom.register_read = rtl8187se_eeprom_register_read;
2364 eeprom.register_write = rtl8187se_eeprom_register_write;
2365 eeprom.width = PCI_EEPROM_WIDTH_93C46;
2367 eeprom_93cx6_read(&eeprom, EEPROM_COUNTRY_CODE>>1, &eeprom_val);
2368 priv->channel_plan = eeprom_val & 0xFF;
2369 if (priv->channel_plan > COUNTRY_CODE_GLOBAL_DOMAIN) {
2370 netdev_err(dev, "rtl8180_init: Invalid channel plan! Set to default.\n");
2371 priv->channel_plan = 0;
2374 DMESG("Channel plan is %d\n", priv->channel_plan);
2375 rtl8180_set_channel_map(priv->channel_plan, priv->ieee80211);
2377 /* FIXME: these constants are placed in a bad pleace. */
2378 priv->txbuffsize = 2048; /* 1024; */
2379 priv->txringcount = 32; /* 32; */
2380 priv->rxbuffersize = 2048; /* 1024; */
2381 priv->rxringcount = 64; /* 32; */
2382 priv->txbeaconcount = 2;
2383 priv->rx_skb_complete = 1;
2385 priv->RFChangeInProgress = false;
2386 priv->SetRFPowerStateInProgress = false;
2387 priv->RFProgType = 0;
2389 priv->irq_enabled = 0;
2391 rtl8180_statistics_init(&priv->stats);
2392 rtl8180_link_detect_init(&priv->link_detect);
2394 priv->ack_tx_to_ieee = 0;
2395 priv->ieee80211->current_network.beacon_interval =
2396 DEFAULT_BEACONINTERVAL;
2397 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2398 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
2399 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
2400 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;
2401 priv->ieee80211->active_scan = 1;
2402 priv->ieee80211->rate = 110; /* 11 mbps */
2403 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION;
2404 priv->ieee80211->host_encrypt = 1;
2405 priv->ieee80211->host_decrypt = 1;
2406 priv->ieee80211->sta_wake_up = rtl8180_hw_wakeup;
2407 priv->ieee80211->ps_request_tx_ack = rtl8180_rq_tx_ack;
2408 priv->ieee80211->enter_sleep_state = rtl8180_hw_sleep;
2409 priv->ieee80211->ps_is_queue_empty = rtl8180_is_tx_queue_empty;
2411 priv->hw_wep = hwwep;
2413 priv->retry_rts = DEFAULT_RETRY_RTS;
2414 priv->retry_data = DEFAULT_RETRY_DATA;
2415 priv->RFChangeInProgress = false;
2416 priv->SetRFPowerStateInProgress = false;
2417 priv->RFProgType = 0;
2418 priv->bInactivePs = true; /* false; */
2419 priv->ieee80211->bInactivePs = priv->bInactivePs;
2420 priv->bSwRfProcessing = false;
2421 priv->eRFPowerState = RF_OFF;
2422 priv->RfOffReason = 0;
2423 priv->led_strategy = SW_LED_MODE0;
2424 priv->TxPollingTimes = 0;
2425 priv->bLeisurePs = true;
2426 priv->dot11PowerSaveMode = ACTIVE;
2427 priv->AdMinCheckPeriod = 5;
2428 priv->AdMaxCheckPeriod = 10;
2429 priv->AdMaxRxSsThreshold = 30; /* 60->30 */
2430 priv->AdRxSsThreshold = 20; /* 50->20 */
2431 priv->AdCheckPeriod = priv->AdMinCheckPeriod;
2432 priv->AdTickCount = 0;
2433 priv->AdRxSignalStrength = -1;
2434 priv->RegSwAntennaDiversityMechanism = 0;
2435 priv->RegDefaultAntenna = 0;
2436 priv->SignalStrength = 0;
2437 priv->AdRxOkCnt = 0;
2438 priv->CurrAntennaIndex = 0;
2439 priv->AdRxSsBeforeSwitched = 0;
2440 init_timer(&priv->SwAntennaDiversityTimer);
2441 priv->SwAntennaDiversityTimer.data = (unsigned long)dev;
2442 priv->SwAntennaDiversityTimer.function =
2443 (void *)SwAntennaDiversityTimerCallback;
2444 priv->bDigMechanism = true;
2445 priv->InitialGain = 6;
2446 priv->bXtalCalibration = false;
2447 priv->XtalCal_Xin = 0;
2448 priv->XtalCal_Xout = 0;
2449 priv->bTxPowerTrack = false;
2450 priv->ThermalMeter = 0;
2451 priv->FalseAlarmRegValue = 0;
2452 priv->RegDigOfdmFaUpTh = 0xc; /* Upper threshold of OFDM false alarm,
2453 which is used in DIG. */
2454 priv->DIG_NumberFallbackVote = 0;
2455 priv->DIG_NumberUpgradeVote = 0;
2456 priv->LastSignalStrengthInPercent = 0;
2457 priv->Stats_SignalStrength = 0;
2458 priv->LastRxPktAntenna = 0;
2459 priv->SignalQuality = 0; /* in 0-100 index. */
2460 priv->Stats_SignalQuality = 0;
2461 priv->RecvSignalPower = 0; /* in dBm. */
2462 priv->Stats_RecvSignalPower = 0;
2463 priv->AdMainAntennaRxOkCnt = 0;
2464 priv->AdAuxAntennaRxOkCnt = 0;
2465 priv->bHWAdSwitched = false;
2466 priv->bRegHighPowerMechanism = true;
2467 priv->RegHiPwrUpperTh = 77;
2468 priv->RegHiPwrLowerTh = 75;
2469 priv->RegRSSIHiPwrUpperTh = 70;
2470 priv->RegRSSIHiPwrLowerTh = 20;
2471 priv->bCurCCKPkt = false;
2472 priv->UndecoratedSmoothedSS = -1;
2473 priv->bToUpdateTxPwr = false;
2474 priv->CurCCKRSSI = 0;
2477 priv->NumTxOkTotal = 0;
2478 priv->NumTxUnicast = 0;
2479 priv->keepAliveLevel = DEFAULT_KEEP_ALIVE_LEVEL;
2480 priv->CurrRetryCnt = 0;
2481 priv->LastRetryCnt = 0;
2482 priv->LastTxokCnt = 0;
2483 priv->LastRxokCnt = 0;
2484 priv->LastRetryRate = 0;
2485 priv->bTryuping = 0;
2486 priv->CurrTxRate = 0;
2487 priv->CurrRetryRate = 0;
2488 priv->TryupingCount = 0;
2489 priv->TryupingCountNoData = 0;
2490 priv->TryDownCountLowData = 0;
2491 priv->LastTxOKBytes = 0;
2492 priv->LastFailTxRate = 0;
2493 priv->LastFailTxRateSS = 0;
2494 priv->FailTxRateCount = 0;
2495 priv->LastTxThroughput = 0;
2496 priv->NumTxOkBytesTotal = 0;
2497 priv->ForcedDataRate = 0;
2498 priv->RegBModeGainStage = 1;
2500 priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
2501 spin_lock_init(&priv->irq_th_lock);
2502 spin_lock_init(&priv->tx_lock);
2503 spin_lock_init(&priv->ps_lock);
2504 spin_lock_init(&priv->rf_ps_lock);
2505 sema_init(&priv->wx_sem, 1);
2506 INIT_WORK(&priv->reset_wq, (void *)rtl8180_restart_wq);
2507 INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,
2508 (void *)rtl8180_hw_wakeup_wq);
2509 INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,
2510 (void *)rtl8180_hw_sleep_wq);
2511 INIT_WORK(&priv->ieee80211->wmm_param_update_wq,
2512 (void *)rtl8180_wmm_param_update);
2513 INIT_DELAYED_WORK(&priv->ieee80211->rate_adapter_wq,
2514 (void *)rtl8180_rate_adapter);
2515 INIT_DELAYED_WORK(&priv->ieee80211->hw_dig_wq,
2516 (void *)rtl8180_hw_dig_wq);
2517 INIT_DELAYED_WORK(&priv->ieee80211->tx_pw_wq,
2518 (void *)rtl8180_tx_pw_wq);
2519 INIT_DELAYED_WORK(&priv->ieee80211->GPIOChangeRFWorkItem,
2520 (void *) GPIOChangeRFWorkItemCallBack);
2521 tasklet_init(&priv->irq_rx_tasklet,
2522 (void(*)(unsigned long)) rtl8180_irq_rx_tasklet,
2523 (unsigned long)priv);
2525 init_timer(&priv->watch_dog_timer);
2526 priv->watch_dog_timer.data = (unsigned long)dev;
2527 priv->watch_dog_timer.function = watch_dog_adaptive;
2529 init_timer(&priv->rateadapter_timer);
2530 priv->rateadapter_timer.data = (unsigned long)dev;
2531 priv->rateadapter_timer.function = timer_rate_adaptive;
2532 priv->RateAdaptivePeriod = RATE_ADAPTIVE_TIMER_PERIOD;
2533 priv->bEnhanceTxPwr = false;
2535 priv->ieee80211->softmac_hard_start_xmit = rtl8180_hard_start_xmit;
2536 priv->ieee80211->set_chan = rtl8180_set_chan;
2537 priv->ieee80211->link_change = rtl8180_link_change;
2538 priv->ieee80211->softmac_data_hard_start_xmit = rtl8180_hard_data_xmit;
2539 priv->ieee80211->data_hard_stop = rtl8180_data_hard_stop;
2540 priv->ieee80211->data_hard_resume = rtl8180_data_hard_resume;
2542 priv->ieee80211->init_wmmparam_flag = 0;
2544 priv->ieee80211->start_send_beacons = rtl8180_start_tx_beacon;
2545 priv->ieee80211->stop_send_beacons = rtl8180_beacon_tx_disable;
2546 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
2548 priv->ShortRetryLimit = 7;
2549 priv->LongRetryLimit = 7;
2550 priv->EarlyRxThreshold = 7;
2552 priv->TransmitConfig = (1<<TCR_DurProcMode_OFFSET) |
2553 (7<<TCR_MXDMA_OFFSET) |
2554 (priv->ShortRetryLimit<<TCR_SRL_OFFSET) |
2555 (priv->LongRetryLimit<<TCR_LRL_OFFSET);
2557 priv->ReceiveConfig = RCR_AMF | RCR_ADF | RCR_ACF |
2558 RCR_AB | RCR_AM | RCR_APM |
2559 (7<<RCR_MXDMA_OFFSET) |
2560 (priv->EarlyRxThreshold<<RCR_FIFO_OFFSET) |
2561 (priv->EarlyRxThreshold == 7 ?
2562 RCR_ONLYERLPKT : 0);
2564 priv->IntrMask = IMR_TMGDOK | IMR_TBDER |
2565 IMR_THPDER | IMR_THPDOK |
2566 IMR_TVODER | IMR_TVODOK |
2567 IMR_TVIDER | IMR_TVIDOK |
2568 IMR_TBEDER | IMR_TBEDOK |
2569 IMR_TBKDER | IMR_TBKDOK |
2574 priv->InitialGain = 6;
2576 DMESG("MAC controller is a RTL8187SE b/g");
2578 priv->ieee80211->modulation |= IEEE80211_OFDM_MODULATION;
2579 priv->ieee80211->short_slot = 1;
2581 eeprom_93cx6_read(&eeprom, EEPROM_SW_REVD_OFFSET, &usValue);
2582 DMESG("usValue is %#hx\n", usValue);
2583 /* 3Read AntennaDiversity */
2585 /* SW Antenna Diversity. */
2586 priv->EEPROMSwAntennaDiversity = (usValue & EEPROM_SW_AD_MASK) ==
2587 EEPROM_SW_AD_ENABLE;
2589 /* Default Antenna to use. */
2590 priv->EEPROMDefaultAntenna1 = (usValue & EEPROM_DEF_ANT_MASK) ==
2593 if (priv->RegSwAntennaDiversityMechanism == 0) /* Auto */
2594 /* 0: default from EEPROM. */
2595 priv->bSwAntennaDiverity = priv->EEPROMSwAntennaDiversity;
2597 /* 1:disable antenna diversity, 2: enable antenna diversity. */
2598 priv->bSwAntennaDiverity =
2599 priv->RegSwAntennaDiversityMechanism == 2;
2601 if (priv->RegDefaultAntenna == 0)
2602 /* 0: default from EEPROM. */
2603 priv->bDefaultAntenna1 = priv->EEPROMDefaultAntenna1;
2605 /* 1: main, 2: aux. */
2606 priv->bDefaultAntenna1 = priv->RegDefaultAntenna == 2;
2608 priv->plcp_preamble_mode = 2;
2609 /* the eeprom type is stored in RCR register bit #6 */
2610 if (RCR_9356SEL & read_nic_dword(dev, RCR))
2611 priv->epromtype = EPROM_93c56;
2613 priv->epromtype = EPROM_93c46;
2615 eeprom_93cx6_multiread(&eeprom, 0x7, (__le16 *)
2618 for (i = 1, j = 0; i < 14; i += 2, j++) {
2619 eeprom_93cx6_read(&eeprom, EPROM_TXPW_CH1_2 + j, &word);
2620 priv->chtxpwr[i] = word & 0xff;
2621 priv->chtxpwr[i+1] = (word & 0xff00)>>8;
2623 for (i = 1, j = 0; i < 14; i += 2, j++) {
2624 eeprom_93cx6_read(&eeprom, EPROM_TXPW_OFDM_CH1_2 + j, &word);
2625 priv->chtxpwr_ofdm[i] = word & 0xff;
2626 priv->chtxpwr_ofdm[i+1] = (word & 0xff00) >> 8;
2629 /* 3Read crystal calibration and thermal meter indication on 87SE. */
2630 eeprom_93cx6_read(&eeprom, EEPROM_RSV>>1, &tmpu16);
2632 /* Crystal calibration for Xin and Xout resp. */
2633 priv->XtalCal_Xout = tmpu16 & EEPROM_XTAL_CAL_XOUT_MASK;
2634 priv->XtalCal_Xin = (tmpu16 & EEPROM_XTAL_CAL_XIN_MASK) >> 4;
2635 if ((tmpu16 & EEPROM_XTAL_CAL_ENABLE) >> 12)
2636 priv->bXtalCalibration = true;
2638 /* Thermal meter reference indication. */
2639 priv->ThermalMeter = (u8)((tmpu16 & EEPROM_THERMAL_METER_MASK) >> 8);
2640 if ((tmpu16 & EEPROM_THERMAL_METER_ENABLE) >> 13)
2641 priv->bTxPowerTrack = true;
2643 priv->rf_sleep = rtl8225z4_rf_sleep;
2644 priv->rf_wakeup = rtl8225z4_rf_wakeup;
2645 DMESGW("**PLEASE** REPORT SUCCESSFUL/UNSUCCESSFUL TO Realtek!");
2647 priv->rf_close = rtl8225z2_rf_close;
2648 priv->rf_init = rtl8225z2_rf_init;
2649 priv->rf_set_chan = rtl8225z2_rf_set_chan;
2650 priv->rf_set_sens = NULL;
2652 if (0 != alloc_rx_desc_ring(dev, priv->rxbuffersize, priv->rxringcount))
2655 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2656 TX_MANAGEPRIORITY_RING_ADDR))
2659 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2660 TX_BKPRIORITY_RING_ADDR))
2663 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2664 TX_BEPRIORITY_RING_ADDR))
2667 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2668 TX_VIPRIORITY_RING_ADDR))
2671 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2672 TX_VOPRIORITY_RING_ADDR))
2675 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2676 TX_HIGHPRIORITY_RING_ADDR))
2679 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txbeaconcount,
2680 TX_BEACON_RING_ADDR))
2683 if (request_irq(dev->irq, rtl8180_interrupt,
2684 IRQF_SHARED, dev->name, dev)) {
2685 DMESGE("Error allocating IRQ %d", dev->irq);
2688 priv->irq = dev->irq;
2689 DMESG("IRQ %d", dev->irq);
2695 void rtl8180_no_hw_wep(struct net_device *dev)
2699 void rtl8180_set_hw_wep(struct net_device *dev)
2701 struct r8180_priv *priv = ieee80211_priv(dev);
2706 pgreg = read_nic_byte(dev, PGSELECT);
2707 write_nic_byte(dev, PGSELECT, pgreg & ~(1<<PGSELECT_PG_SHIFT));
2709 key0_word4 = read_nic_dword(dev, KEY0+4+4+4);
2710 key0_word4 &= ~0xff;
2711 key0_word4 |= priv->key0[3] & 0xff;
2712 write_nic_dword(dev, KEY0, (priv->key0[0]));
2713 write_nic_dword(dev, KEY0+4, (priv->key0[1]));
2714 write_nic_dword(dev, KEY0+4+4, (priv->key0[2]));
2715 write_nic_dword(dev, KEY0+4+4+4, (key0_word4));
2717 security = read_nic_byte(dev, SECURITY);
2718 security |= (1<<SECURITY_WEP_TX_ENABLE_SHIFT);
2719 security |= (1<<SECURITY_WEP_RX_ENABLE_SHIFT);
2720 security &= ~SECURITY_ENCRYP_MASK;
2721 security |= (SECURITY_ENCRYP_104<<SECURITY_ENCRYP_SHIFT);
2723 write_nic_byte(dev, SECURITY, security);
2725 DMESG("key %x %x %x %x", read_nic_dword(dev, KEY0+4+4+4),
2726 read_nic_dword(dev, KEY0+4+4), read_nic_dword(dev, KEY0+4),
2727 read_nic_dword(dev, KEY0));
2731 void rtl8185_rf_pins_enable(struct net_device *dev)
2733 write_nic_word(dev, RFPinsEnable, 0x1fff); /* | tmp); */
2736 void rtl8185_set_anaparam2(struct net_device *dev, u32 a)
2740 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
2742 conf3 = read_nic_byte(dev, CONFIG3);
2743 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
2744 write_nic_dword(dev, ANAPARAM2, a);
2746 conf3 = read_nic_byte(dev, CONFIG3);
2747 write_nic_byte(dev, CONFIG3, conf3 & ~(1<<CONFIG3_ANAPARAM_W_SHIFT));
2748 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2751 void rtl8180_set_anaparam(struct net_device *dev, u32 a)
2755 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
2757 conf3 = read_nic_byte(dev, CONFIG3);
2758 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
2759 write_nic_dword(dev, ANAPARAM, a);
2761 conf3 = read_nic_byte(dev, CONFIG3);
2762 write_nic_byte(dev, CONFIG3, conf3 & ~(1<<CONFIG3_ANAPARAM_W_SHIFT));
2763 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2766 void rtl8185_tx_antenna(struct net_device *dev, u8 ant)
2768 write_nic_byte(dev, TX_ANTENNA, ant);
2769 force_pci_posting(dev);
2773 static void rtl8185_write_phy(struct net_device *dev, u8 adr, u32 data)
2779 phyw = ((data<<8) | adr);
2781 /* Note: we must write 0xff7c after 0x7d-0x7f to write BB register. */
2782 write_nic_byte(dev, 0x7f, ((phyw & 0xff000000) >> 24));
2783 write_nic_byte(dev, 0x7e, ((phyw & 0x00ff0000) >> 16));
2784 write_nic_byte(dev, 0x7d, ((phyw & 0x0000ff00) >> 8));
2785 write_nic_byte(dev, 0x7c, ((phyw & 0x000000ff)));
2788 inline void write_phy_ofdm(struct net_device *dev, u8 adr, u32 data)
2791 rtl8185_write_phy(dev, adr, data);
2794 void write_phy_cck(struct net_device *dev, u8 adr, u32 data)
2797 rtl8185_write_phy(dev, adr, data | 0x10000);
2801 * This configures registers for beacon tx and enables it via
2802 * rtl8180_beacon_tx_enable(). rtl8180_beacon_tx_disable() might
2803 * be used to stop beacon transmission
2805 void rtl8180_start_tx_beacon(struct net_device *dev)
2809 DMESG("Enabling beacon TX");
2810 rtl8180_prepare_beacon(dev);
2811 rtl8180_irq_disable(dev);
2812 rtl8180_beacon_tx_enable(dev);
2814 word = read_nic_word(dev, AtimWnd) & ~AtimWnd_AtimWnd;
2815 write_nic_word(dev, AtimWnd, word); /* word |= */
2817 word = read_nic_word(dev, BintrItv);
2818 word &= ~BintrItv_BintrItv;
2819 word |= 1000; /* priv->ieee80211->current_network.beacon_interval *
2820 * ((priv->txbeaconcount > 1)?(priv->txbeaconcount-1):1);
2821 * FIXME: check if correct ^^ worked with 0x3e8;
2823 write_nic_word(dev, BintrItv, word);
2825 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2827 rtl8185b_irq_enable(dev);
2830 static struct net_device_stats *rtl8180_stats(struct net_device *dev)
2832 struct r8180_priv *priv = ieee80211_priv(dev);
2834 return &priv->ieee80211->stats;
2838 * Change current and default preamble mode.
2840 static bool MgntActSet_802_11_PowerSaveMode(struct r8180_priv *priv,
2841 enum rt_ps_mode rtPsMode)
2843 /* Currently, we do not change power save mode on IBSS mode. */
2844 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
2847 priv->ieee80211->ps = rtPsMode;
2852 static void LeisurePSEnter(struct r8180_priv *priv)
2854 if (priv->bLeisurePs)
2855 if (priv->ieee80211->ps == IEEE80211_PS_DISABLED)
2856 /* IEEE80211_PS_ENABLE */
2857 MgntActSet_802_11_PowerSaveMode(priv,
2858 IEEE80211_PS_MBCAST | IEEE80211_PS_UNICAST);
2861 static void LeisurePSLeave(struct r8180_priv *priv)
2863 if (priv->bLeisurePs)
2864 if (priv->ieee80211->ps != IEEE80211_PS_DISABLED)
2865 MgntActSet_802_11_PowerSaveMode(
2866 priv, IEEE80211_PS_DISABLED);
2869 void rtl8180_hw_wakeup_wq(struct work_struct *work)
2871 struct delayed_work *dwork = to_delayed_work(work);
2872 struct ieee80211_device *ieee = container_of(
2873 dwork, struct ieee80211_device, hw_wakeup_wq);
2874 struct net_device *dev = ieee->dev;
2876 rtl8180_hw_wakeup(dev);
2879 void rtl8180_hw_sleep_wq(struct work_struct *work)
2881 struct delayed_work *dwork = to_delayed_work(work);
2882 struct ieee80211_device *ieee = container_of(
2883 dwork, struct ieee80211_device, hw_sleep_wq);
2884 struct net_device *dev = ieee->dev;
2886 rtl8180_hw_sleep_down(dev);
2889 static void MgntLinkKeepAlive(struct r8180_priv *priv)
2891 if (priv->keepAliveLevel == 0)
2894 if (priv->ieee80211->state == IEEE80211_LINKED) {
2899 if ((priv->keepAliveLevel == 2) ||
2900 (priv->link_detect.last_num_tx_unicast ==
2901 priv->NumTxUnicast &&
2902 priv->link_detect.last_num_rx_unicast ==
2903 priv->ieee80211->NumRxUnicast)
2905 priv->link_detect.idle_count++;
2908 * Send a Keep-Alive packet packet to AP if we had
2909 * been idle for a while.
2911 if (priv->link_detect.idle_count >=
2912 KEEP_ALIVE_INTERVAL /
2913 CHECK_FOR_HANG_PERIOD - 1) {
2914 priv->link_detect.idle_count = 0;
2915 ieee80211_sta_ps_send_null_frame(
2916 priv->ieee80211, false);
2919 priv->link_detect.idle_count = 0;
2921 priv->link_detect.last_num_tx_unicast = priv->NumTxUnicast;
2922 priv->link_detect.last_num_rx_unicast =
2923 priv->ieee80211->NumRxUnicast;
2927 void rtl8180_watch_dog(struct net_device *dev)
2929 struct r8180_priv *priv = ieee80211_priv(dev);
2930 bool bEnterPS = false;
2931 bool bBusyTraffic = false;
2935 if (priv->ieee80211->actscanning == false) {
2936 if ((priv->ieee80211->iw_mode != IW_MODE_ADHOC) &&
2937 (priv->ieee80211->state == IEEE80211_NOLINK) &&
2938 (priv->ieee80211->beinretry == false) &&
2939 (priv->eRFPowerState == RF_ON))
2942 if ((priv->ieee80211->state == IEEE80211_LINKED) &&
2943 (priv->ieee80211->iw_mode == IW_MODE_INFRA)) {
2944 SlotIndex = (priv->link_detect.slot_index++) %
2945 priv->link_detect.slot_num;
2947 priv->link_detect.rx_frame_num[SlotIndex] =
2948 priv->ieee80211->NumRxDataInPeriod +
2949 priv->ieee80211->NumRxBcnInPeriod;
2951 for (i = 0; i < priv->link_detect.slot_num; i++)
2952 TotalRxNum += priv->link_detect.rx_frame_num[i];
2954 if (TotalRxNum == 0) {
2955 priv->ieee80211->state = IEEE80211_ASSOCIATING;
2956 queue_work(priv->ieee80211->wq,
2957 &priv->ieee80211->associate_procedure_wq);
2961 MgntLinkKeepAlive(priv);
2963 LeisurePSLeave(priv);
2965 if (priv->ieee80211->state == IEEE80211_LINKED) {
2966 priv->link_detect.num_rx_ok_in_period =
2967 priv->ieee80211->NumRxDataInPeriod;
2968 if (priv->link_detect.num_rx_ok_in_period > 666 ||
2969 priv->link_detect.num_tx_ok_in_period > 666) {
2970 bBusyTraffic = true;
2972 if ((priv->link_detect.num_rx_ok_in_period +
2973 priv->link_detect.num_tx_ok_in_period > 8)
2974 || (priv->link_detect.num_rx_ok_in_period > 2)) {
2980 LeisurePSEnter(priv);
2982 LeisurePSLeave(priv);
2984 LeisurePSLeave(priv);
2985 priv->link_detect.b_busy_traffic = bBusyTraffic;
2986 priv->link_detect.num_rx_ok_in_period = 0;
2987 priv->link_detect.num_tx_ok_in_period = 0;
2988 priv->ieee80211->NumRxDataInPeriod = 0;
2989 priv->ieee80211->NumRxBcnInPeriod = 0;
2992 static int _rtl8180_up(struct net_device *dev)
2994 struct r8180_priv *priv = ieee80211_priv(dev);
2998 DMESG("Bringing up iface");
2999 rtl8185b_adapter_start(dev);
3000 rtl8185b_rx_enable(dev);
3001 rtl8185b_tx_enable(dev);
3002 if (priv->bInactivePs) {
3003 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3006 timer_rate_adaptive((unsigned long)dev);
3007 watch_dog_adaptive((unsigned long)dev);
3008 if (priv->bSwAntennaDiverity)
3009 SwAntennaDiversityTimerCallback(dev);
3010 ieee80211_softmac_start_protocol(priv->ieee80211);
3014 static int rtl8180_open(struct net_device *dev)
3016 struct r8180_priv *priv = ieee80211_priv(dev);
3019 down(&priv->wx_sem);
3020 ret = rtl8180_up(dev);
3025 int rtl8180_up(struct net_device *dev)
3027 struct r8180_priv *priv = ieee80211_priv(dev);
3032 return _rtl8180_up(dev);
3035 static int rtl8180_close(struct net_device *dev)
3037 struct r8180_priv *priv = ieee80211_priv(dev);
3040 down(&priv->wx_sem);
3041 ret = rtl8180_down(dev);
3047 int rtl8180_down(struct net_device *dev)
3049 struct r8180_priv *priv = ieee80211_priv(dev);
3056 ieee80211_softmac_stop_protocol(priv->ieee80211);
3058 if (!netif_queue_stopped(dev))
3059 netif_stop_queue(dev);
3060 rtl8180_rtx_disable(dev);
3061 rtl8180_irq_disable(dev);
3062 del_timer_sync(&priv->watch_dog_timer);
3063 del_timer_sync(&priv->rateadapter_timer);
3064 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
3065 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
3066 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
3067 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
3068 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
3069 del_timer_sync(&priv->SwAntennaDiversityTimer);
3070 SetZebraRFPowerState8185(dev, RF_OFF);
3071 memset(&priv->ieee80211->current_network,
3072 0, sizeof(struct ieee80211_network));
3073 priv->ieee80211->state = IEEE80211_NOLINK;
3077 void rtl8180_restart_wq(struct work_struct *work)
3079 struct r8180_priv *priv = container_of(
3080 work, struct r8180_priv, reset_wq);
3081 struct net_device *dev = priv->dev;
3083 down(&priv->wx_sem);
3085 rtl8180_commit(dev);
3090 static void rtl8180_restart(struct net_device *dev)
3092 struct r8180_priv *priv = ieee80211_priv(dev);
3094 schedule_work(&priv->reset_wq);
3097 void rtl8180_commit(struct net_device *dev)
3099 struct r8180_priv *priv = ieee80211_priv(dev);
3104 del_timer_sync(&priv->watch_dog_timer);
3105 del_timer_sync(&priv->rateadapter_timer);
3106 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
3107 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
3108 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
3109 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
3110 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
3111 del_timer_sync(&priv->SwAntennaDiversityTimer);
3112 ieee80211_softmac_stop_protocol(priv->ieee80211);
3113 rtl8180_irq_disable(dev);
3114 rtl8180_rtx_disable(dev);
3118 static void r8180_set_multicast(struct net_device *dev)
3120 struct r8180_priv *priv = ieee80211_priv(dev);
3123 promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
3125 if (promisc != priv->promisc)
3126 rtl8180_restart(dev);
3128 priv->promisc = promisc;
3131 static int r8180_set_mac_adr(struct net_device *dev, void *mac)
3133 struct r8180_priv *priv = ieee80211_priv(dev);
3134 struct sockaddr *addr = mac;
3136 down(&priv->wx_sem);
3138 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
3140 if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
3141 memcpy(priv->ieee80211->current_network.bssid,
3142 dev->dev_addr, ETH_ALEN);
3154 /* based on ipw2200 driver */
3155 static int rtl8180_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3157 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3158 struct iwreq *wrq = (struct iwreq *) rq;
3162 case RTL_IOCTL_WPA_SUPPLICANT:
3163 ret = ieee80211_wpa_supplicant_ioctl(
3164 priv->ieee80211, &wrq->u.data);
3173 static const struct net_device_ops rtl8180_netdev_ops = {
3174 .ndo_open = rtl8180_open,
3175 .ndo_stop = rtl8180_close,
3176 .ndo_get_stats = rtl8180_stats,
3177 .ndo_tx_timeout = rtl8180_restart,
3178 .ndo_do_ioctl = rtl8180_ioctl,
3179 .ndo_set_rx_mode = r8180_set_multicast,
3180 .ndo_set_mac_address = r8180_set_mac_adr,
3181 .ndo_validate_addr = eth_validate_addr,
3182 .ndo_change_mtu = eth_change_mtu,
3183 .ndo_start_xmit = ieee80211_rtl_xmit,
3186 static int rtl8180_pci_probe(struct pci_dev *pdev,
3187 const struct pci_device_id *id)
3189 unsigned long ioaddr = 0;
3190 struct net_device *dev = NULL;
3191 struct r8180_priv *priv = NULL;
3195 unsigned long pmem_start, pmem_len, pmem_flags;
3197 DMESG("Configuring chip resources");
3199 if (pci_enable_device(pdev)) {
3200 DMESG("Failed to enable PCI device");
3204 pci_set_master(pdev);
3205 pci_set_dma_mask(pdev, 0xffffff00ULL);
3206 pci_set_consistent_dma_mask(pdev, 0xffffff00ULL);
3207 dev = alloc_ieee80211(sizeof(struct r8180_priv));
3212 priv = ieee80211_priv(dev);
3213 priv->ieee80211 = netdev_priv(dev);
3215 pci_set_drvdata(pdev, dev);
3216 SET_NETDEV_DEV(dev, &pdev->dev);
3218 priv = ieee80211_priv(dev);
3221 pmem_start = pci_resource_start(pdev, 1);
3222 pmem_len = pci_resource_len(pdev, 1);
3223 pmem_flags = pci_resource_flags(pdev, 1);
3225 if (!(pmem_flags & IORESOURCE_MEM)) {
3226 DMESG("region #1 not a MMIO resource, aborting");
3230 if (!request_mem_region(pmem_start, pmem_len, RTL8180_MODULE_NAME)) {
3231 DMESG("request_mem_region failed!");
3235 ioaddr = (unsigned long)ioremap_nocache(pmem_start, pmem_len);
3236 if (ioaddr == (unsigned long)NULL) {
3237 DMESG("ioremap failed!");
3241 dev->mem_start = ioaddr; /* shared mem start */
3242 dev->mem_end = ioaddr + pci_resource_len(pdev, 0); /* shared mem end */
3244 pci_read_config_byte(pdev, 0x05, &unit);
3245 pci_write_config_byte(pdev, 0x05, unit & (~0x04));
3247 dev->irq = pdev->irq;
3250 dev->netdev_ops = &rtl8180_netdev_ops;
3251 dev->wireless_handlers = &r8180_wx_handlers_def;
3253 dev->type = ARPHRD_ETHER;
3254 dev->watchdog_timeo = HZ*3;
3256 if (dev_alloc_name(dev, ifname) < 0) {
3257 DMESG("Oops: devname already taken! Trying wlan%%d...\n");
3258 strcpy(ifname, "wlan%d");
3259 dev_alloc_name(dev, ifname);
3262 if (rtl8180_init(dev) != 0) {
3263 DMESG("Initialization failed");
3267 netif_carrier_off(dev);
3269 if (register_netdev(dev))
3272 rtl8180_proc_init_one(dev);
3274 DMESG("Driver probe completed\n");
3277 if (dev->mem_start != (unsigned long)NULL) {
3278 iounmap((void __iomem *)dev->mem_start);
3279 release_mem_region(pci_resource_start(pdev, 1),
3280 pci_resource_len(pdev, 1));
3285 free_irq(dev->irq, dev);
3288 free_ieee80211(dev);
3292 pci_disable_device(pdev);
3294 DMESG("wlan driver load failed\n");
3298 static void rtl8180_pci_remove(struct pci_dev *pdev)
3300 struct r8180_priv *priv;
3301 struct net_device *dev = pci_get_drvdata(pdev);
3304 unregister_netdev(dev);
3306 priv = ieee80211_priv(dev);
3308 rtl8180_proc_remove_one(dev);
3310 priv->rf_close(dev);
3315 DMESG("Freeing irq %d", dev->irq);
3316 free_irq(dev->irq, dev);
3320 free_rx_desc_ring(dev);
3321 free_tx_desc_rings(dev);
3323 if (dev->mem_start != (unsigned long)NULL) {
3324 iounmap((void __iomem *)dev->mem_start);
3325 release_mem_region(pci_resource_start(pdev, 1),
3326 pci_resource_len(pdev, 1));
3329 free_ieee80211(dev);
3331 pci_disable_device(pdev);
3333 DMESG("wlan driver removed\n");
3336 static int __init rtl8180_pci_module_init(void)
3340 ret = ieee80211_crypto_init();
3342 pr_err("ieee80211_crypto_init() failed %d\n", ret);
3345 ret = ieee80211_crypto_tkip_init();
3347 pr_err("ieee80211_crypto_tkip_init() failed %d\n", ret);
3350 ret = ieee80211_crypto_ccmp_init();
3352 pr_err("ieee80211_crypto_ccmp_init() failed %d\n", ret);
3355 ret = ieee80211_crypto_wep_init();
3357 pr_err("ieee80211_crypto_wep_init() failed %d\n", ret);
3361 pr_info("\nLinux kernel driver for RTL8180 / RTL8185 based WLAN cards\n");
3362 pr_info("Copyright (c) 2004-2005, Andrea Merello\n");
3363 DMESG("Initializing module");
3364 DMESG("Wireless extensions version %d", WIRELESS_EXT);
3365 rtl8180_proc_module_init();
3367 if (pci_register_driver(&rtl8180_pci_driver)) {
3368 DMESG("No device found");
3374 static void __exit rtl8180_pci_module_exit(void)
3376 pci_unregister_driver(&rtl8180_pci_driver);
3377 rtl8180_proc_module_remove();
3378 ieee80211_crypto_tkip_exit();
3379 ieee80211_crypto_ccmp_exit();
3380 ieee80211_crypto_wep_exit();
3381 ieee80211_crypto_deinit();
3385 static void rtl8180_try_wake_queue(struct net_device *dev, int pri)
3387 unsigned long flags;
3389 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3391 spin_lock_irqsave(&priv->tx_lock, flags);
3392 enough_desc = check_nic_enought_desc(dev, pri);
3393 spin_unlock_irqrestore(&priv->tx_lock, flags);
3396 ieee80211_rtl_wake_queue(priv->ieee80211);
3399 static void rtl8180_tx_isr(struct net_device *dev, int pri, short error)
3401 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3402 u32 *tail; /* tail virtual addr */
3403 u32 *head; /* head virtual addr */
3404 u32 *begin; /* start of ring virtual addr */
3405 u32 *nicv; /* nic pointer virtual addr */
3406 u32 nic; /* nic pointer physical addr */
3407 u32 nicbegin; /* start of ring physical addr */
3409 /* physical addr are ok on 32 bits since we set DMA mask */
3414 priv->stats.txretry++;
3415 spin_lock_irqsave(&priv->tx_lock, flag);
3417 case MANAGE_PRIORITY:
3418 tail = priv->txmapringtail;
3419 begin = priv->txmapring;
3420 head = priv->txmapringhead;
3421 nic = read_nic_dword(dev, TX_MANAGEPRIORITY_RING_ADDR);
3422 nicbegin = priv->txmapringdma;
3425 tail = priv->txbkpringtail;
3426 begin = priv->txbkpring;
3427 head = priv->txbkpringhead;
3428 nic = read_nic_dword(dev, TX_BKPRIORITY_RING_ADDR);
3429 nicbegin = priv->txbkpringdma;
3432 tail = priv->txbepringtail;
3433 begin = priv->txbepring;
3434 head = priv->txbepringhead;
3435 nic = read_nic_dword(dev, TX_BEPRIORITY_RING_ADDR);
3436 nicbegin = priv->txbepringdma;
3439 tail = priv->txvipringtail;
3440 begin = priv->txvipring;
3441 head = priv->txvipringhead;
3442 nic = read_nic_dword(dev, TX_VIPRIORITY_RING_ADDR);
3443 nicbegin = priv->txvipringdma;
3446 tail = priv->txvopringtail;
3447 begin = priv->txvopring;
3448 head = priv->txvopringhead;
3449 nic = read_nic_dword(dev, TX_VOPRIORITY_RING_ADDR);
3450 nicbegin = priv->txvopringdma;
3453 tail = priv->txhpringtail;
3454 begin = priv->txhpring;
3455 head = priv->txhpringhead;
3456 nic = read_nic_dword(dev, TX_HIGHPRIORITY_RING_ADDR);
3457 nicbegin = priv->txhpringdma;
3461 spin_unlock_irqrestore(&priv->tx_lock, flag);
3465 nicv = (u32 *)((nic - nicbegin) + (u8 *)begin);
3466 if ((head <= tail && (nicv > tail || nicv < head)) ||
3467 (head > tail && (nicv > tail && nicv < head))) {
3468 DMESGW("nic has lost pointer");
3469 spin_unlock_irqrestore(&priv->tx_lock, flag);
3470 rtl8180_restart(dev);
3475 * We check all the descriptors between the head and the nic,
3476 * but not the currently pointed by the nic (the next to be txed)
3477 * and the previous of the pointed (might be in process ??)
3479 offs = (nic - nicbegin);
3480 offs = offs / 8 / 4;
3481 hd = (head - begin) / 8;
3486 j = offs + (priv->txringcount-1-hd);
3492 for (i = 0; i < j; i++) {
3493 if ((*head) & (1<<31))
3495 if (((*head)&(0x10000000)) != 0) {
3496 priv->CurrRetryCnt += (u16)((*head) & (0x000000ff));
3498 priv->NumTxOkTotal++;
3502 priv->NumTxOkBytesTotal += (*(head+3)) & (0x00000fff);
3504 *head = *head & ~(1<<31);
3506 if ((head - begin)/8 == priv->txringcount-1)
3513 * The head has been moved to the last certainly TXed
3514 * (or at least processed by the nic) packet.
3515 * The driver take forcefully owning of all these packets
3516 * If the packet previous of the nic pointer has been
3517 * processed this doesn't matter: it will be checked
3518 * here at the next round. Anyway if no more packet are
3519 * TXed no memory leak occur at all.
3523 case MANAGE_PRIORITY:
3524 priv->txmapringhead = head;
3526 if (priv->ack_tx_to_ieee) {
3527 if (rtl8180_is_tx_queue_empty(dev)) {
3528 priv->ack_tx_to_ieee = 0;
3529 ieee80211_ps_tx_ack(priv->ieee80211, !error);
3534 priv->txbkpringhead = head;
3537 priv->txbepringhead = head;
3540 priv->txvipringhead = head;
3543 priv->txvopringhead = head;
3546 priv->txhpringhead = head;
3550 spin_unlock_irqrestore(&priv->tx_lock, flag);
3553 static irqreturn_t rtl8180_interrupt(int irq, void *netdev)
3555 struct net_device *dev = (struct net_device *) netdev;
3556 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3557 unsigned long flags;
3560 /* We should return IRQ_NONE, but for now let me keep this */
3561 if (priv->irq_enabled == 0)
3564 spin_lock_irqsave(&priv->irq_th_lock, flags);
3567 inta = read_nic_dword(dev, ISR);
3568 write_nic_dword(dev, ISR, inta); /* reset int situation */
3570 priv->stats.shints++;
3573 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3576 * most probably we can safely return IRQ_NONE,
3577 * but for now is better to avoid problems
3581 if (inta == 0xffff) {
3582 /* HW disappeared */
3583 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3589 if (!netif_running(dev)) {
3590 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3594 if (inta & ISR_TimeOut)
3595 write_nic_dword(dev, TimerInt, 0);
3597 if (inta & ISR_TBDOK)
3598 priv->stats.txbeacon++;
3600 if (inta & ISR_TBDER)
3601 priv->stats.txbeaconerr++;
3603 if (inta & IMR_TMGDOK)
3604 rtl8180_tx_isr(dev, MANAGE_PRIORITY, 0);
3606 if (inta & ISR_THPDER) {
3607 priv->stats.txhperr++;
3608 rtl8180_tx_isr(dev, HI_PRIORITY, 1);
3609 priv->ieee80211->stats.tx_errors++;
3612 if (inta & ISR_THPDOK) { /* High priority tx ok */
3613 priv->link_detect.num_tx_ok_in_period++;
3614 priv->stats.txhpokint++;
3615 rtl8180_tx_isr(dev, HI_PRIORITY, 0);
3619 priv->stats.rxerr++;
3621 if (inta & ISR_TBKDER) { /* corresponding to BK_PRIORITY */
3622 priv->stats.txbkperr++;
3623 priv->ieee80211->stats.tx_errors++;
3624 rtl8180_tx_isr(dev, BK_PRIORITY, 1);
3625 rtl8180_try_wake_queue(dev, BK_PRIORITY);
3628 if (inta & ISR_TBEDER) { /* corresponding to BE_PRIORITY */
3629 priv->stats.txbeperr++;
3630 priv->ieee80211->stats.tx_errors++;
3631 rtl8180_tx_isr(dev, BE_PRIORITY, 1);
3632 rtl8180_try_wake_queue(dev, BE_PRIORITY);
3634 if (inta & ISR_TNPDER) { /* corresponding to VO_PRIORITY */
3635 priv->stats.txnperr++;
3636 priv->ieee80211->stats.tx_errors++;
3637 rtl8180_tx_isr(dev, NORM_PRIORITY, 1);
3638 rtl8180_try_wake_queue(dev, NORM_PRIORITY);
3641 if (inta & ISR_TLPDER) { /* corresponding to VI_PRIORITY */
3642 priv->stats.txlperr++;
3643 priv->ieee80211->stats.tx_errors++;
3644 rtl8180_tx_isr(dev, LOW_PRIORITY, 1);
3645 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
3648 if (inta & ISR_ROK) {
3649 priv->stats.rxint++;
3650 tasklet_schedule(&priv->irq_rx_tasklet);
3653 if (inta & ISR_RQoSOK) {
3654 priv->stats.rxint++;
3655 tasklet_schedule(&priv->irq_rx_tasklet);
3658 if (inta & ISR_BcnInt)
3659 rtl8180_prepare_beacon(dev);
3661 if (inta & ISR_RDU) {
3662 DMESGW("No RX descriptor available");
3663 priv->stats.rxrdu++;
3664 tasklet_schedule(&priv->irq_rx_tasklet);
3667 if (inta & ISR_RXFOVW) {
3668 priv->stats.rxoverflow++;
3669 tasklet_schedule(&priv->irq_rx_tasklet);
3672 if (inta & ISR_TXFOVW)
3673 priv->stats.txoverflow++;
3675 if (inta & ISR_TNPDOK) { /* Normal priority tx ok */
3676 priv->link_detect.num_tx_ok_in_period++;
3677 priv->stats.txnpokint++;
3678 rtl8180_tx_isr(dev, NORM_PRIORITY, 0);
3679 rtl8180_try_wake_queue(dev, NORM_PRIORITY);
3682 if (inta & ISR_TLPDOK) { /* Low priority tx ok */
3683 priv->link_detect.num_tx_ok_in_period++;
3684 priv->stats.txlpokint++;
3685 rtl8180_tx_isr(dev, LOW_PRIORITY, 0);
3686 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
3689 if (inta & ISR_TBKDOK) { /* corresponding to BK_PRIORITY */
3690 priv->stats.txbkpokint++;
3691 priv->link_detect.num_tx_ok_in_period++;
3692 rtl8180_tx_isr(dev, BK_PRIORITY, 0);
3693 rtl8180_try_wake_queue(dev, BE_PRIORITY);
3696 if (inta & ISR_TBEDOK) { /* corresponding to BE_PRIORITY */
3697 priv->stats.txbeperr++;
3698 priv->link_detect.num_tx_ok_in_period++;
3699 rtl8180_tx_isr(dev, BE_PRIORITY, 0);
3700 rtl8180_try_wake_queue(dev, BE_PRIORITY);
3702 force_pci_posting(dev);
3703 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3708 void rtl8180_irq_rx_tasklet(struct r8180_priv *priv)
3710 rtl8180_rx(priv->dev);
3713 void GPIOChangeRFWorkItemCallBack(struct work_struct *work)
3715 struct ieee80211_device *ieee = container_of(
3716 work, struct ieee80211_device, GPIOChangeRFWorkItem.work);
3717 struct net_device *dev = ieee->dev;
3718 struct r8180_priv *priv = ieee80211_priv(dev);
3721 enum rt_rf_power_state eRfPowerStateToSet;
3722 bool bActuallySet = false;
3725 static char *RadioPowerPath = "/etc/acpi/events/RadioPower.sh";
3726 static char *envp[] = {"HOME=/", "TERM=linux",
3727 "PATH=/usr/bin:/bin", NULL};
3728 static int readf_count;
3730 readf_count = (readf_count+1)%0xffff;
3731 /* We should turn off LED before polling FF51[4]. */
3734 btPSR = read_nic_byte(dev, PSR);
3735 write_nic_byte(dev, PSR, (btPSR & ~BIT3));
3737 /* It need to delay 4us suggested */
3740 /* HW radio On/Off according to the value of FF51[4](config0) */
3741 btConfig0 = btPSR = read_nic_byte(dev, CONFIG0);
3743 eRfPowerStateToSet = (btConfig0 & BIT4) ? RF_ON : RF_OFF;
3745 /* Turn LED back on when radio enabled */
3746 if (eRfPowerStateToSet == RF_ON)
3747 write_nic_byte(dev, PSR, btPSR | BIT3);
3749 if ((priv->ieee80211->bHwRadioOff == true) &&
3750 (eRfPowerStateToSet == RF_ON)) {
3751 priv->ieee80211->bHwRadioOff = false;
3752 bActuallySet = true;
3753 } else if ((priv->ieee80211->bHwRadioOff == false) &&
3754 (eRfPowerStateToSet == RF_OFF)) {
3755 priv->ieee80211->bHwRadioOff = true;
3756 bActuallySet = true;
3760 MgntActSet_RF_State(dev, eRfPowerStateToSet, RF_CHANGE_BY_HW);
3762 /* To update the UI status for Power status changed */
3763 if (priv->ieee80211->bHwRadioOff == true)
3767 argv[0] = RadioPowerPath;
3770 call_usermodehelper(RadioPowerPath, argv, envp, UMH_WAIT_PROC);
3774 module_init(rtl8180_pci_module_init);
3775 module_exit(rtl8180_pci_module_exit);