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.
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>
42 #include "r8180_rtl8225.h" /* RTL8225 Radio frontend */
43 #include "r8180_93cx6.h" /* Card EEPROM */
47 #include "ieee80211/dot11d.h"
49 static struct pci_device_id rtl8180_pci_id_tbl[] = {
51 .vendor = PCI_VENDOR_ID_REALTEK,
53 .subvendor = PCI_ANY_ID,
54 .subdevice = PCI_ANY_ID,
66 static char ifname[IFNAMSIZ] = "wlan%d";
69 MODULE_LICENSE("GPL");
70 MODULE_DEVICE_TABLE(pci, rtl8180_pci_id_tbl);
71 MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>");
72 MODULE_DESCRIPTION("Linux driver for Realtek RTL8187SE WiFi cards");
74 module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR);
75 module_param(hwwep, int, S_IRUGO|S_IWUSR);
77 MODULE_PARM_DESC(hwwep, " Try to use hardware WEP support. Still broken and not available on all cards");
79 static int rtl8180_pci_probe(struct pci_dev *pdev,
80 const struct pci_device_id *id);
82 static void rtl8180_pci_remove(struct pci_dev *pdev);
84 static void rtl8180_shutdown(struct pci_dev *pdev)
86 struct net_device *dev = pci_get_drvdata(pdev);
87 if (dev->netdev_ops->ndo_stop)
88 dev->netdev_ops->ndo_stop(dev);
89 pci_disable_device(pdev);
92 static int rtl8180_suspend(struct pci_dev *pdev, pm_message_t state)
94 struct net_device *dev = pci_get_drvdata(pdev);
96 if (!netif_running(dev))
99 if (dev->netdev_ops->ndo_stop)
100 dev->netdev_ops->ndo_stop(dev);
102 netif_device_detach(dev);
105 pci_save_state(pdev);
106 pci_disable_device(pdev);
107 pci_set_power_state(pdev, pci_choose_state(pdev, state));
111 static int rtl8180_resume(struct pci_dev *pdev)
113 struct net_device *dev = pci_get_drvdata(pdev);
117 pci_set_power_state(pdev, PCI_D0);
119 err = pci_enable_device(pdev);
121 dev_err(&pdev->dev, "pci_enable_device failed on resume\n");
126 pci_restore_state(pdev);
129 * Suspend/Resume resets the PCI configuration space, so we have to
130 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
131 * from interfering with C3 CPU state. pci_restore_state won't help
132 * here since it only restores the first 64 bytes pci config header.
134 pci_read_config_dword(pdev, 0x40, &val);
135 if ((val & 0x0000ff00) != 0)
136 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
138 if (!netif_running(dev))
141 if (dev->netdev_ops->ndo_open)
142 dev->netdev_ops->ndo_open(dev);
144 netif_device_attach(dev);
149 static struct pci_driver rtl8180_pci_driver = {
150 .name = RTL8180_MODULE_NAME,
151 .id_table = rtl8180_pci_id_tbl,
152 .probe = rtl8180_pci_probe,
153 .remove = rtl8180_pci_remove,
154 .suspend = rtl8180_suspend,
155 .resume = rtl8180_resume,
156 .shutdown = rtl8180_shutdown,
159 u8 read_nic_byte(struct net_device *dev, int x)
161 return 0xff&readb((u8 *)dev->mem_start + x);
164 u32 read_nic_dword(struct net_device *dev, int x)
166 return readl((u8 *)dev->mem_start + x);
169 u16 read_nic_word(struct net_device *dev, int x)
171 return readw((u8 *)dev->mem_start + x);
174 void write_nic_byte(struct net_device *dev, int x, u8 y)
176 writeb(y, (u8 *)dev->mem_start + x);
180 void write_nic_dword(struct net_device *dev, int x, u32 y)
182 writel(y, (u8 *)dev->mem_start + x);
186 void write_nic_word(struct net_device *dev, int x, u16 y)
188 writew(y, (u8 *)dev->mem_start + x);
192 inline void force_pci_posting(struct net_device *dev)
194 read_nic_byte(dev, EPROM_CMD);
198 irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs);
199 void set_nic_rxring(struct net_device *dev);
200 void set_nic_txring(struct net_device *dev);
201 static struct net_device_stats *rtl8180_stats(struct net_device *dev);
202 void rtl8180_commit(struct net_device *dev);
203 void rtl8180_start_tx_beacon(struct net_device *dev);
205 static struct proc_dir_entry *rtl8180_proc;
207 static int proc_get_registers(char *page, char **start,
208 off_t offset, int count,
209 int *eof, void *data)
211 struct net_device *dev = data;
216 /* This dump the current register page */
217 for (n = 0; n <= max;) {
218 len += snprintf(page + len, count - len, "\nD: %2x > ", n);
220 for (i = 0; i < 16 && n <= max; i++, n++)
221 len += snprintf(page + len, count - len, "%2x ",
222 read_nic_byte(dev, n));
224 len += snprintf(page + len, count - len, "\n");
230 int get_curr_tx_free_desc(struct net_device *dev, int priority);
232 static int proc_get_stats_hw(char *page, char **start,
233 off_t offset, int count,
234 int *eof, void *data)
242 static int proc_get_stats_rx(char *page, char **start,
243 off_t offset, int count,
244 int *eof, void *data)
246 struct net_device *dev = data;
247 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
251 len += snprintf(page + len, count - len,
254 "RX CRC Error(0-500): %lu\n"
255 "RX CRC Error(500-1000): %lu\n"
256 "RX CRC Error(>1000): %lu\n"
257 "RX ICV Error: %lu\n",
260 priv->stats.rxcrcerrmin,
261 priv->stats.rxcrcerrmid,
262 priv->stats.rxcrcerrmax,
270 static int proc_get_stats_tx(char *page, char **start,
271 off_t offset, int count,
272 int *eof, void *data)
274 struct net_device *dev = data;
275 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
278 unsigned long totalOK;
280 totalOK = priv->stats.txnpokint+priv->stats.txhpokint+priv->stats.txlpokint;
281 len += snprintf(page + len, count - len,
285 "TX beacon OK: %lu\n"
286 "TX beacon error: %lu\n",
288 priv->stats.txnperr+priv->stats.txhperr+priv->stats.txlperr,
290 priv->stats.txbeacon,
291 priv->stats.txbeaconerr
298 void rtl8180_proc_module_init(void)
300 DMESG("Initializing proc filesystem");
301 rtl8180_proc = proc_mkdir(RTL8180_MODULE_NAME, init_net.proc_net);
304 void rtl8180_proc_module_remove(void)
306 remove_proc_entry(RTL8180_MODULE_NAME, init_net.proc_net);
309 void rtl8180_proc_remove_one(struct net_device *dev)
311 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
313 remove_proc_entry("stats-hw", priv->dir_dev);
314 remove_proc_entry("stats-tx", priv->dir_dev);
315 remove_proc_entry("stats-rx", priv->dir_dev);
316 remove_proc_entry("registers", priv->dir_dev);
317 priv->dir_dev = NULL;
321 void rtl8180_proc_init_one(struct net_device *dev)
323 struct proc_dir_entry *e;
324 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
326 priv->dir_dev = rtl8180_proc;
327 if (!priv->dir_dev) {
328 DMESGE("Unable to initialize /proc/net/r8180/%s\n",
333 e = create_proc_read_entry("stats-hw", S_IFREG | S_IRUGO,
334 priv->dir_dev, proc_get_stats_hw, dev);
336 DMESGE("Unable to initialize "
337 "/proc/net/r8180/%s/stats-hw\n",
341 e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
342 priv->dir_dev, proc_get_stats_rx, dev);
344 DMESGE("Unable to initialize "
345 "/proc/net/r8180/%s/stats-rx\n",
350 e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
351 priv->dir_dev, proc_get_stats_tx, dev);
353 DMESGE("Unable to initialize "
354 "/proc/net/r8180/%s/stats-tx\n",
358 e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
359 priv->dir_dev, proc_get_registers, dev);
361 DMESGE("Unable to initialize "
362 "/proc/net/r8180/%s/registers\n",
368 FIXME: check if we can use some standard already-existent
369 data type+functions in kernel
372 short buffer_add(struct buffer **buffer, u32 *buf, dma_addr_t dma,
373 struct buffer **bufferhead)
379 *buffer = kmalloc(sizeof(struct buffer), GFP_KERNEL);
381 if (*buffer == NULL) {
382 DMESGE("Failed to kmalloc head of TX/RX struct");
385 (*buffer)->next = *buffer;
386 (*buffer)->buf = buf;
387 (*buffer)->dma = dma;
388 if (bufferhead != NULL)
389 (*bufferhead) = (*buffer);
394 while (tmp->next != (*buffer))
396 tmp->next = kmalloc(sizeof(struct buffer), GFP_KERNEL);
397 if (tmp->next == NULL) {
398 DMESGE("Failed to kmalloc TX/RX struct");
401 tmp->next->buf = buf;
402 tmp->next->dma = dma;
403 tmp->next->next = *buffer;
408 void buffer_free(struct net_device *dev, struct buffer **buffer, int len, short consistent)
411 struct buffer *tmp, *next;
412 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
413 struct pci_dev *pdev = priv->pdev;
423 pci_free_consistent(pdev, len,
426 pci_unmap_single(pdev, tmp->dma,
427 len, PCI_DMA_FROMDEVICE);
432 } while (next != *buffer);
437 int get_curr_tx_free_desc(struct net_device *dev, int priority)
439 struct r8180_priv *priv = ieee80211_priv(dev);
445 case MANAGE_PRIORITY:
446 head = priv->txmapringhead;
447 tail = priv->txmapringtail;
450 head = priv->txbkpringhead;
451 tail = priv->txbkpringtail;
454 head = priv->txbepringhead;
455 tail = priv->txbepringtail;
458 head = priv->txvipringhead;
459 tail = priv->txvipringtail;
462 head = priv->txvopringhead;
463 tail = priv->txvopringtail;
466 head = priv->txhpringhead;
467 tail = priv->txhpringtail;
474 ret = priv->txringcount - (tail - head)/8;
476 ret = (head - tail)/8;
478 if (ret > priv->txringcount)
484 short check_nic_enought_desc(struct net_device *dev, int priority)
486 struct r8180_priv *priv = ieee80211_priv(dev);
487 struct ieee80211_device *ieee = netdev_priv(dev);
488 int requiredbyte, required;
490 requiredbyte = priv->ieee80211->fts + sizeof(struct ieee80211_header_data);
492 if (ieee->current_network.QoS_Enable)
495 required = requiredbyte / (priv->txbuffsize-4);
497 if (requiredbyte % priv->txbuffsize)
500 /* for now we keep two free descriptor as a safety boundary
501 * between the tail and the head
504 return (required+2 < get_curr_tx_free_desc(dev, priority));
507 void fix_tx_fifo(struct net_device *dev)
509 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
513 for (tmp = priv->txmapring, i = 0;
514 i < priv->txringcount;
516 *tmp = *tmp & ~(1<<31);
519 for (tmp = priv->txbkpring, i = 0;
520 i < priv->txringcount;
522 *tmp = *tmp & ~(1<<31);
525 for (tmp = priv->txbepring, i = 0;
526 i < priv->txringcount;
528 *tmp = *tmp & ~(1<<31);
530 for (tmp = priv->txvipring, i = 0;
531 i < priv->txringcount;
533 *tmp = *tmp & ~(1<<31);
536 for (tmp = priv->txvopring, i = 0;
537 i < priv->txringcount;
539 *tmp = *tmp & ~(1<<31);
542 for (tmp = priv->txhpring, i = 0;
543 i < priv->txringcount;
545 *tmp = *tmp & ~(1<<31);
548 for (tmp = priv->txbeaconring, i = 0;
549 i < priv->txbeaconcount;
551 *tmp = *tmp & ~(1<<31);
554 priv->txmapringtail = priv->txmapring;
555 priv->txmapringhead = priv->txmapring;
556 priv->txmapbufstail = priv->txmapbufs;
558 priv->txbkpringtail = priv->txbkpring;
559 priv->txbkpringhead = priv->txbkpring;
560 priv->txbkpbufstail = priv->txbkpbufs;
562 priv->txbepringtail = priv->txbepring;
563 priv->txbepringhead = priv->txbepring;
564 priv->txbepbufstail = priv->txbepbufs;
566 priv->txvipringtail = priv->txvipring;
567 priv->txvipringhead = priv->txvipring;
568 priv->txvipbufstail = priv->txvipbufs;
570 priv->txvopringtail = priv->txvopring;
571 priv->txvopringhead = priv->txvopring;
572 priv->txvopbufstail = priv->txvopbufs;
574 priv->txhpringtail = priv->txhpring;
575 priv->txhpringhead = priv->txhpring;
576 priv->txhpbufstail = priv->txhpbufs;
578 priv->txbeaconringtail = priv->txbeaconring;
579 priv->txbeaconbufstail = priv->txbeaconbufs;
582 ieee80211_reset_queue(priv->ieee80211);
583 priv->ack_tx_to_ieee = 0;
586 void fix_rx_fifo(struct net_device *dev)
588 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
590 struct buffer *rxbuf;
593 rx_desc_size = 8; /* 4*8 = 32 bytes */
595 for (tmp = priv->rxring, rxbuf = priv->rxbufferhead;
596 (tmp < (priv->rxring)+(priv->rxringcount)*rx_desc_size);
597 tmp += rx_desc_size, rxbuf = rxbuf->next) {
598 *(tmp+2) = rxbuf->dma;
599 *tmp = *tmp & ~0xfff;
600 *tmp = *tmp | priv->rxbuffersize;
604 priv->rxringtail = priv->rxring;
605 priv->rxbuffer = priv->rxbufferhead;
606 priv->rx_skb_complete = 1;
610 void rtl8180_irq_disable(struct net_device *dev)
612 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
614 write_nic_dword(dev, IMR, 0);
615 force_pci_posting(dev);
616 priv->irq_enabled = 0;
619 void rtl8180_set_mode(struct net_device *dev, int mode)
623 ecmd = read_nic_byte(dev, EPROM_CMD);
624 ecmd = ecmd & ~EPROM_CMD_OPERATING_MODE_MASK;
625 ecmd = ecmd | (mode<<EPROM_CMD_OPERATING_MODE_SHIFT);
626 ecmd = ecmd & ~(1<<EPROM_CS_SHIFT);
627 ecmd = ecmd & ~(1<<EPROM_CK_SHIFT);
628 write_nic_byte(dev, EPROM_CMD, ecmd);
631 void rtl8180_beacon_tx_enable(struct net_device *dev);
633 void rtl8180_update_msr(struct net_device *dev)
635 struct r8180_priv *priv = ieee80211_priv(dev);
639 msr = read_nic_byte(dev, MSR);
640 msr &= ~MSR_LINK_MASK;
642 rxconf = read_nic_dword(dev, RX_CONF);
644 if (priv->ieee80211->state == IEEE80211_LINKED) {
645 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
646 msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT);
647 else if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
648 msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT);
649 else if (priv->ieee80211->iw_mode == IW_MODE_INFRA)
650 msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT);
652 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
653 rxconf |= (1<<RX_CHECK_BSSID_SHIFT);
656 msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT);
657 rxconf &= ~(1<<RX_CHECK_BSSID_SHIFT);
660 write_nic_byte(dev, MSR, msr);
661 write_nic_dword(dev, RX_CONF, rxconf);
664 void rtl8180_set_chan(struct net_device *dev, short ch)
666 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
668 if ((ch > 14) || (ch < 1)) {
669 printk("In %s: Invalid chnanel %d\n", __func__, ch);
674 priv->rf_set_chan(dev, priv->chan);
677 void set_nic_txring(struct net_device *dev)
679 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
681 write_nic_dword(dev, TX_MANAGEPRIORITY_RING_ADDR, priv->txmapringdma);
682 write_nic_dword(dev, TX_BKPRIORITY_RING_ADDR, priv->txbkpringdma);
683 write_nic_dword(dev, TX_BEPRIORITY_RING_ADDR, priv->txbepringdma);
684 write_nic_dword(dev, TX_VIPRIORITY_RING_ADDR, priv->txvipringdma);
685 write_nic_dword(dev, TX_VOPRIORITY_RING_ADDR, priv->txvopringdma);
686 write_nic_dword(dev, TX_HIGHPRIORITY_RING_ADDR, priv->txhpringdma);
687 write_nic_dword(dev, TX_BEACON_RING_ADDR, priv->txbeaconringdma);
690 void rtl8180_beacon_tx_enable(struct net_device *dev)
692 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
694 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
695 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_BQ);
696 write_nic_byte(dev, TPPollStop, priv->dma_poll_mask);
697 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
700 void rtl8180_beacon_tx_disable(struct net_device *dev)
702 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
704 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
705 priv->dma_poll_stop_mask |= TPPOLLSTOP_BQ;
706 write_nic_byte(dev, TPPollStop, priv->dma_poll_stop_mask);
707 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
711 void rtl8180_rtx_disable(struct net_device *dev)
714 struct r8180_priv *priv = ieee80211_priv(dev);
716 cmd = read_nic_byte(dev, CMD);
717 write_nic_byte(dev, CMD, cmd &
718 ~((1<<CMD_RX_ENABLE_SHIFT)|(1<<CMD_TX_ENABLE_SHIFT)));
719 force_pci_posting(dev);
722 if (!priv->rx_skb_complete)
723 dev_kfree_skb_any(priv->rx_skb);
726 short alloc_tx_desc_ring(struct net_device *dev, int bufsize, int count,
732 dma_addr_t dma_desc, dma_tmp;
733 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
734 struct pci_dev *pdev = priv->pdev;
737 if ((bufsize & 0xfff) != bufsize) {
738 DMESGE("TX buffer allocation too large");
741 desc = (u32 *)pci_alloc_consistent(pdev,
742 sizeof(u32)*8*count+256, &dma_desc);
748 * descriptor's buffer must be 256 byte aligned
749 * we shouldn't be here, since we set DMA mask !
751 WARN(1, "DMA buffer is not aligned\n");
755 for (i = 0; i < count; i++) {
756 buf = (void *)pci_alloc_consistent(pdev, bufsize, &dma_tmp);
761 case TX_MANAGEPRIORITY_RING_ADDR:
762 if (-1 == buffer_add(&(priv->txmapbufs), buf, dma_tmp, NULL)) {
763 DMESGE("Unable to allocate mem for buffer NP");
767 case TX_BKPRIORITY_RING_ADDR:
768 if (-1 == buffer_add(&(priv->txbkpbufs), buf, dma_tmp, NULL)) {
769 DMESGE("Unable to allocate mem for buffer LP");
773 case TX_BEPRIORITY_RING_ADDR:
774 if (-1 == buffer_add(&(priv->txbepbufs), buf, dma_tmp, NULL)) {
775 DMESGE("Unable to allocate mem for buffer NP");
779 case TX_VIPRIORITY_RING_ADDR:
780 if (-1 == buffer_add(&(priv->txvipbufs), buf, dma_tmp, NULL)) {
781 DMESGE("Unable to allocate mem for buffer LP");
785 case TX_VOPRIORITY_RING_ADDR:
786 if (-1 == buffer_add(&(priv->txvopbufs), buf, dma_tmp, NULL)) {
787 DMESGE("Unable to allocate mem for buffer NP");
791 case TX_HIGHPRIORITY_RING_ADDR:
792 if (-1 == buffer_add(&(priv->txhpbufs), buf, dma_tmp, NULL)) {
793 DMESGE("Unable to allocate mem for buffer HP");
797 case TX_BEACON_RING_ADDR:
798 if (-1 == buffer_add(&(priv->txbeaconbufs), buf, dma_tmp, NULL)) {
799 DMESGE("Unable to allocate mem for buffer BP");
804 *tmp = *tmp & ~(1<<31); /* descriptor empty, owned by the drv */
805 *(tmp+2) = (u32)dma_tmp;
809 *(tmp+4) = (u32)dma_desc+((i+1)*8*4);
811 *(tmp+4) = (u32)dma_desc;
817 case TX_MANAGEPRIORITY_RING_ADDR:
818 priv->txmapringdma = dma_desc;
819 priv->txmapring = desc;
821 case TX_BKPRIORITY_RING_ADDR:
822 priv->txbkpringdma = dma_desc;
823 priv->txbkpring = desc;
825 case TX_BEPRIORITY_RING_ADDR:
826 priv->txbepringdma = dma_desc;
827 priv->txbepring = desc;
829 case TX_VIPRIORITY_RING_ADDR:
830 priv->txvipringdma = dma_desc;
831 priv->txvipring = desc;
833 case TX_VOPRIORITY_RING_ADDR:
834 priv->txvopringdma = dma_desc;
835 priv->txvopring = desc;
837 case TX_HIGHPRIORITY_RING_ADDR:
838 priv->txhpringdma = dma_desc;
839 priv->txhpring = desc;
841 case TX_BEACON_RING_ADDR:
842 priv->txbeaconringdma = dma_desc;
843 priv->txbeaconring = desc;
851 void free_tx_desc_rings(struct net_device *dev)
853 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
854 struct pci_dev *pdev = priv->pdev;
855 int count = priv->txringcount;
857 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
858 priv->txmapring, priv->txmapringdma);
859 buffer_free(dev, &(priv->txmapbufs), priv->txbuffsize, 1);
861 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
862 priv->txbkpring, priv->txbkpringdma);
863 buffer_free(dev, &(priv->txbkpbufs), priv->txbuffsize, 1);
865 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
866 priv->txbepring, priv->txbepringdma);
867 buffer_free(dev, &(priv->txbepbufs), priv->txbuffsize, 1);
869 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
870 priv->txvipring, priv->txvipringdma);
871 buffer_free(dev, &(priv->txvipbufs), priv->txbuffsize, 1);
873 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
874 priv->txvopring, priv->txvopringdma);
875 buffer_free(dev, &(priv->txvopbufs), priv->txbuffsize, 1);
877 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
878 priv->txhpring, priv->txhpringdma);
879 buffer_free(dev, &(priv->txhpbufs), priv->txbuffsize, 1);
881 count = priv->txbeaconcount;
882 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
883 priv->txbeaconring, priv->txbeaconringdma);
884 buffer_free(dev, &(priv->txbeaconbufs), priv->txbuffsize, 1);
887 void free_rx_desc_ring(struct net_device *dev)
889 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
890 struct pci_dev *pdev = priv->pdev;
891 int count = priv->rxringcount;
893 pci_free_consistent(pdev, sizeof(u32)*8*count+256,
894 priv->rxring, priv->rxringdma);
896 buffer_free(dev, &(priv->rxbuffer), priv->rxbuffersize, 0);
899 short alloc_rx_desc_ring(struct net_device *dev, u16 bufsize, int count)
904 dma_addr_t dma_desc, dma_tmp;
905 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
906 struct pci_dev *pdev = priv->pdev;
910 rx_desc_size = 8; /* 4*8 = 32 bytes */
912 if ((bufsize & 0xfff) != bufsize) {
913 DMESGE("RX buffer allocation too large");
917 desc = (u32 *)pci_alloc_consistent(pdev, sizeof(u32)*rx_desc_size*count+256,
922 * descriptor's buffer must be 256 byte aligned
923 * should never happen since we specify the DMA mask
925 WARN(1, "DMA buffer is not aligned\n");
928 priv->rxringdma = dma_desc;
931 for (i = 0; i < count; i++) {
932 buf = kmalloc(bufsize * sizeof(u8), GFP_ATOMIC);
934 DMESGE("Failed to kmalloc RX buffer");
938 dma_tmp = pci_map_single(pdev, buf, bufsize * sizeof(u8),
940 if (pci_dma_mapping_error(pdev, dma_tmp))
942 if (-1 == buffer_add(&(priv->rxbuffer), buf, dma_tmp,
943 &(priv->rxbufferhead))) {
944 DMESGE("Unable to allocate mem RX buf");
947 *tmp = 0; /* zero pads the header of the descriptor */
948 *tmp = *tmp | (bufsize&0xfff);
949 *(tmp+2) = (u32)dma_tmp;
950 *tmp = *tmp | (1<<31); /* descriptor void, owned by the NIC */
952 tmp = tmp+rx_desc_size;
955 *(tmp-rx_desc_size) = *(tmp-rx_desc_size) | (1<<30); /* this is the last descriptor */
961 void set_nic_rxring(struct net_device *dev)
964 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
966 pgreg = read_nic_byte(dev, PGSELECT);
967 write_nic_byte(dev, PGSELECT, pgreg & ~(1<<PGSELECT_PG_SHIFT));
969 write_nic_dword(dev, RXRING_ADDR, priv->rxringdma);
972 void rtl8180_reset(struct net_device *dev)
976 rtl8180_irq_disable(dev);
978 cr = read_nic_byte(dev, CMD);
980 cr = cr | (1<<CMD_RST_SHIFT);
981 write_nic_byte(dev, CMD, cr);
983 force_pci_posting(dev);
987 if (read_nic_byte(dev, CMD) & (1<<CMD_RST_SHIFT))
988 DMESGW("Card reset timeout!");
990 DMESG("Card successfully reset");
992 rtl8180_set_mode(dev, EPROM_CMD_LOAD);
993 force_pci_posting(dev);
997 inline u16 ieeerate2rtlrate(int rate)
1029 static u16 rtl_rate[] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540, 720};
1031 inline u16 rtl8180_rate2rate(short rate)
1035 return rtl_rate[rate];
1038 inline u8 rtl8180_IsWirelessBMode(u16 rate)
1040 if (((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220))
1046 u16 N_DBPSOfRate(u16 DataRate);
1048 u16 ComputeTxTime(u16 FrameLength, u16 DataRate, u8 bManagementFrame,
1055 if (rtl8180_IsWirelessBMode(DataRate)) {
1056 if (bManagementFrame || !bShortPreamble || DataRate == 10)
1058 FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
1060 /* short preamble */
1061 FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
1063 if ((FrameLength*8 % (DataRate/10)) != 0) /* get the ceilling */
1065 } else { /* 802.11g DSSS-OFDM PLCP length field calculation. */
1066 N_DBPS = N_DBPSOfRate(DataRate);
1067 Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
1068 + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
1069 FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
1074 u16 N_DBPSOfRate(u16 DataRate)
1111 * For Netgear case, they want good-looking signal strength.
1113 long NetgearSignalStrengthTranslate(long LastSS, long CurrSS)
1117 /* Step 1. Scale mapping. */
1118 if (CurrSS >= 71 && CurrSS <= 100)
1119 RetSS = 90 + ((CurrSS - 70) / 3);
1120 else if (CurrSS >= 41 && CurrSS <= 70)
1121 RetSS = 78 + ((CurrSS - 40) / 3);
1122 else if (CurrSS >= 31 && CurrSS <= 40)
1123 RetSS = 66 + (CurrSS - 30);
1124 else if (CurrSS >= 21 && CurrSS <= 30)
1125 RetSS = 54 + (CurrSS - 20);
1126 else if (CurrSS >= 5 && CurrSS <= 20)
1127 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
1128 else if (CurrSS == 4)
1130 else if (CurrSS == 3)
1132 else if (CurrSS == 2)
1134 else if (CurrSS == 1)
1139 /* Step 2. Smoothing. */
1141 RetSS = ((LastSS * 5) + (RetSS) + 5) / 6;
1147 * Translate 0-100 signal strength index into dBm.
1149 long TranslateToDbm8185(u8 SignalStrengthIndex)
1153 /* Translate to dBm (x=0.5y-95). */
1154 SignalPower = (long)((SignalStrengthIndex + 1) >> 1);
1161 * Perform signal smoothing for dynamic mechanism.
1162 * This is different with PerformSignalSmoothing8185 in smoothing formula.
1163 * No dramatic adjustion is apply because dynamic mechanism need some degree
1164 * of correctness. Ported from 8187B.
1166 void PerformUndecoratedSignalSmoothing8185(struct r8180_priv *priv,
1169 /* Determin the current packet is CCK rate. */
1170 priv->bCurCCKPkt = bCckRate;
1172 if (priv->UndecoratedSmoothedSS >= 0)
1173 priv->UndecoratedSmoothedSS = ((priv->UndecoratedSmoothedSS * 5) +
1174 (priv->SignalStrength * 10)) / 6;
1176 priv->UndecoratedSmoothedSS = priv->SignalStrength * 10;
1178 priv->UndercorateSmoothedRxPower = ((priv->UndercorateSmoothedRxPower * 50) +
1179 (priv->RxPower * 11)) / 60;
1182 priv->CurCCKRSSI = priv->RSSI;
1184 priv->CurCCKRSSI = 0;
1189 * This is rough RX isr handling routine
1191 void rtl8180_rx(struct net_device *dev)
1193 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1194 struct sk_buff *tmp_skb;
1198 unsigned char quality, signal;
1207 u8 LNA_gain[4] = {02, 17, 29, 39};
1209 struct ieee80211_hdr_4addr *hdr;
1211 u8 bHwError = 0, bCRC = 0, bICV = 0;
1212 bool bCckRate = false;
1214 long SignalStrengthIndex = 0;
1215 struct ieee80211_rx_stats stats = {
1219 .freq = IEEE80211_24GHZ_BAND,
1222 stats.nic_type = NIC_8185B;
1225 if ((*(priv->rxringtail)) & (1<<31)) {
1226 /* we have got an RX int, but the descriptor
1227 * we are pointing is empty */
1229 priv->stats.rxnodata++;
1230 priv->ieee80211->stats.rx_errors++;
1233 tmp = priv->rxringtail;
1235 if (tmp == priv->rxring)
1236 tmp = priv->rxring + (priv->rxringcount - 1)*rx_desc_size;
1238 tmp -= rx_desc_size;
1240 if (!(*tmp & (1<<31)))
1242 } while (tmp != priv->rxring);
1245 priv->rxringtail = tmp2;
1248 /* while there are filled descriptors */
1249 while (!(*(priv->rxringtail) & (1<<31))) {
1250 if (*(priv->rxringtail) & (1<<26))
1251 DMESGW("RX buffer overflow");
1252 if (*(priv->rxringtail) & (1<<12))
1253 priv->stats.rxicverr++;
1255 if (*(priv->rxringtail) & (1<<27)) {
1256 priv->stats.rxdmafail++;
1257 /* DMESG("EE: RX DMA FAILED at buffer pointed by descriptor %x",(u32)priv->rxringtail); */
1261 pci_dma_sync_single_for_cpu(priv->pdev,
1262 priv->rxbuffer->dma,
1263 priv->rxbuffersize * sizeof(u8),
1264 PCI_DMA_FROMDEVICE);
1266 first = *(priv->rxringtail) & (1<<29) ? 1 : 0;
1268 priv->rx_prevlen = 0;
1270 last = *(priv->rxringtail) & (1<<28) ? 1 : 0;
1272 lastlen = ((*priv->rxringtail) & 0xfff);
1274 /* if the last descriptor (that should
1275 * tell us the total packet len) tell
1276 * us something less than the descriptors
1277 * len we had until now, then there is some
1279 * workaround to prevent kernel panic
1281 if (lastlen < priv->rx_prevlen)
1284 len = lastlen-priv->rx_prevlen;
1286 if (*(priv->rxringtail) & (1<<13)) {
1287 if ((*(priv->rxringtail) & 0xfff) < 500)
1288 priv->stats.rxcrcerrmin++;
1289 else if ((*(priv->rxringtail) & 0x0fff) > 1000)
1290 priv->stats.rxcrcerrmax++;
1292 priv->stats.rxcrcerrmid++;
1297 len = priv->rxbuffersize;
1300 if (first && last) {
1301 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
1303 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
1310 priv->rx_prevlen += len;
1312 if (priv->rx_prevlen > MAX_FRAG_THRESHOLD + 100) {
1313 /* HW is probably passing several buggy frames
1314 * without FD or LD flag set.
1315 * Throw this garbage away to prevent skb
1318 if (!priv->rx_skb_complete)
1319 dev_kfree_skb_any(priv->rx_skb);
1320 priv->rx_skb_complete = 1;
1323 signal = (unsigned char)(((*(priv->rxringtail+3)) & (0x00ff0000))>>16);
1324 signal = (signal & 0xfe) >> 1;
1326 quality = (unsigned char)((*(priv->rxringtail+3)) & (0xff));
1328 stats.mac_time[0] = *(priv->rxringtail+1);
1329 stats.mac_time[1] = *(priv->rxringtail+2);
1330 rxpower = ((char)(((*(priv->rxringtail+4)) & (0x00ff0000))>>16))/2 - 42;
1331 RSSI = ((u8)(((*(priv->rxringtail+3)) & (0x0000ff00))>>8)) & (0x7f);
1333 rate = ((*(priv->rxringtail)) &
1334 ((1<<23)|(1<<22)|(1<<21)|(1<<20)))>>20;
1336 stats.rate = rtl8180_rate2rate(rate);
1337 Antenna = (((*(priv->rxringtail+3)) & (0x00008000)) == 0) ? 0 : 1;
1338 if (!rtl8180_IsWirelessBMode(stats.rate)) { /* OFDM rate. */
1339 RxAGC_dBm = rxpower+1; /* bias */
1340 } else { /* CCK rate. */
1341 RxAGC_dBm = signal; /* bit 0 discard */
1343 LNA = (u8) (RxAGC_dBm & 0x60) >> 5; /* bit 6~ bit 5 */
1344 BB = (u8) (RxAGC_dBm & 0x1F); /* bit 4 ~ bit 0 */
1346 RxAGC_dBm = -(LNA_gain[LNA] + (BB*2)); /* Pin_11b=-(LNA_gain+BB_gain) (dBm) */
1348 RxAGC_dBm += 4; /* bias */
1351 if (RxAGC_dBm & 0x80) /* absolute value */
1352 RXAGC = ~(RxAGC_dBm)+1;
1353 bCckRate = rtl8180_IsWirelessBMode(stats.rate);
1354 /* Translate RXAGC into 1-100. */
1355 if (!rtl8180_IsWirelessBMode(stats.rate)) { /* OFDM rate. */
1358 else if (RXAGC < 25)
1360 RXAGC = (90-RXAGC)*100/65;
1361 } else { /* CCK rate. */
1364 else if (RXAGC < 30)
1366 RXAGC = (95-RXAGC)*100/65;
1368 priv->SignalStrength = (u8)RXAGC;
1369 priv->RecvSignalPower = RxAGC_dBm;
1370 priv->RxPower = rxpower;
1372 /* SQ translation formula is provided by SD3 DZ. 2006.06.27 */
1374 quality = 1; /*0; */ /* 0 will cause epc to show signal zero , walk around now; */
1375 else if (quality < 27)
1378 quality = 127 - quality;
1379 priv->SignalQuality = quality;
1381 stats.signal = (u8)quality; /*priv->wstats.qual.level = priv->SignalStrength; */
1382 stats.signalstrength = RXAGC;
1383 if (stats.signalstrength > 100)
1384 stats.signalstrength = 100;
1385 stats.signalstrength = (stats.signalstrength * 70)/100 + 30;
1386 /* printk("==========================>rx : RXAGC is %d,signalstrength is %d\n",RXAGC,stats.signalstrength); */
1387 stats.rssi = priv->wstats.qual.qual = priv->SignalQuality;
1388 stats.noise = priv->wstats.qual.noise = 100 - priv->wstats.qual.qual;
1389 bHwError = (((*(priv->rxringtail)) & (0x00000fff)) == 4080) |
1390 (((*(priv->rxringtail)) & (0x04000000)) != 0) |
1391 (((*(priv->rxringtail)) & (0x08000000)) != 0) |
1392 (((~(*(priv->rxringtail))) & (0x10000000)) != 0) |
1393 (((~(*(priv->rxringtail))) & (0x20000000)) != 0);
1394 bCRC = ((*(priv->rxringtail)) & (0x00002000)) >> 13;
1395 bICV = ((*(priv->rxringtail)) & (0x00001000)) >> 12;
1396 hdr = (struct ieee80211_hdr_4addr *)priv->rxbuffer->buf;
1397 fc = le16_to_cpu(hdr->frame_ctl);
1398 type = WLAN_FC_GET_TYPE(fc);
1400 if (IEEE80211_FTYPE_CTL != type &&
1401 !bHwError && !bCRC && !bICV &&
1402 eqMacAddr(priv->ieee80211->current_network.bssid,
1403 fc & IEEE80211_FCTL_TODS ? hdr->addr1 :
1404 fc & IEEE80211_FCTL_FROMDS ? hdr->addr2 :
1407 /* Perform signal smoothing for dynamic
1408 * mechanism on demand. This is different
1409 * with PerformSignalSmoothing8185 in smoothing
1410 * fomula. No dramatic adjustion is apply
1411 * because dynamic mechanism need some degree
1412 * of correctness. */
1413 PerformUndecoratedSignalSmoothing8185(priv, bCckRate);
1415 /* For good-looking singal strength. */
1416 SignalStrengthIndex = NetgearSignalStrengthTranslate(
1417 priv->LastSignalStrengthInPercent,
1418 priv->SignalStrength);
1420 priv->LastSignalStrengthInPercent = SignalStrengthIndex;
1421 priv->Stats_SignalStrength = TranslateToDbm8185((u8)SignalStrengthIndex);
1423 * We need more correct power of received packets and the "SignalStrength" of RxStats is beautified,
1424 * so we record the correct power here.
1426 priv->Stats_SignalQuality = (long)(priv->Stats_SignalQuality * 5 + (long)priv->SignalQuality + 5) / 6;
1427 priv->Stats_RecvSignalPower = (long)(priv->Stats_RecvSignalPower * 5 + priv->RecvSignalPower - 1) / 6;
1429 /* Figure out which antenna that received the last packet. */
1430 priv->LastRxPktAntenna = Antenna ? 1 : 0; /* 0: aux, 1: main. */
1431 SwAntennaDiversityRxOk8185(dev, priv->SignalStrength);
1435 if (!priv->rx_skb_complete) {
1436 /* seems that HW sometimes fails to receive and
1437 doesn't provide the last descriptor */
1438 dev_kfree_skb_any(priv->rx_skb);
1439 priv->stats.rxnolast++;
1441 priv->rx_skb = dev_alloc_skb(len+2);
1445 priv->rx_skb_complete = 0;
1446 priv->rx_skb->dev = dev;
1448 /* if we are here we should have already RXed
1450 * If we get here and the skb is not allocated then
1451 * we have just throw out garbage (skb not allocated)
1452 * and we are still rxing garbage....
1454 if (!priv->rx_skb_complete) {
1456 tmp_skb = dev_alloc_skb(priv->rx_skb->len+len+2);
1463 memcpy(skb_put(tmp_skb, priv->rx_skb->len),
1467 dev_kfree_skb_any(priv->rx_skb);
1469 priv->rx_skb = tmp_skb;
1473 if (!priv->rx_skb_complete) {
1475 memcpy(skb_put(priv->rx_skb, len),
1476 (((unsigned char *)priv->rxbuffer->buf) + 2), len);
1478 memcpy(skb_put(priv->rx_skb, len),
1479 priv->rxbuffer->buf, len);
1483 if (last && !priv->rx_skb_complete) {
1484 if (priv->rx_skb->len > 4)
1485 skb_trim(priv->rx_skb, priv->rx_skb->len-4);
1486 if (!ieee80211_rtl_rx(priv->ieee80211,
1487 priv->rx_skb, &stats))
1488 dev_kfree_skb_any(priv->rx_skb);
1489 priv->rx_skb_complete = 1;
1492 pci_dma_sync_single_for_device(priv->pdev,
1493 priv->rxbuffer->dma,
1494 priv->rxbuffersize * sizeof(u8),
1495 PCI_DMA_FROMDEVICE);
1497 drop: /* this is used when we have not enough mem */
1498 /* restore the descriptor */
1499 *(priv->rxringtail+2) = priv->rxbuffer->dma;
1500 *(priv->rxringtail) = *(priv->rxringtail) & ~0xfff;
1501 *(priv->rxringtail) =
1502 *(priv->rxringtail) | priv->rxbuffersize;
1504 *(priv->rxringtail) =
1505 *(priv->rxringtail) | (1<<31);
1507 priv->rxringtail += rx_desc_size;
1508 if (priv->rxringtail >=
1509 (priv->rxring)+(priv->rxringcount)*rx_desc_size)
1510 priv->rxringtail = priv->rxring;
1512 priv->rxbuffer = (priv->rxbuffer->next);
1517 void rtl8180_dma_kick(struct net_device *dev, int priority)
1519 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1521 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1522 write_nic_byte(dev, TX_DMA_POLLING,
1523 (1 << (priority + 1)) | priv->dma_poll_mask);
1524 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1526 force_pci_posting(dev);
1529 void rtl8180_data_hard_stop(struct net_device *dev)
1531 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1533 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1534 priv->dma_poll_stop_mask |= TPPOLLSTOP_AC_VIQ;
1535 write_nic_byte(dev, TPPollStop, priv->dma_poll_stop_mask);
1536 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1539 void rtl8180_data_hard_resume(struct net_device *dev)
1541 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1543 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1544 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_AC_VIQ);
1545 write_nic_byte(dev, TPPollStop, priv->dma_poll_stop_mask);
1546 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1550 * This function TX data frames when the ieee80211 stack requires this.
1551 * It checks also if we need to stop the ieee tx queue, eventually do it
1553 void rtl8180_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int
1555 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1557 struct ieee80211_hdr_3addr *h = (struct ieee80211_hdr_3addr *) skb->data;
1558 short morefrag = (h->frame_control) & IEEE80211_FCTL_MOREFRAGS;
1559 unsigned long flags;
1562 mode = priv->ieee80211->iw_mode;
1564 rate = ieeerate2rtlrate(rate);
1566 * This function doesn't require lock because we make
1567 * sure it's called with the tx_lock already acquired.
1568 * this come from the kernel's hard_xmit callback (through
1569 * the ieee stack, or from the try_wake_queue (again through
1572 priority = AC2Q(skb->priority);
1573 spin_lock_irqsave(&priv->tx_lock, flags);
1575 if (priv->ieee80211->bHwRadioOff) {
1576 spin_unlock_irqrestore(&priv->tx_lock, flags);
1581 if (!check_nic_enought_desc(dev, priority)) {
1582 DMESGW("Error: no descriptor left by previous TX (avail %d) ",
1583 get_curr_tx_free_desc(dev, priority));
1584 ieee80211_rtl_stop_queue(priv->ieee80211);
1586 rtl8180_tx(dev, skb->data, skb->len, priority, morefrag, 0, rate);
1587 if (!check_nic_enought_desc(dev, priority))
1588 ieee80211_rtl_stop_queue(priv->ieee80211);
1590 spin_unlock_irqrestore(&priv->tx_lock, flags);
1594 * This is a rough attempt to TX a frame
1595 * This is called by the ieee 80211 stack to TX management frames.
1596 * If the ring is full packets are dropped (for data frame the queue
1597 * is stopped before this can happen). For this reason it is better
1598 * if the descriptors are larger than the largest management frame
1599 * we intend to TX: i'm unsure what the HW does if it will not find
1600 * the last fragment of a frame because it has been dropped...
1601 * Since queues for Management and Data frames are different we
1602 * might use a different lock than tx_lock (for example mgmt_tx_lock)
1604 /* these function may loop if invoked with 0 descriptors or 0 len buffer */
1605 int rtl8180_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1607 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1608 unsigned long flags;
1611 priority = MANAGE_PRIORITY;
1613 spin_lock_irqsave(&priv->tx_lock, flags);
1615 if (priv->ieee80211->bHwRadioOff) {
1616 spin_unlock_irqrestore(&priv->tx_lock, flags);
1617 dev_kfree_skb_any(skb);
1618 return NETDEV_TX_OK;
1621 rtl8180_tx(dev, skb->data, skb->len, priority,
1622 0, 0, ieeerate2rtlrate(priv->ieee80211->basic_rate));
1624 priv->ieee80211->stats.tx_bytes += skb->len;
1625 priv->ieee80211->stats.tx_packets++;
1626 spin_unlock_irqrestore(&priv->tx_lock, flags);
1628 dev_kfree_skb_any(skb);
1629 return NETDEV_TX_OK;
1632 /* longpre 144+48 shortpre 72+24 */
1633 u16 rtl8180_len2duration(u32 len, short rate, short *ext)
1642 duration = ((len+4)<<4) / 0x2;
1643 drift = ((len+4)<<4) % 0x2;
1650 duration = ((len+4)<<4) / 0x4;
1651 drift = ((len+4)<<4) % 0x4;
1656 case 2: /* 5.5mbps */
1658 duration = ((len+4)<<4) / 0xb;
1659 drift = ((len+4)<<4) % 0xb;
1665 case 3: /* 11mbps */
1667 duration = ((len+4)<<4) / 0x16;
1668 drift = ((len+4)<<4) % 0x16;
1681 void rtl8180_prepare_beacon(struct net_device *dev)
1683 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1684 struct sk_buff *skb;
1686 u16 word = read_nic_word(dev, BcnItv);
1687 word &= ~BcnItv_BcnItv; /* clear Bcn_Itv */
1688 word |= cpu_to_le16(priv->ieee80211->current_network.beacon_interval); /* 0x64; */
1689 write_nic_word(dev, BcnItv, word);
1691 skb = ieee80211_get_beacon(priv->ieee80211);
1693 rtl8180_tx(dev, skb->data, skb->len, BEACON_PRIORITY,
1694 0, 0, ieeerate2rtlrate(priv->ieee80211->basic_rate));
1695 dev_kfree_skb_any(skb);
1700 * This function do the real dirty work: it enqueues a TX command
1701 * descriptor in the ring buffer, copyes the frame in a TX buffer
1702 * and kicks the NIC to ensure it does the DMA transfer.
1704 short rtl8180_tx(struct net_device *dev, u8 *txbuf, int len, int priority,
1705 short morefrag, short descfrag, int rate)
1707 struct r8180_priv *priv = ieee80211_priv(dev);
1708 u32 *tail, *temp_tail;
1715 struct buffer *buflist;
1716 struct ieee80211_hdr_3addr *frag_hdr = (struct ieee80211_hdr_3addr *)txbuf;
1718 u8 bUseShortPreamble = 0;
1723 u16 ThisFrameTime = 0;
1724 u16 TxDescDuration = 0;
1725 u8 ownbit_flag = false;
1728 case MANAGE_PRIORITY:
1729 tail = priv->txmapringtail;
1730 begin = priv->txmapring;
1731 buflist = priv->txmapbufstail;
1732 count = priv->txringcount;
1735 tail = priv->txbkpringtail;
1736 begin = priv->txbkpring;
1737 buflist = priv->txbkpbufstail;
1738 count = priv->txringcount;
1741 tail = priv->txbepringtail;
1742 begin = priv->txbepring;
1743 buflist = priv->txbepbufstail;
1744 count = priv->txringcount;
1747 tail = priv->txvipringtail;
1748 begin = priv->txvipring;
1749 buflist = priv->txvipbufstail;
1750 count = priv->txringcount;
1753 tail = priv->txvopringtail;
1754 begin = priv->txvopring;
1755 buflist = priv->txvopbufstail;
1756 count = priv->txringcount;
1759 tail = priv->txhpringtail;
1760 begin = priv->txhpring;
1761 buflist = priv->txhpbufstail;
1762 count = priv->txringcount;
1764 case BEACON_PRIORITY:
1765 tail = priv->txbeaconringtail;
1766 begin = priv->txbeaconring;
1767 buflist = priv->txbeaconbufstail;
1768 count = priv->txbeaconcount;
1775 memcpy(&dest, frag_hdr->addr1, ETH_ALEN);
1776 if (is_multicast_ether_addr(dest)) {
1782 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate),
1783 0, bUseShortPreamble);
1784 TxDescDuration = ThisFrameTime;
1785 } else { /* Unicast packet */
1788 /* YJ,add,080828,for Keep alive */
1789 priv->NumTxUnicast++;
1791 /* Figure out ACK rate according to BSS basic rate
1793 AckTime = ComputeTxTime(14, 10, 0, 0); /* AckCTSLng = 14 use 1M bps send */
1795 if (((len + sCrcLng) > priv->rts) && priv->rts) { /* RTS/CTS. */
1796 u16 RtsTime, CtsTime;
1801 /* Rate and time required for RTS. */
1802 RtsTime = ComputeTxTime(sAckCtsLng/8, priv->ieee80211->basic_rate, 0, 0);
1803 /* Rate and time required for CTS. */
1804 CtsTime = ComputeTxTime(14, 10, 0, 0); /* AckCTSLng = 14 use 1M bps send */
1806 /* Figure out time required to transmit this frame. */
1807 ThisFrameTime = ComputeTxTime(len + sCrcLng,
1808 rtl8180_rate2rate(rate),
1812 /* RTS-CTS-ThisFrame-ACK. */
1813 RtsDur = CtsTime + ThisFrameTime + AckTime + 3*aSifsTime;
1815 TxDescDuration = RtsTime + RtsDur;
1816 } else { /* Normal case. */
1821 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate),
1822 0, bUseShortPreamble);
1823 TxDescDuration = ThisFrameTime + aSifsTime + AckTime;
1826 if (!(frag_hdr->frame_control & IEEE80211_FCTL_MOREFRAGS)) {
1827 /* ThisFrame-ACK. */
1828 Duration = aSifsTime + AckTime;
1829 } else { /* One or more fragments remained. */
1831 NextFragTime = ComputeTxTime(len + sCrcLng, /* pretend following packet length equal current packet */
1832 rtl8180_rate2rate(rate),
1836 /* ThisFrag-ACk-NextFrag-ACK. */
1837 Duration = NextFragTime + 3*aSifsTime + 2*AckTime;
1840 } /* End of Unicast packet */
1842 frag_hdr->duration_id = Duration;
1844 buflen = priv->txbuffsize;
1848 while (remain != 0) {
1851 DMESGE("TX buffer error, cannot TX frames. pri %d.", priority);
1856 if ((*tail & (1 << 31)) && (priority != BEACON_PRIORITY)) {
1857 DMESGW("No more TX desc, returning %x of %x",
1859 priv->stats.txrdu++;
1863 *tail = 0; /* zeroes header */
1870 /* FIXME: this should be triggered by HW encryption parameters.*/
1871 *tail |= (1<<15); /* no encrypt */
1873 if (remain == len && !descfrag) {
1874 ownbit_flag = false;
1875 *tail = *tail | (1<<29) ; /* fist segment of the packet */
1876 *tail = *tail | (len);
1881 for (i = 0; i < buflen && remain > 0; i++, remain--) {
1882 ((u8 *)buf)[i] = txbuf[i]; /* copy data into descriptor pointed DMAble buffer */
1883 if (remain == 4 && i+4 >= buflen)
1885 /* ensure the last desc has at least 4 bytes payload */
1889 *(tail+3) = *(tail+3) & ~0xfff;
1890 *(tail+3) = *(tail+3) | i; /* buffer length */
1891 /* Use short preamble or not */
1892 if (priv->ieee80211->current_network.capability&WLAN_CAPABILITY_SHORT_PREAMBLE)
1893 if (priv->plcp_preamble_mode == 1 && rate != 0) /* short mode now, not long! */
1894 ; /* *tail |= (1<<16); */ /* enable short preamble mode. */
1899 if (bRTSEnable) { /* rts enable */
1900 *tail |= ((ieeerate2rtlrate(priv->ieee80211->basic_rate))<<19); /* RTS RATE */
1901 *tail |= (1<<23); /* rts enable */
1902 *(tail+1) |= (RtsDur&0xffff); /* RTS Duration */
1904 *(tail+3) |= ((TxDescDuration&0xffff)<<16); /* DURATION */
1905 /* *(tail+3) |= (0xe6<<16); */
1906 *(tail+5) |= (11<<8); /* (priv->retry_data<<8); */ /* retry lim; */
1908 *tail = *tail | ((rate&0xf) << 24);
1911 *tail = (*tail) | (1<<17); /* more fragment */
1913 *tail = (*tail) | (1<<28); /* last segment of frame */
1915 *(tail+5) = *(tail+5)|(2<<27);
1916 *(tail+7) = *(tail+7)|(1<<4);
1920 *tail = *tail | (1<<31); /* descriptor ready to be txed */
1922 if ((tail - begin)/8 == count-1)
1927 buflist = buflist->next;
1932 case MANAGE_PRIORITY:
1933 priv->txmapringtail = tail;
1934 priv->txmapbufstail = buflist;
1937 priv->txbkpringtail = tail;
1938 priv->txbkpbufstail = buflist;
1941 priv->txbepringtail = tail;
1942 priv->txbepbufstail = buflist;
1945 priv->txvipringtail = tail;
1946 priv->txvipbufstail = buflist;
1949 priv->txvopringtail = tail;
1950 priv->txvopbufstail = buflist;
1953 priv->txhpringtail = tail;
1954 priv->txhpbufstail = buflist;
1956 case BEACON_PRIORITY:
1958 * The HW seems to be happy with the 1st
1959 * descriptor filled and the 2nd empty...
1960 * So always update descriptor 1 and never
1966 *temp_tail = *temp_tail | (1<<31); /* descriptor ready to be txed */
1967 rtl8180_dma_kick(dev, priority);
1972 void rtl8180_irq_rx_tasklet(struct r8180_priv *priv);
1974 void rtl8180_link_change(struct net_device *dev)
1976 struct r8180_priv *priv = ieee80211_priv(dev);
1977 u16 beacon_interval;
1978 struct ieee80211_network *net = &priv->ieee80211->current_network;
1980 rtl8180_update_msr(dev);
1982 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1984 write_nic_dword(dev, BSSID, ((u32 *)net->bssid)[0]);
1985 write_nic_word(dev, BSSID+4, ((u16 *)net->bssid)[2]);
1987 beacon_interval = read_nic_word(dev, BEACON_INTERVAL);
1988 beacon_interval &= ~BEACON_INTERVAL_MASK;
1989 beacon_interval |= net->beacon_interval;
1990 write_nic_word(dev, BEACON_INTERVAL, beacon_interval);
1992 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1994 rtl8180_set_chan(dev, priv->chan);
1997 void rtl8180_rq_tx_ack(struct net_device *dev)
2000 struct r8180_priv *priv = ieee80211_priv(dev);
2002 write_nic_byte(dev, CONFIG4, read_nic_byte(dev, CONFIG4) | CONFIG4_PWRMGT);
2003 priv->ack_tx_to_ieee = 1;
2006 short rtl8180_is_tx_queue_empty(struct net_device *dev)
2009 struct r8180_priv *priv = ieee80211_priv(dev);
2012 for (d = priv->txmapring;
2013 d < priv->txmapring + priv->txringcount; d += 8)
2017 for (d = priv->txbkpring;
2018 d < priv->txbkpring + priv->txringcount; d += 8)
2022 for (d = priv->txbepring;
2023 d < priv->txbepring + priv->txringcount; d += 8)
2027 for (d = priv->txvipring;
2028 d < priv->txvipring + priv->txringcount; d += 8)
2032 for (d = priv->txvopring;
2033 d < priv->txvopring + priv->txringcount; d += 8)
2037 for (d = priv->txhpring;
2038 d < priv->txhpring + priv->txringcount; d += 8)
2044 void rtl8180_hw_wakeup(struct net_device *dev)
2046 unsigned long flags;
2047 struct r8180_priv *priv = ieee80211_priv(dev);
2049 spin_lock_irqsave(&priv->ps_lock, flags);
2050 write_nic_byte(dev, CONFIG4, read_nic_byte(dev, CONFIG4) & ~CONFIG4_PWRMGT);
2051 if (priv->rf_wakeup)
2052 priv->rf_wakeup(dev);
2053 spin_unlock_irqrestore(&priv->ps_lock, flags);
2056 void rtl8180_hw_sleep_down(struct net_device *dev)
2058 unsigned long flags;
2059 struct r8180_priv *priv = ieee80211_priv(dev);
2061 spin_lock_irqsave(&priv->ps_lock, flags);
2063 priv->rf_sleep(dev);
2064 spin_unlock_irqrestore(&priv->ps_lock, flags);
2067 void rtl8180_hw_sleep(struct net_device *dev, u32 th, u32 tl)
2069 struct r8180_priv *priv = ieee80211_priv(dev);
2071 unsigned long flags;
2073 spin_lock_irqsave(&priv->ps_lock, flags);
2076 * Writing HW register with 0 equals to disable
2077 * the timer, that is not really what we want
2079 tl -= MSECS(4+16+7);
2082 * If the interval in witch we are requested to sleep is too
2083 * short then give up and remain awake
2085 if (((tl >= rb) && (tl-rb) <= MSECS(MIN_SLEEP_TIME))
2086 || ((rb > tl) && (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
2087 spin_unlock_irqrestore(&priv->ps_lock, flags);
2088 printk("too short to sleep\n");
2093 u32 tmp = (tl > rb) ? (tl-rb) : (rb-tl);
2095 priv->DozePeriodInPast2Sec += jiffies_to_msecs(tmp);
2096 /* as tl may be less than rb */
2097 queue_delayed_work(priv->ieee80211->wq, &priv->ieee80211->hw_wakeup_wq, tmp);
2100 * If we suspect the TimerInt is gone beyond tl
2101 * while setting it, then give up
2104 if (((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME))) ||
2105 ((tl < rb) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))) {
2106 spin_unlock_irqrestore(&priv->ps_lock, flags);
2110 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_sleep_wq);
2111 spin_unlock_irqrestore(&priv->ps_lock, flags);
2114 void rtl8180_wmm_param_update(struct work_struct *work)
2116 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, wmm_param_update_wq);
2117 struct net_device *dev = ieee->dev;
2118 u8 *ac_param = (u8 *)(ieee->current_network.wmm_param);
2119 u8 mode = ieee->current_network.mode;
2125 if (!ieee->current_network.QoS_Enable) {
2126 /* legacy ac_xx_param update */
2127 AcParam.longData = 0;
2128 AcParam.f.AciAifsn.f.AIFSN = 2; /* Follow 802.11 DIFS. */
2129 AcParam.f.AciAifsn.f.ACM = 0;
2130 AcParam.f.Ecw.f.ECWmin = 3; /* Follow 802.11 CWmin. */
2131 AcParam.f.Ecw.f.ECWmax = 7; /* Follow 802.11 CWmax. */
2132 AcParam.f.TXOPLimit = 0;
2133 for (eACI = 0; eACI < AC_MAX; eACI++) {
2134 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
2138 pAcParam = (PAC_PARAM)(&AcParam);
2139 /* Retrieve parameters to update. */
2140 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G) ? 9 : 20) + aSifsTime;
2141 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit))<<AC_PARAM_TXOP_LIMIT_OFFSET)|
2142 (((u32)(pAcParam->f.Ecw.f.ECWmax))<<AC_PARAM_ECW_MAX_OFFSET)|
2143 (((u32)(pAcParam->f.Ecw.f.ECWmin))<<AC_PARAM_ECW_MIN_OFFSET)|
2144 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
2147 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
2150 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
2153 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
2156 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
2159 pr_warn("SetHwReg8185():invalid ACI: %d!\n",
2168 for (i = 0; i < AC_MAX; i++) {
2169 /* AcParam.longData = 0; */
2170 pAcParam = (AC_PARAM *)ac_param;
2176 /* Retrieve parameters to update. */
2177 eACI = pAcParam->f.AciAifsn.f.ACI;
2178 /* Mode G/A: slotTimeTimer = 9; Mode B: 20 */
2179 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G) ? 9 : 20) + aSifsTime;
2180 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
2181 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
2182 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
2183 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
2187 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
2190 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
2193 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
2196 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
2199 pr_warn("SetHwReg8185(): invalid ACI: %d !\n",
2204 ac_param += (sizeof(AC_PARAM));
2208 void rtl8180_restart_wq(struct work_struct *work);
2209 /* void rtl8180_rq_tx_ack(struct work_struct *work); */
2210 void rtl8180_watch_dog_wq(struct work_struct *work);
2211 void rtl8180_hw_wakeup_wq(struct work_struct *work);
2212 void rtl8180_hw_sleep_wq(struct work_struct *work);
2213 void rtl8180_sw_antenna_wq(struct work_struct *work);
2214 void rtl8180_watch_dog(struct net_device *dev);
2216 void watch_dog_adaptive(unsigned long data)
2218 struct r8180_priv *priv = ieee80211_priv((struct net_device *)data);
2221 DMESG("<----watch_dog_adaptive():driver is not up!\n");
2225 /* Tx High Power Mechanism. */
2226 if (CheckHighPower((struct net_device *)data))
2227 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->tx_pw_wq);
2229 /* Tx Power Tracking on 87SE. */
2230 if (CheckTxPwrTracking((struct net_device *)data))
2231 TxPwrTracking87SE((struct net_device *)data);
2233 /* Perform DIG immediately. */
2234 if (CheckDig((struct net_device *)data) == true)
2235 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_dig_wq);
2236 rtl8180_watch_dog((struct net_device *)data);
2238 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->GPIOChangeRFWorkItem);
2240 priv->watch_dog_timer.expires = jiffies + MSECS(IEEE80211_WATCH_DOG_TIME);
2241 add_timer(&priv->watch_dog_timer);
2244 static CHANNEL_LIST ChannelPlan[] = {
2245 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64},19}, /* FCC */
2246 {{1,2,3,4,5,6,7,8,9,10,11},11}, /* IC */
2247 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, /* ETSI */
2248 {{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. */
2249 {{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. */
2250 {{14,36,40,44,48,52,56,60,64},9}, /* MKK */
2251 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14, 36,40,44,48,52,56,60,64},22},/* MKK1 */
2252 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, /* Israel. */
2253 {{1,2,3,4,5,6,7,8,9,10,11,12,13,34,38,42,46},17}, /* For 11a , TELEC */
2254 {{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 */
2255 {{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 */
2258 static void rtl8180_set_channel_map(u8 channel_plan, struct ieee80211_device *ieee)
2262 /* lzm add 080826 */
2263 ieee->MinPassiveChnlNum = MAX_CHANNEL_NUMBER+1;
2264 ieee->IbssStartChnl = 0;
2266 switch (channel_plan) {
2267 case COUNTRY_CODE_FCC:
2268 case COUNTRY_CODE_IC:
2269 case COUNTRY_CODE_ETSI:
2270 case COUNTRY_CODE_SPAIN:
2271 case COUNTRY_CODE_FRANCE:
2272 case COUNTRY_CODE_MKK:
2273 case COUNTRY_CODE_MKK1:
2274 case COUNTRY_CODE_ISRAEL:
2275 case COUNTRY_CODE_TELEC:
2278 ieee->bGlobalDomain = false;
2279 if (ChannelPlan[channel_plan].Len != 0) {
2280 /* Clear old channel map */
2281 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
2282 /* Set new channel map */
2283 for (i = 0; i < ChannelPlan[channel_plan].Len; i++) {
2284 if (ChannelPlan[channel_plan].Channel[i] <= 14)
2285 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
2290 case COUNTRY_CODE_GLOBAL_DOMAIN:
2292 GET_DOT11D_INFO(ieee)->bEnabled = 0;
2294 ieee->bGlobalDomain = true;
2297 case COUNTRY_CODE_WORLD_WIDE_13_INDEX:/* lzm add 080826 */
2299 ieee->MinPassiveChnlNum = 12;
2300 ieee->IbssStartChnl = 10;
2306 ieee->bGlobalDomain = false;
2307 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
2308 for (i = 1; i <= 14; i++)
2309 GET_DOT11D_INFO(ieee)->channel_map[i] = 1;
2315 void GPIOChangeRFWorkItemCallBack(struct work_struct *work);
2318 static void rtl8180_statistics_init(struct Stats *pstats)
2320 memset(pstats, 0, sizeof(struct Stats));
2323 static void rtl8180_link_detect_init(plink_detect_t plink_detect)
2325 memset(plink_detect, 0, sizeof(link_detect_t));
2326 plink_detect->SlotNum = DEFAULT_SLOT_NUM;
2329 /* YJ,add,080828,end */
2330 static void rtl8187se_eeprom_register_read(struct eeprom_93cx6 *eeprom)
2332 struct net_device *dev = eeprom->data;
2333 u8 reg = read_nic_byte(dev, EPROM_CMD);
2335 eeprom->reg_data_in = reg & RTL818X_EEPROM_CMD_WRITE;
2336 eeprom->reg_data_out = reg & RTL818X_EEPROM_CMD_READ;
2337 eeprom->reg_data_clock = reg & RTL818X_EEPROM_CMD_CK;
2338 eeprom->reg_chip_select = reg & RTL818X_EEPROM_CMD_CS;
2341 static void rtl8187se_eeprom_register_write(struct eeprom_93cx6 *eeprom)
2343 struct net_device *dev = eeprom->data;
2346 if (eeprom->reg_data_in)
2347 reg |= RTL818X_EEPROM_CMD_WRITE;
2348 if (eeprom->reg_data_out)
2349 reg |= RTL818X_EEPROM_CMD_READ;
2350 if (eeprom->reg_data_clock)
2351 reg |= RTL818X_EEPROM_CMD_CK;
2352 if (eeprom->reg_chip_select)
2353 reg |= RTL818X_EEPROM_CMD_CS;
2355 write_nic_byte(dev, EPROM_CMD, reg);
2356 read_nic_byte(dev, EPROM_CMD);
2360 short rtl8180_init(struct net_device *dev)
2362 struct r8180_priv *priv = ieee80211_priv(dev);
2367 struct eeprom_93cx6 eeprom;
2371 eeprom.register_read = rtl8187se_eeprom_register_read;
2372 eeprom.register_write = rtl8187se_eeprom_register_write;
2373 eeprom.width = PCI_EEPROM_WIDTH_93C46;
2375 eeprom_93cx6_read(&eeprom, EEPROM_COUNTRY_CODE>>1, &eeprom_val);
2376 priv->channel_plan = eeprom_val & 0xFF;
2377 if (priv->channel_plan > COUNTRY_CODE_GLOBAL_DOMAIN) {
2378 printk("rtl8180_init:Error channel plan! Set to default.\n");
2379 priv->channel_plan = 0;
2382 DMESG("Channel plan is %d\n", priv->channel_plan);
2383 rtl8180_set_channel_map(priv->channel_plan, priv->ieee80211);
2385 /* FIXME: these constants are placed in a bad pleace. */
2386 priv->txbuffsize = 2048; /* 1024; */
2387 priv->txringcount = 32; /* 32; */
2388 priv->rxbuffersize = 2048; /* 1024; */
2389 priv->rxringcount = 64; /* 32; */
2390 priv->txbeaconcount = 2;
2391 priv->rx_skb_complete = 1;
2393 priv->RFChangeInProgress = false;
2394 priv->SetRFPowerStateInProgress = false;
2395 priv->RFProgType = 0;
2397 priv->irq_enabled = 0;
2399 rtl8180_statistics_init(&priv->stats);
2400 rtl8180_link_detect_init(&priv->link_detect);
2402 priv->ack_tx_to_ieee = 0;
2403 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
2404 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2405 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
2406 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
2407 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;
2408 priv->ieee80211->active_scan = 1;
2409 priv->ieee80211->rate = 110; /* 11 mbps */
2410 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION;
2411 priv->ieee80211->host_encrypt = 1;
2412 priv->ieee80211->host_decrypt = 1;
2413 priv->ieee80211->sta_wake_up = rtl8180_hw_wakeup;
2414 priv->ieee80211->ps_request_tx_ack = rtl8180_rq_tx_ack;
2415 priv->ieee80211->enter_sleep_state = rtl8180_hw_sleep;
2416 priv->ieee80211->ps_is_queue_empty = rtl8180_is_tx_queue_empty;
2418 priv->hw_wep = hwwep;
2420 priv->retry_rts = DEFAULT_RETRY_RTS;
2421 priv->retry_data = DEFAULT_RETRY_DATA;
2422 priv->RFChangeInProgress = false;
2423 priv->SetRFPowerStateInProgress = false;
2424 priv->RFProgType = 0;
2425 priv->bInactivePs = true; /* false; */
2426 priv->ieee80211->bInactivePs = priv->bInactivePs;
2427 priv->bSwRfProcessing = false;
2428 priv->eRFPowerState = eRfOff;
2429 priv->RfOffReason = 0;
2430 priv->LedStrategy = SW_LED_MODE0;
2431 priv->TxPollingTimes = 0; /* lzm add 080826 */
2432 priv->bLeisurePs = true;
2433 priv->dot11PowerSaveMode = eActive;
2434 priv->AdMinCheckPeriod = 5;
2435 priv->AdMaxCheckPeriod = 10;
2436 priv->AdMaxRxSsThreshold = 30; /* 60->30 */
2437 priv->AdRxSsThreshold = 20; /* 50->20 */
2438 priv->AdCheckPeriod = priv->AdMinCheckPeriod;
2439 priv->AdTickCount = 0;
2440 priv->AdRxSignalStrength = -1;
2441 priv->RegSwAntennaDiversityMechanism = 0;
2442 priv->RegDefaultAntenna = 0;
2443 priv->SignalStrength = 0;
2444 priv->AdRxOkCnt = 0;
2445 priv->CurrAntennaIndex = 0;
2446 priv->AdRxSsBeforeSwitched = 0;
2447 init_timer(&priv->SwAntennaDiversityTimer);
2448 priv->SwAntennaDiversityTimer.data = (unsigned long)dev;
2449 priv->SwAntennaDiversityTimer.function = (void *)SwAntennaDiversityTimerCallback;
2450 priv->bDigMechanism = 1;
2451 priv->InitialGain = 6;
2452 priv->bXtalCalibration = false;
2453 priv->XtalCal_Xin = 0;
2454 priv->XtalCal_Xout = 0;
2455 priv->bTxPowerTrack = false;
2456 priv->ThermalMeter = 0;
2457 priv->FalseAlarmRegValue = 0;
2458 priv->RegDigOfdmFaUpTh = 0xc; /* Upper threshold of OFDM false alarm, which is used in DIG. */
2459 priv->DIG_NumberFallbackVote = 0;
2460 priv->DIG_NumberUpgradeVote = 0;
2461 priv->LastSignalStrengthInPercent = 0;
2462 priv->Stats_SignalStrength = 0;
2463 priv->LastRxPktAntenna = 0;
2464 priv->SignalQuality = 0; /* in 0-100 index. */
2465 priv->Stats_SignalQuality = 0;
2466 priv->RecvSignalPower = 0; /* in dBm. */
2467 priv->Stats_RecvSignalPower = 0;
2468 priv->AdMainAntennaRxOkCnt = 0;
2469 priv->AdAuxAntennaRxOkCnt = 0;
2470 priv->bHWAdSwitched = false;
2471 priv->bRegHighPowerMechanism = true;
2472 priv->RegHiPwrUpperTh = 77;
2473 priv->RegHiPwrLowerTh = 75;
2474 priv->RegRSSIHiPwrUpperTh = 70;
2475 priv->RegRSSIHiPwrLowerTh = 20;
2476 priv->bCurCCKPkt = false;
2477 priv->UndecoratedSmoothedSS = -1;
2478 priv->bToUpdateTxPwr = false;
2479 priv->CurCCKRSSI = 0;
2482 priv->NumTxOkTotal = 0;
2483 priv->NumTxUnicast = 0;
2484 priv->keepAliveLevel = DEFAULT_KEEP_ALIVE_LEVEL;
2485 priv->CurrRetryCnt = 0;
2486 priv->LastRetryCnt = 0;
2487 priv->LastTxokCnt = 0;
2488 priv->LastRxokCnt = 0;
2489 priv->LastRetryRate = 0;
2490 priv->bTryuping = 0;
2491 priv->CurrTxRate = 0;
2492 priv->CurrRetryRate = 0;
2493 priv->TryupingCount = 0;
2494 priv->TryupingCountNoData = 0;
2495 priv->TryDownCountLowData = 0;
2496 priv->LastTxOKBytes = 0;
2497 priv->LastFailTxRate = 0;
2498 priv->LastFailTxRateSS = 0;
2499 priv->FailTxRateCount = 0;
2500 priv->LastTxThroughput = 0;
2501 priv->NumTxOkBytesTotal = 0;
2502 priv->ForcedDataRate = 0;
2503 priv->RegBModeGainStage = 1;
2505 priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
2506 spin_lock_init(&priv->irq_th_lock);
2507 spin_lock_init(&priv->tx_lock);
2508 spin_lock_init(&priv->ps_lock);
2509 spin_lock_init(&priv->rf_ps_lock);
2510 sema_init(&priv->wx_sem, 1);
2511 INIT_WORK(&priv->reset_wq, (void *)rtl8180_restart_wq);
2512 INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,
2513 (void *)rtl8180_hw_wakeup_wq);
2514 INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,
2515 (void *)rtl8180_hw_sleep_wq);
2516 INIT_WORK(&priv->ieee80211->wmm_param_update_wq,
2517 (void *)rtl8180_wmm_param_update);
2518 INIT_DELAYED_WORK(&priv->ieee80211->rate_adapter_wq,
2519 (void *)rtl8180_rate_adapter);
2520 INIT_DELAYED_WORK(&priv->ieee80211->hw_dig_wq,
2521 (void *)rtl8180_hw_dig_wq);
2522 INIT_DELAYED_WORK(&priv->ieee80211->tx_pw_wq,
2523 (void *)rtl8180_tx_pw_wq);
2524 INIT_DELAYED_WORK(&priv->ieee80211->GPIOChangeRFWorkItem,
2525 (void *) GPIOChangeRFWorkItemCallBack);
2526 tasklet_init(&priv->irq_rx_tasklet,
2527 (void(*)(unsigned long)) rtl8180_irq_rx_tasklet,
2528 (unsigned long)priv);
2530 init_timer(&priv->watch_dog_timer);
2531 priv->watch_dog_timer.data = (unsigned long)dev;
2532 priv->watch_dog_timer.function = watch_dog_adaptive;
2534 init_timer(&priv->rateadapter_timer);
2535 priv->rateadapter_timer.data = (unsigned long)dev;
2536 priv->rateadapter_timer.function = timer_rate_adaptive;
2537 priv->RateAdaptivePeriod = RATE_ADAPTIVE_TIMER_PERIOD;
2538 priv->bEnhanceTxPwr = false;
2540 priv->ieee80211->softmac_hard_start_xmit = rtl8180_hard_start_xmit;
2541 priv->ieee80211->set_chan = rtl8180_set_chan;
2542 priv->ieee80211->link_change = rtl8180_link_change;
2543 priv->ieee80211->softmac_data_hard_start_xmit = rtl8180_hard_data_xmit;
2544 priv->ieee80211->data_hard_stop = rtl8180_data_hard_stop;
2545 priv->ieee80211->data_hard_resume = rtl8180_data_hard_resume;
2547 priv->ieee80211->init_wmmparam_flag = 0;
2549 priv->ieee80211->start_send_beacons = rtl8180_start_tx_beacon;
2550 priv->ieee80211->stop_send_beacons = rtl8180_beacon_tx_disable;
2551 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
2553 priv->ShortRetryLimit = 7;
2554 priv->LongRetryLimit = 7;
2555 priv->EarlyRxThreshold = 7;
2557 priv->TransmitConfig = (1<<TCR_DurProcMode_OFFSET) |
2558 (7<<TCR_MXDMA_OFFSET) |
2559 (priv->ShortRetryLimit<<TCR_SRL_OFFSET) |
2560 (priv->LongRetryLimit<<TCR_LRL_OFFSET);
2562 priv->ReceiveConfig = RCR_AMF | RCR_ADF | RCR_ACF |
2563 RCR_AB | RCR_AM | RCR_APM |
2564 (7<<RCR_MXDMA_OFFSET) |
2565 (priv->EarlyRxThreshold<<RCR_FIFO_OFFSET) |
2566 (priv->EarlyRxThreshold == 7 ?
2567 RCR_ONLYERLPKT : 0);
2569 priv->IntrMask = IMR_TMGDOK | IMR_TBDER | IMR_THPDER |
2570 IMR_THPDER | IMR_THPDOK |
2571 IMR_TVODER | IMR_TVODOK |
2572 IMR_TVIDER | IMR_TVIDOK |
2573 IMR_TBEDER | IMR_TBEDOK |
2574 IMR_TBKDER | IMR_TBKDOK |
2579 priv->InitialGain = 6;
2581 DMESG("MAC controller is a RTL8187SE b/g");
2583 priv->ieee80211->modulation |= IEEE80211_OFDM_MODULATION;
2584 priv->ieee80211->short_slot = 1;
2586 eeprom_93cx6_read(&eeprom, EEPROM_SW_REVD_OFFSET, &usValue);
2587 DMESG("usValue is %#hx\n", usValue);
2588 /* 3Read AntennaDiversity */
2590 /* SW Antenna Diversity. */
2591 priv->EEPROMSwAntennaDiversity = (usValue & EEPROM_SW_AD_MASK) ==
2592 EEPROM_SW_AD_ENABLE;
2594 /* Default Antenna to use. */
2595 priv->EEPROMDefaultAntenna1 = (usValue & EEPROM_DEF_ANT_MASK) ==
2598 if (priv->RegSwAntennaDiversityMechanism == 0) /* Auto */
2599 /* 0: default from EEPROM. */
2600 priv->bSwAntennaDiverity = priv->EEPROMSwAntennaDiversity;
2602 /* 1:disable antenna diversity, 2: enable antenna diversity. */
2603 priv->bSwAntennaDiverity = priv->RegSwAntennaDiversityMechanism == 2;
2605 if (priv->RegDefaultAntenna == 0)
2606 /* 0: default from EEPROM. */
2607 priv->bDefaultAntenna1 = priv->EEPROMDefaultAntenna1;
2609 /* 1: main, 2: aux. */
2610 priv->bDefaultAntenna1 = priv->RegDefaultAntenna == 2;
2612 priv->plcp_preamble_mode = 2;
2613 /* the eeprom type is stored in RCR register bit #6 */
2614 if (RCR_9356SEL & read_nic_dword(dev, RCR))
2615 priv->epromtype = EPROM_93c56;
2617 priv->epromtype = EPROM_93c46;
2619 eeprom_93cx6_multiread(&eeprom, 0x7, (__le16 *)
2622 for (i = 1, j = 0; i < 14; i += 2, j++) {
2623 eeprom_93cx6_read(&eeprom, EPROM_TXPW_CH1_2 + j, &word);
2624 priv->chtxpwr[i] = word & 0xff;
2625 priv->chtxpwr[i+1] = (word & 0xff00)>>8;
2627 for (i = 1, j = 0; i < 14; i += 2, j++) {
2628 eeprom_93cx6_read(&eeprom, EPROM_TXPW_OFDM_CH1_2 + j, &word);
2629 priv->chtxpwr_ofdm[i] = word & 0xff;
2630 priv->chtxpwr_ofdm[i+1] = (word & 0xff00) >> 8;
2633 /* 3Read crystal calibration and thermal meter indication on 87SE. */
2634 eeprom_93cx6_read(&eeprom, EEPROM_RSV>>1, &tmpu16);
2636 /* Crystal calibration for Xin and Xout resp. */
2637 priv->XtalCal_Xout = tmpu16 & EEPROM_XTAL_CAL_XOUT_MASK;
2638 priv->XtalCal_Xin = (tmpu16 & EEPROM_XTAL_CAL_XIN_MASK) >> 4;
2639 if ((tmpu16 & EEPROM_XTAL_CAL_ENABLE) >> 12)
2640 priv->bXtalCalibration = true;
2642 /* Thermal meter reference indication. */
2643 priv->ThermalMeter = (u8)((tmpu16 & EEPROM_THERMAL_METER_MASK) >> 8);
2644 if ((tmpu16 & EEPROM_THERMAL_METER_ENABLE) >> 13)
2645 priv->bTxPowerTrack = true;
2647 priv->rf_sleep = rtl8225z4_rf_sleep;
2648 priv->rf_wakeup = rtl8225z4_rf_wakeup;
2649 DMESGW("**PLEASE** REPORT SUCCESSFUL/UNSUCCESSFUL TO Realtek!");
2651 priv->rf_close = rtl8225z2_rf_close;
2652 priv->rf_init = rtl8225z2_rf_init;
2653 priv->rf_set_chan = rtl8225z2_rf_set_chan;
2654 priv->rf_set_sens = NULL;
2656 if (0 != alloc_rx_desc_ring(dev, priv->rxbuffersize, priv->rxringcount))
2659 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2660 TX_MANAGEPRIORITY_RING_ADDR))
2663 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2664 TX_BKPRIORITY_RING_ADDR))
2667 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2668 TX_BEPRIORITY_RING_ADDR))
2671 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2672 TX_VIPRIORITY_RING_ADDR))
2675 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2676 TX_VOPRIORITY_RING_ADDR))
2679 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2680 TX_HIGHPRIORITY_RING_ADDR))
2683 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txbeaconcount,
2684 TX_BEACON_RING_ADDR))
2687 if (request_irq(dev->irq, (void *)rtl8180_interrupt, IRQF_SHARED, dev->name, dev)) {
2688 DMESGE("Error allocating IRQ %d", dev->irq);
2691 priv->irq = dev->irq;
2692 DMESG("IRQ %d", dev->irq);
2698 void rtl8180_no_hw_wep(struct net_device *dev)
2702 void rtl8180_set_hw_wep(struct net_device *dev)
2704 struct r8180_priv *priv = ieee80211_priv(dev);
2709 pgreg = read_nic_byte(dev, PGSELECT);
2710 write_nic_byte(dev, PGSELECT, pgreg & ~(1<<PGSELECT_PG_SHIFT));
2712 key0_word4 = read_nic_dword(dev, KEY0+4+4+4);
2713 key0_word4 &= ~0xff;
2714 key0_word4 |= priv->key0[3] & 0xff;
2715 write_nic_dword(dev, KEY0, (priv->key0[0]));
2716 write_nic_dword(dev, KEY0+4, (priv->key0[1]));
2717 write_nic_dword(dev, KEY0+4+4, (priv->key0[2]));
2718 write_nic_dword(dev, KEY0+4+4+4, (key0_word4));
2720 security = read_nic_byte(dev, SECURITY);
2721 security |= (1<<SECURITY_WEP_TX_ENABLE_SHIFT);
2722 security |= (1<<SECURITY_WEP_RX_ENABLE_SHIFT);
2723 security &= ~SECURITY_ENCRYP_MASK;
2724 security |= (SECURITY_ENCRYP_104<<SECURITY_ENCRYP_SHIFT);
2726 write_nic_byte(dev, SECURITY, security);
2728 DMESG("key %x %x %x %x", read_nic_dword(dev, KEY0+4+4+4),
2729 read_nic_dword(dev, KEY0+4+4), read_nic_dword(dev, KEY0+4),
2730 read_nic_dword(dev, KEY0));
2734 void rtl8185_rf_pins_enable(struct net_device *dev)
2737 /* tmp = read_nic_word(dev, RFPinsEnable); */
2738 write_nic_word(dev, RFPinsEnable, 0x1fff); /* | tmp); */
2741 void rtl8185_set_anaparam2(struct net_device *dev, u32 a)
2745 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
2747 conf3 = read_nic_byte(dev, CONFIG3);
2748 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
2749 write_nic_dword(dev, ANAPARAM2, a);
2751 conf3 = read_nic_byte(dev, CONFIG3);
2752 write_nic_byte(dev, CONFIG3, conf3 & ~(1<<CONFIG3_ANAPARAM_W_SHIFT));
2753 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2756 void rtl8180_set_anaparam(struct net_device *dev, u32 a)
2760 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
2762 conf3 = read_nic_byte(dev, CONFIG3);
2763 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
2764 write_nic_dword(dev, ANAPARAM, a);
2766 conf3 = read_nic_byte(dev, CONFIG3);
2767 write_nic_byte(dev, CONFIG3, conf3 & ~(1<<CONFIG3_ANAPARAM_W_SHIFT));
2768 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2771 void rtl8185_tx_antenna(struct net_device *dev, u8 ant)
2773 write_nic_byte(dev, TX_ANTENNA, ant);
2774 force_pci_posting(dev);
2778 void rtl8185_write_phy(struct net_device *dev, u8 adr, u32 data)
2784 phyw = ((data<<8) | adr);
2786 /* Note that, we must write 0xff7c after 0x7d-0x7f to write BB register. */
2787 write_nic_byte(dev, 0x7f, ((phyw & 0xff000000) >> 24));
2788 write_nic_byte(dev, 0x7e, ((phyw & 0x00ff0000) >> 16));
2789 write_nic_byte(dev, 0x7d, ((phyw & 0x0000ff00) >> 8));
2790 write_nic_byte(dev, 0x7c, ((phyw & 0x000000ff)));
2792 /* this is ok to fail when we write AGC table. check for AGC table might be
2793 * done by masking with 0x7f instead of 0xff
2795 /* if (phyr != (data&0xff)) DMESGW("Phy write timeout %x %x %x", phyr, data, adr); */
2798 inline void write_phy_ofdm(struct net_device *dev, u8 adr, u32 data)
2801 rtl8185_write_phy(dev, adr, data);
2804 void write_phy_cck(struct net_device *dev, u8 adr, u32 data)
2807 rtl8185_write_phy(dev, adr, data | 0x10000);
2811 * This configures registers for beacon tx and enables it via
2812 * rtl8180_beacon_tx_enable(). rtl8180_beacon_tx_disable() might
2813 * be used to stop beacon transmission
2815 void rtl8180_start_tx_beacon(struct net_device *dev)
2819 DMESG("Enabling beacon TX");
2820 rtl8180_prepare_beacon(dev);
2821 rtl8180_irq_disable(dev);
2822 rtl8180_beacon_tx_enable(dev);
2824 word = read_nic_word(dev, AtimWnd) & ~AtimWnd_AtimWnd;
2825 write_nic_word(dev, AtimWnd, word); /* word |= */
2827 word = read_nic_word(dev, BintrItv);
2828 word &= ~BintrItv_BintrItv;
2829 word |= 1000; /* priv->ieee80211->current_network.beacon_interval *
2830 ((priv->txbeaconcount > 1)?(priv->txbeaconcount-1):1);
2831 // FIXME: check if correct ^^ worked with 0x3e8;
2833 write_nic_word(dev, BintrItv, word);
2835 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2837 rtl8185b_irq_enable(dev);
2840 static struct net_device_stats *rtl8180_stats(struct net_device *dev)
2842 struct r8180_priv *priv = ieee80211_priv(dev);
2844 return &priv->ieee80211->stats;
2848 * Change current and default preamble mode.
2851 MgntActSet_802_11_PowerSaveMode(
2852 struct r8180_priv *priv,
2856 /* Currently, we do not change power save mode on IBSS mode. */
2857 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
2860 priv->ieee80211->ps = rtPsMode;
2865 void LeisurePSEnter(struct r8180_priv *priv)
2867 if (priv->bLeisurePs) {
2868 if (priv->ieee80211->ps == IEEE80211_PS_DISABLED)
2869 /* IEEE80211_PS_ENABLE */
2870 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST);
2874 void LeisurePSLeave(struct r8180_priv *priv)
2876 if (priv->bLeisurePs) {
2877 if (priv->ieee80211->ps != IEEE80211_PS_DISABLED)
2878 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_DISABLED);
2882 void rtl8180_hw_wakeup_wq(struct work_struct *work)
2884 struct delayed_work *dwork = to_delayed_work(work);
2885 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, hw_wakeup_wq);
2886 struct net_device *dev = ieee->dev;
2888 rtl8180_hw_wakeup(dev);
2891 void rtl8180_hw_sleep_wq(struct work_struct *work)
2893 struct delayed_work *dwork = to_delayed_work(work);
2894 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, hw_sleep_wq);
2895 struct net_device *dev = ieee->dev;
2897 rtl8180_hw_sleep_down(dev);
2900 static void MgntLinkKeepAlive(struct r8180_priv *priv)
2902 if (priv->keepAliveLevel == 0)
2905 if (priv->ieee80211->state == IEEE80211_LINKED) {
2910 if ((priv->keepAliveLevel == 2) ||
2911 (priv->link_detect.LastNumTxUnicast == priv->NumTxUnicast &&
2912 priv->link_detect.LastNumRxUnicast == priv->ieee80211->NumRxUnicast)
2914 priv->link_detect.IdleCount++;
2917 * Send a Keep-Alive packet packet to AP if we had been idle for a while.
2919 if (priv->link_detect.IdleCount >= ((KEEP_ALIVE_INTERVAL / CHECK_FOR_HANG_PERIOD)-1)) {
2920 priv->link_detect.IdleCount = 0;
2921 ieee80211_sta_ps_send_null_frame(priv->ieee80211, false);
2924 priv->link_detect.IdleCount = 0;
2926 priv->link_detect.LastNumTxUnicast = priv->NumTxUnicast;
2927 priv->link_detect.LastNumRxUnicast = priv->ieee80211->NumRxUnicast;
2931 void rtl8180_watch_dog(struct net_device *dev)
2933 struct r8180_priv *priv = ieee80211_priv(dev);
2934 bool bEnterPS = false;
2935 bool bBusyTraffic = false;
2939 if (priv->ieee80211->actscanning == false) {
2940 if ((priv->ieee80211->iw_mode != IW_MODE_ADHOC) &&
2941 (priv->ieee80211->state == IEEE80211_NOLINK) &&
2942 (priv->ieee80211->beinretry == false) &&
2943 (priv->eRFPowerState == eRfOn))
2946 /* YJ,add,080828,for link state check */
2947 if ((priv->ieee80211->state == IEEE80211_LINKED) && (priv->ieee80211->iw_mode == IW_MODE_INFRA)) {
2948 SlotIndex = (priv->link_detect.SlotIndex++) % priv->link_detect.SlotNum;
2949 priv->link_detect.RxFrameNum[SlotIndex] = priv->ieee80211->NumRxDataInPeriod + priv->ieee80211->NumRxBcnInPeriod;
2950 for (i = 0; i < priv->link_detect.SlotNum; i++)
2951 TotalRxNum += priv->link_detect.RxFrameNum[i];
2953 if (TotalRxNum == 0) {
2954 priv->ieee80211->state = IEEE80211_ASSOCIATING;
2955 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
2959 /* YJ,add,080828,for KeepAlive */
2960 MgntLinkKeepAlive(priv);
2962 /* YJ,add,080828,for LPS */
2963 LeisurePSLeave(priv);
2965 if (priv->ieee80211->state == IEEE80211_LINKED) {
2966 priv->link_detect.NumRxOkInPeriod = priv->ieee80211->NumRxDataInPeriod;
2967 if (priv->link_detect.NumRxOkInPeriod > 666 ||
2968 priv->link_detect.NumTxOkInPeriod > 666) {
2969 bBusyTraffic = true;
2971 if (((priv->link_detect.NumRxOkInPeriod + priv->link_detect.NumTxOkInPeriod) > 8)
2972 || (priv->link_detect.NumRxOkInPeriod > 2)) {
2978 LeisurePSEnter(priv);
2980 LeisurePSLeave(priv);
2982 LeisurePSLeave(priv);
2983 priv->link_detect.bBusyTraffic = bBusyTraffic;
2984 priv->link_detect.NumRxOkInPeriod = 0;
2985 priv->link_detect.NumTxOkInPeriod = 0;
2986 priv->ieee80211->NumRxDataInPeriod = 0;
2987 priv->ieee80211->NumRxBcnInPeriod = 0;
2990 int _rtl8180_up(struct net_device *dev)
2992 struct r8180_priv *priv = ieee80211_priv(dev);
2996 DMESG("Bringing up iface");
2997 rtl8185b_adapter_start(dev);
2998 rtl8185b_rx_enable(dev);
2999 rtl8185b_tx_enable(dev);
3000 if (priv->bInactivePs) {
3001 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3004 timer_rate_adaptive((unsigned long)dev);
3005 watch_dog_adaptive((unsigned long)dev);
3006 if (priv->bSwAntennaDiverity)
3007 SwAntennaDiversityTimerCallback(dev);
3008 ieee80211_softmac_start_protocol(priv->ieee80211);
3012 int rtl8180_open(struct net_device *dev)
3014 struct r8180_priv *priv = ieee80211_priv(dev);
3017 down(&priv->wx_sem);
3018 ret = rtl8180_up(dev);
3023 int rtl8180_up(struct net_device *dev)
3025 struct r8180_priv *priv = ieee80211_priv(dev);
3030 return _rtl8180_up(dev);
3033 int rtl8180_close(struct net_device *dev)
3035 struct r8180_priv *priv = ieee80211_priv(dev);
3038 down(&priv->wx_sem);
3039 ret = rtl8180_down(dev);
3045 int rtl8180_down(struct net_device *dev)
3047 struct r8180_priv *priv = ieee80211_priv(dev);
3054 ieee80211_softmac_stop_protocol(priv->ieee80211);
3056 if (!netif_queue_stopped(dev))
3057 netif_stop_queue(dev);
3058 rtl8180_rtx_disable(dev);
3059 rtl8180_irq_disable(dev);
3060 del_timer_sync(&priv->watch_dog_timer);
3061 del_timer_sync(&priv->rateadapter_timer);
3062 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
3063 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
3064 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
3065 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
3066 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
3067 del_timer_sync(&priv->SwAntennaDiversityTimer);
3068 SetZebraRFPowerState8185(dev, eRfOff);
3069 memset(&(priv->ieee80211->current_network), 0, sizeof(struct ieee80211_network));
3070 priv->ieee80211->state = IEEE80211_NOLINK;
3074 void rtl8180_restart_wq(struct work_struct *work)
3076 struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
3077 struct net_device *dev = priv->dev;
3079 down(&priv->wx_sem);
3081 rtl8180_commit(dev);
3086 void rtl8180_restart(struct net_device *dev)
3088 struct r8180_priv *priv = ieee80211_priv(dev);
3090 schedule_work(&priv->reset_wq);
3093 void rtl8180_commit(struct net_device *dev)
3095 struct r8180_priv *priv = ieee80211_priv(dev);
3100 del_timer_sync(&priv->watch_dog_timer);
3101 del_timer_sync(&priv->rateadapter_timer);
3102 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
3103 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
3104 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
3105 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
3106 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
3107 del_timer_sync(&priv->SwAntennaDiversityTimer);
3108 ieee80211_softmac_stop_protocol(priv->ieee80211);
3109 rtl8180_irq_disable(dev);
3110 rtl8180_rtx_disable(dev);
3114 static void r8180_set_multicast(struct net_device *dev)
3116 struct r8180_priv *priv = ieee80211_priv(dev);
3119 promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
3121 if (promisc != priv->promisc)
3122 rtl8180_restart(dev);
3124 priv->promisc = promisc;
3127 int r8180_set_mac_adr(struct net_device *dev, void *mac)
3129 struct r8180_priv *priv = ieee80211_priv(dev);
3130 struct sockaddr *addr = mac;
3132 down(&priv->wx_sem);
3134 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
3136 if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
3137 memcpy(priv->ieee80211->current_network.bssid, dev->dev_addr, ETH_ALEN);
3149 /* based on ipw2200 driver */
3150 int rtl8180_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3152 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3153 struct iwreq *wrq = (struct iwreq *) rq;
3157 case RTL_IOCTL_WPA_SUPPLICANT:
3158 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
3167 static const struct net_device_ops rtl8180_netdev_ops = {
3168 .ndo_open = rtl8180_open,
3169 .ndo_stop = rtl8180_close,
3170 .ndo_get_stats = rtl8180_stats,
3171 .ndo_tx_timeout = rtl8180_restart,
3172 .ndo_do_ioctl = rtl8180_ioctl,
3173 .ndo_set_rx_mode = r8180_set_multicast,
3174 .ndo_set_mac_address = r8180_set_mac_adr,
3175 .ndo_validate_addr = eth_validate_addr,
3176 .ndo_change_mtu = eth_change_mtu,
3177 .ndo_start_xmit = ieee80211_rtl_xmit,
3180 static int rtl8180_pci_probe(struct pci_dev *pdev,
3181 const struct pci_device_id *id)
3183 unsigned long ioaddr = 0;
3184 struct net_device *dev = NULL;
3185 struct r8180_priv *priv = NULL;
3189 unsigned long pmem_start, pmem_len, pmem_flags;
3191 DMESG("Configuring chip resources");
3193 if (pci_enable_device(pdev)) {
3194 DMESG("Failed to enable PCI device");
3198 pci_set_master(pdev);
3199 pci_set_dma_mask(pdev, 0xffffff00ULL);
3200 pci_set_consistent_dma_mask(pdev, 0xffffff00ULL);
3201 dev = alloc_ieee80211(sizeof(struct r8180_priv));
3206 priv = ieee80211_priv(dev);
3207 priv->ieee80211 = netdev_priv(dev);
3209 pci_set_drvdata(pdev, dev);
3210 SET_NETDEV_DEV(dev, &pdev->dev);
3212 priv = ieee80211_priv(dev);
3215 pmem_start = pci_resource_start(pdev, 1);
3216 pmem_len = pci_resource_len(pdev, 1);
3217 pmem_flags = pci_resource_flags(pdev, 1);
3219 if (!(pmem_flags & IORESOURCE_MEM)) {
3220 DMESG("region #1 not a MMIO resource, aborting");
3224 if (!request_mem_region(pmem_start, pmem_len, RTL8180_MODULE_NAME)) {
3225 DMESG("request_mem_region failed!");
3229 ioaddr = (unsigned long)ioremap_nocache(pmem_start, pmem_len);
3230 if (ioaddr == (unsigned long)NULL) {
3231 DMESG("ioremap failed!");
3235 dev->mem_start = ioaddr; /* shared mem start */
3236 dev->mem_end = ioaddr + pci_resource_len(pdev, 0); /* shared mem end */
3238 pci_read_config_byte(pdev, 0x05, &unit);
3239 pci_write_config_byte(pdev, 0x05, unit & (~0x04));
3241 dev->irq = pdev->irq;
3244 dev->netdev_ops = &rtl8180_netdev_ops;
3245 dev->wireless_handlers = &r8180_wx_handlers_def;
3247 dev->type = ARPHRD_ETHER;
3248 dev->watchdog_timeo = HZ*3;
3250 if (dev_alloc_name(dev, ifname) < 0) {
3251 DMESG("Oops: devname already taken! Trying wlan%%d...\n");
3252 strcpy(ifname, "wlan%d");
3253 dev_alloc_name(dev, ifname);
3256 if (rtl8180_init(dev) != 0) {
3257 DMESG("Initialization failed");
3261 netif_carrier_off(dev);
3263 if (register_netdev(dev))
3266 rtl8180_proc_init_one(dev);
3268 DMESG("Driver probe completed\n");
3271 if (dev->mem_start != (unsigned long)NULL) {
3272 iounmap((void *)dev->mem_start);
3273 release_mem_region(pci_resource_start(pdev, 1),
3274 pci_resource_len(pdev, 1));
3279 free_irq(dev->irq, dev);
3282 free_ieee80211(dev);
3286 pci_disable_device(pdev);
3288 DMESG("wlan driver load failed\n");
3289 pci_set_drvdata(pdev, NULL);
3293 static void rtl8180_pci_remove(struct pci_dev *pdev)
3295 struct r8180_priv *priv;
3296 struct net_device *dev = pci_get_drvdata(pdev);
3299 unregister_netdev(dev);
3301 priv = ieee80211_priv(dev);
3303 rtl8180_proc_remove_one(dev);
3305 priv->rf_close(dev);
3310 DMESG("Freeing irq %d", dev->irq);
3311 free_irq(dev->irq, dev);
3315 free_rx_desc_ring(dev);
3316 free_tx_desc_rings(dev);
3318 if (dev->mem_start != (unsigned long)NULL) {
3319 iounmap((void *)dev->mem_start);
3320 release_mem_region(pci_resource_start(pdev, 1),
3321 pci_resource_len(pdev, 1));
3324 free_ieee80211(dev);
3326 pci_disable_device(pdev);
3328 DMESG("wlan driver removed\n");
3331 /* fun with the built-in ieee80211 stack... */
3332 extern int ieee80211_crypto_init(void);
3333 extern void ieee80211_crypto_deinit(void);
3334 extern int ieee80211_crypto_tkip_init(void);
3335 extern void ieee80211_crypto_tkip_exit(void);
3336 extern int ieee80211_crypto_ccmp_init(void);
3337 extern void ieee80211_crypto_ccmp_exit(void);
3338 extern int ieee80211_crypto_wep_init(void);
3339 extern void ieee80211_crypto_wep_exit(void);
3341 static int __init rtl8180_pci_module_init(void)
3345 ret = ieee80211_crypto_init();
3347 pr_err("ieee80211_crypto_init() failed %d\n", ret);
3350 ret = ieee80211_crypto_tkip_init();
3352 pr_err("ieee80211_crypto_tkip_init() failed %d\n", ret);
3355 ret = ieee80211_crypto_ccmp_init();
3357 pr_err("ieee80211_crypto_ccmp_init() failed %d\n", ret);
3360 ret = ieee80211_crypto_wep_init();
3362 pr_err("ieee80211_crypto_wep_init() failed %d\n", ret);
3366 pr_info("\nLinux kernel driver for RTL8180 / RTL8185 based WLAN cards\n");
3367 pr_info("Copyright (c) 2004-2005, Andrea Merello\n");
3368 DMESG("Initializing module");
3369 DMESG("Wireless extensions version %d", WIRELESS_EXT);
3370 rtl8180_proc_module_init();
3372 if (pci_register_driver(&rtl8180_pci_driver)) {
3373 DMESG("No device found");
3379 static void __exit rtl8180_pci_module_exit(void)
3381 pci_unregister_driver(&rtl8180_pci_driver);
3382 rtl8180_proc_module_remove();
3383 ieee80211_crypto_tkip_exit();
3384 ieee80211_crypto_ccmp_exit();
3385 ieee80211_crypto_wep_exit();
3386 ieee80211_crypto_deinit();
3390 void rtl8180_try_wake_queue(struct net_device *dev, int pri)
3392 unsigned long flags;
3394 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3396 spin_lock_irqsave(&priv->tx_lock, flags);
3397 enough_desc = check_nic_enought_desc(dev, pri);
3398 spin_unlock_irqrestore(&priv->tx_lock, flags);
3401 ieee80211_rtl_wake_queue(priv->ieee80211);
3404 void rtl8180_tx_isr(struct net_device *dev, int pri, short error)
3406 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3407 u32 *tail; /* tail virtual addr */
3408 u32 *head; /* head virtual addr */
3409 u32 *begin; /* start of ring virtual addr */
3410 u32 *nicv; /* nic pointer virtual addr */
3411 u32 nic; /* nic pointer physical addr */
3412 u32 nicbegin; /* start of ring physical addr */
3414 /* physical addr are ok on 32 bits since we set DMA mask */
3419 priv->stats.txretry++; /* tony 20060601 */
3420 spin_lock_irqsave(&priv->tx_lock, flag);
3422 case MANAGE_PRIORITY:
3423 tail = priv->txmapringtail;
3424 begin = priv->txmapring;
3425 head = priv->txmapringhead;
3426 nic = read_nic_dword(dev, TX_MANAGEPRIORITY_RING_ADDR);
3427 nicbegin = priv->txmapringdma;
3430 tail = priv->txbkpringtail;
3431 begin = priv->txbkpring;
3432 head = priv->txbkpringhead;
3433 nic = read_nic_dword(dev, TX_BKPRIORITY_RING_ADDR);
3434 nicbegin = priv->txbkpringdma;
3437 tail = priv->txbepringtail;
3438 begin = priv->txbepring;
3439 head = priv->txbepringhead;
3440 nic = read_nic_dword(dev, TX_BEPRIORITY_RING_ADDR);
3441 nicbegin = priv->txbepringdma;
3444 tail = priv->txvipringtail;
3445 begin = priv->txvipring;
3446 head = priv->txvipringhead;
3447 nic = read_nic_dword(dev, TX_VIPRIORITY_RING_ADDR);
3448 nicbegin = priv->txvipringdma;
3451 tail = priv->txvopringtail;
3452 begin = priv->txvopring;
3453 head = priv->txvopringhead;
3454 nic = read_nic_dword(dev, TX_VOPRIORITY_RING_ADDR);
3455 nicbegin = priv->txvopringdma;
3458 tail = priv->txhpringtail;
3459 begin = priv->txhpring;
3460 head = priv->txhpringhead;
3461 nic = read_nic_dword(dev, TX_HIGHPRIORITY_RING_ADDR);
3462 nicbegin = priv->txhpringdma;
3466 spin_unlock_irqrestore(&priv->tx_lock, flag);
3470 nicv = (u32 *)((nic - nicbegin) + (u8 *)begin);
3471 if ((head <= tail && (nicv > tail || nicv < head)) ||
3472 (head > tail && (nicv > tail && nicv < head))) {
3473 DMESGW("nic has lost pointer");
3474 spin_unlock_irqrestore(&priv->tx_lock, flag);
3475 rtl8180_restart(dev);
3480 * We check all the descriptors between the head and the nic,
3481 * but not the currently pointed by the nic (the next to be txed)
3482 * and the previous of the pointed (might be in process ??)
3484 offs = (nic - nicbegin);
3485 offs = offs / 8 / 4;
3486 hd = (head - begin) / 8;
3491 j = offs + (priv->txringcount-1-hd);
3497 for (i = 0; i < j; i++) {
3498 if ((*head) & (1<<31))
3500 if (((*head)&(0x10000000)) != 0) {
3501 priv->CurrRetryCnt += (u16)((*head) & (0x000000ff));
3503 priv->NumTxOkTotal++;
3507 priv->NumTxOkBytesTotal += (*(head+3)) & (0x00000fff);
3509 *head = *head & ~(1<<31);
3511 if ((head - begin)/8 == priv->txringcount-1)
3518 * The head has been moved to the last certainly TXed
3519 * (or at least processed by the nic) packet.
3520 * The driver take forcefully owning of all these packets
3521 * If the packet previous of the nic pointer has been
3522 * processed this doesn't matter: it will be checked
3523 * here at the next round. Anyway if no more packet are
3524 * TXed no memory leak occur at all.
3528 case MANAGE_PRIORITY:
3529 priv->txmapringhead = head;
3531 if (priv->ack_tx_to_ieee) {
3532 if (rtl8180_is_tx_queue_empty(dev)) {
3533 priv->ack_tx_to_ieee = 0;
3534 ieee80211_ps_tx_ack(priv->ieee80211, !error);
3539 priv->txbkpringhead = head;
3542 priv->txbepringhead = head;
3545 priv->txvipringhead = head;
3548 priv->txvopringhead = head;
3551 priv->txhpringhead = head;
3555 spin_unlock_irqrestore(&priv->tx_lock, flag);
3558 irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs)
3560 struct net_device *dev = (struct net_device *) netdev;
3561 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3562 unsigned long flags;
3565 /* We should return IRQ_NONE, but for now let me keep this */
3566 if (priv->irq_enabled == 0)
3569 spin_lock_irqsave(&priv->irq_th_lock, flags);
3572 inta = read_nic_dword(dev, ISR); /* & priv->IntrMask; */
3573 write_nic_dword(dev, ISR, inta); /* reset int situation */
3575 priv->stats.shints++;
3578 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3581 * most probably we can safely return IRQ_NONE,
3582 * but for now is better to avoid problems
3586 if (inta == 0xffff) {
3587 /* HW disappeared */
3588 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3594 if (!netif_running(dev)) {
3595 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3599 if (inta & ISR_TimeOut)
3600 write_nic_dword(dev, TimerInt, 0);
3602 if (inta & ISR_TBDOK)
3603 priv->stats.txbeacon++;
3605 if (inta & ISR_TBDER)
3606 priv->stats.txbeaconerr++;
3608 if (inta & IMR_TMGDOK)
3609 rtl8180_tx_isr(dev, MANAGE_PRIORITY, 0);
3611 if (inta & ISR_THPDER) {
3612 priv->stats.txhperr++;
3613 rtl8180_tx_isr(dev, HI_PRIORITY, 1);
3614 priv->ieee80211->stats.tx_errors++;
3617 if (inta & ISR_THPDOK) { /* High priority tx ok */
3618 priv->link_detect.NumTxOkInPeriod++; /* YJ,add,080828 */
3619 priv->stats.txhpokint++;
3620 rtl8180_tx_isr(dev, HI_PRIORITY, 0);
3624 priv->stats.rxerr++;
3626 if (inta & ISR_TBKDER) { /* corresponding to BK_PRIORITY */
3627 priv->stats.txbkperr++;
3628 priv->ieee80211->stats.tx_errors++;
3629 rtl8180_tx_isr(dev, BK_PRIORITY, 1);
3630 rtl8180_try_wake_queue(dev, BK_PRIORITY);
3633 if (inta & ISR_TBEDER) { /* corresponding to BE_PRIORITY */
3634 priv->stats.txbeperr++;
3635 priv->ieee80211->stats.tx_errors++;
3636 rtl8180_tx_isr(dev, BE_PRIORITY, 1);
3637 rtl8180_try_wake_queue(dev, BE_PRIORITY);
3639 if (inta & ISR_TNPDER) { /* corresponding to VO_PRIORITY */
3640 priv->stats.txnperr++;
3641 priv->ieee80211->stats.tx_errors++;
3642 rtl8180_tx_isr(dev, NORM_PRIORITY, 1);
3643 rtl8180_try_wake_queue(dev, NORM_PRIORITY);
3646 if (inta & ISR_TLPDER) { /* corresponding to VI_PRIORITY */
3647 priv->stats.txlperr++;
3648 priv->ieee80211->stats.tx_errors++;
3649 rtl8180_tx_isr(dev, LOW_PRIORITY, 1);
3650 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
3653 if (inta & ISR_ROK) {
3654 priv->stats.rxint++;
3655 tasklet_schedule(&priv->irq_rx_tasklet);
3658 if (inta & ISR_RQoSOK) {
3659 priv->stats.rxint++;
3660 tasklet_schedule(&priv->irq_rx_tasklet);
3663 if (inta & ISR_BcnInt)
3664 rtl8180_prepare_beacon(dev);
3666 if (inta & ISR_RDU) {
3667 DMESGW("No RX descriptor available");
3668 priv->stats.rxrdu++;
3669 tasklet_schedule(&priv->irq_rx_tasklet);
3672 if (inta & ISR_RXFOVW) {
3673 priv->stats.rxoverflow++;
3674 tasklet_schedule(&priv->irq_rx_tasklet);
3677 if (inta & ISR_TXFOVW)
3678 priv->stats.txoverflow++;
3680 if (inta & ISR_TNPDOK) { /* Normal priority tx ok */
3681 priv->link_detect.NumTxOkInPeriod++; /* YJ,add,080828 */
3682 priv->stats.txnpokint++;
3683 rtl8180_tx_isr(dev, NORM_PRIORITY, 0);
3684 rtl8180_try_wake_queue(dev, NORM_PRIORITY);
3687 if (inta & ISR_TLPDOK) { /* Low priority tx ok */
3688 priv->link_detect.NumTxOkInPeriod++; /* YJ,add,080828 */
3689 priv->stats.txlpokint++;
3690 rtl8180_tx_isr(dev, LOW_PRIORITY, 0);
3691 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
3694 if (inta & ISR_TBKDOK) { /* corresponding to BK_PRIORITY */
3695 priv->stats.txbkpokint++;
3696 priv->link_detect.NumTxOkInPeriod++; /* YJ,add,080828 */
3697 rtl8180_tx_isr(dev, BK_PRIORITY, 0);
3698 rtl8180_try_wake_queue(dev, BE_PRIORITY);
3701 if (inta & ISR_TBEDOK) { /* corresponding to BE_PRIORITY */
3702 priv->stats.txbeperr++;
3703 priv->link_detect.NumTxOkInPeriod++; /* YJ,add,080828 */
3704 rtl8180_tx_isr(dev, BE_PRIORITY, 0);
3705 rtl8180_try_wake_queue(dev, BE_PRIORITY);
3707 force_pci_posting(dev);
3708 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3713 void rtl8180_irq_rx_tasklet(struct r8180_priv *priv)
3715 rtl8180_rx(priv->dev);
3718 void GPIOChangeRFWorkItemCallBack(struct work_struct *work)
3720 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, GPIOChangeRFWorkItem.work);
3721 struct net_device *dev = ieee->dev;
3722 struct r8180_priv *priv = ieee80211_priv(dev);
3725 RT_RF_POWER_STATE eRfPowerStateToSet;
3726 bool bActuallySet = false;
3729 static char *RadioPowerPath = "/etc/acpi/events/RadioPower.sh";
3730 static char *envp[] = {"HOME=/", "TERM=linux", "PATH=/usr/bin:/bin", NULL};
3731 static int readf_count;
3733 readf_count = (readf_count+1)%0xffff;
3734 /* We should turn off LED before polling FF51[4]. */
3737 btPSR = read_nic_byte(dev, PSR);
3738 write_nic_byte(dev, PSR, (btPSR & ~BIT3));
3740 /* It need to delay 4us suggested by Jong, 2008-01-16 */
3743 /* HW radio On/Off according to the value of FF51[4](config0) */
3744 btConfig0 = btPSR = read_nic_byte(dev, CONFIG0);
3746 eRfPowerStateToSet = (btConfig0 & BIT4) ? eRfOn : eRfOff;
3748 /* Turn LED back on when radio enabled */
3749 if (eRfPowerStateToSet == eRfOn)
3750 write_nic_byte(dev, PSR, btPSR | BIT3);
3752 if ((priv->ieee80211->bHwRadioOff == true) &&
3753 (eRfPowerStateToSet == eRfOn)) {
3754 priv->ieee80211->bHwRadioOff = false;
3755 bActuallySet = true;
3756 } else if ((priv->ieee80211->bHwRadioOff == false) &&
3757 (eRfPowerStateToSet == eRfOff)) {
3758 priv->ieee80211->bHwRadioOff = true;
3759 bActuallySet = true;
3763 MgntActSet_RF_State(dev, eRfPowerStateToSet, RF_CHANGE_BY_HW);
3765 /* To update the UI status for Power status changed */
3766 if (priv->ieee80211->bHwRadioOff == true)
3770 argv[0] = RadioPowerPath;
3773 call_usermodehelper(RadioPowerPath, argv, envp, UMH_WAIT_PROC);
3777 module_init(rtl8180_pci_module_init);
3778 module_exit(rtl8180_pci_module_exit);