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),
941 if (-1 == buffer_add(&(priv->rxbuffer), buf, dma_tmp,
942 &(priv->rxbufferhead))) {
943 DMESGE("Unable to allocate mem RX buf");
946 *tmp = 0; /* zero pads the header of the descriptor */
947 *tmp = *tmp | (bufsize&0xfff);
948 *(tmp+2) = (u32)dma_tmp;
949 *tmp = *tmp | (1<<31); /* descriptor void, owned by the NIC */
951 tmp = tmp+rx_desc_size;
954 *(tmp-rx_desc_size) = *(tmp-rx_desc_size) | (1<<30); /* this is the last descriptor */
960 void set_nic_rxring(struct net_device *dev)
963 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
965 pgreg = read_nic_byte(dev, PGSELECT);
966 write_nic_byte(dev, PGSELECT, pgreg & ~(1<<PGSELECT_PG_SHIFT));
968 write_nic_dword(dev, RXRING_ADDR, priv->rxringdma);
971 void rtl8180_reset(struct net_device *dev)
975 rtl8180_irq_disable(dev);
977 cr = read_nic_byte(dev, CMD);
979 cr = cr | (1<<CMD_RST_SHIFT);
980 write_nic_byte(dev, CMD, cr);
982 force_pci_posting(dev);
986 if (read_nic_byte(dev, CMD) & (1<<CMD_RST_SHIFT))
987 DMESGW("Card reset timeout!");
989 DMESG("Card successfully reset");
991 rtl8180_set_mode(dev, EPROM_CMD_LOAD);
992 force_pci_posting(dev);
996 inline u16 ieeerate2rtlrate(int rate)
1028 static u16 rtl_rate[] = {10, 20, 55, 110, 60, 90, 120, 180, 240, 360, 480, 540, 720};
1030 inline u16 rtl8180_rate2rate(short rate)
1034 return rtl_rate[rate];
1037 inline u8 rtl8180_IsWirelessBMode(u16 rate)
1039 if (((rate <= 110) && (rate != 60) && (rate != 90)) || (rate == 220))
1045 u16 N_DBPSOfRate(u16 DataRate);
1047 u16 ComputeTxTime(u16 FrameLength, u16 DataRate, u8 bManagementFrame,
1054 if (rtl8180_IsWirelessBMode(DataRate)) {
1055 if (bManagementFrame || !bShortPreamble || DataRate == 10)
1057 FrameTime = (u16)(144+48+(FrameLength*8/(DataRate/10)));
1059 /* short preamble */
1060 FrameTime = (u16)(72+24+(FrameLength*8/(DataRate/10)));
1062 if ((FrameLength*8 % (DataRate/10)) != 0) /* get the ceilling */
1064 } else { /* 802.11g DSSS-OFDM PLCP length field calculation. */
1065 N_DBPS = N_DBPSOfRate(DataRate);
1066 Ceiling = (16 + 8*FrameLength + 6) / N_DBPS
1067 + (((16 + 8*FrameLength + 6) % N_DBPS) ? 1 : 0);
1068 FrameTime = (u16)(16 + 4 + 4*Ceiling + 6);
1073 u16 N_DBPSOfRate(u16 DataRate)
1110 * For Netgear case, they want good-looking signal strength.
1112 long NetgearSignalStrengthTranslate(long LastSS, long CurrSS)
1116 /* Step 1. Scale mapping. */
1117 if (CurrSS >= 71 && CurrSS <= 100)
1118 RetSS = 90 + ((CurrSS - 70) / 3);
1119 else if (CurrSS >= 41 && CurrSS <= 70)
1120 RetSS = 78 + ((CurrSS - 40) / 3);
1121 else if (CurrSS >= 31 && CurrSS <= 40)
1122 RetSS = 66 + (CurrSS - 30);
1123 else if (CurrSS >= 21 && CurrSS <= 30)
1124 RetSS = 54 + (CurrSS - 20);
1125 else if (CurrSS >= 5 && CurrSS <= 20)
1126 RetSS = 42 + (((CurrSS - 5) * 2) / 3);
1127 else if (CurrSS == 4)
1129 else if (CurrSS == 3)
1131 else if (CurrSS == 2)
1133 else if (CurrSS == 1)
1138 /* Step 2. Smoothing. */
1140 RetSS = ((LastSS * 5) + (RetSS) + 5) / 6;
1146 * Translate 0-100 signal strength index into dBm.
1148 long TranslateToDbm8185(u8 SignalStrengthIndex)
1152 /* Translate to dBm (x=0.5y-95). */
1153 SignalPower = (long)((SignalStrengthIndex + 1) >> 1);
1160 * Perform signal smoothing for dynamic mechanism.
1161 * This is different with PerformSignalSmoothing8185 in smoothing formula.
1162 * No dramatic adjustion is apply because dynamic mechanism need some degree
1163 * of correctness. Ported from 8187B.
1165 void PerformUndecoratedSignalSmoothing8185(struct r8180_priv *priv,
1168 /* Determin the current packet is CCK rate. */
1169 priv->bCurCCKPkt = bCckRate;
1171 if (priv->UndecoratedSmoothedSS >= 0)
1172 priv->UndecoratedSmoothedSS = ((priv->UndecoratedSmoothedSS * 5) +
1173 (priv->SignalStrength * 10)) / 6;
1175 priv->UndecoratedSmoothedSS = priv->SignalStrength * 10;
1177 priv->UndercorateSmoothedRxPower = ((priv->UndercorateSmoothedRxPower * 50) +
1178 (priv->RxPower * 11)) / 60;
1181 priv->CurCCKRSSI = priv->RSSI;
1183 priv->CurCCKRSSI = 0;
1188 * This is rough RX isr handling routine
1190 void rtl8180_rx(struct net_device *dev)
1192 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1193 struct sk_buff *tmp_skb;
1197 unsigned char quality, signal;
1206 u8 LNA_gain[4] = {02, 17, 29, 39};
1208 struct ieee80211_hdr_4addr *hdr;
1210 u8 bHwError = 0, bCRC = 0, bICV = 0;
1211 bool bCckRate = false;
1213 long SignalStrengthIndex = 0;
1214 struct ieee80211_rx_stats stats = {
1218 .freq = IEEE80211_24GHZ_BAND,
1221 stats.nic_type = NIC_8185B;
1224 if ((*(priv->rxringtail)) & (1<<31)) {
1225 /* we have got an RX int, but the descriptor
1226 * we are pointing is empty */
1228 priv->stats.rxnodata++;
1229 priv->ieee80211->stats.rx_errors++;
1232 tmp = priv->rxringtail;
1234 if (tmp == priv->rxring)
1235 tmp = priv->rxring + (priv->rxringcount - 1)*rx_desc_size;
1237 tmp -= rx_desc_size;
1239 if (!(*tmp & (1<<31)))
1241 } while (tmp != priv->rxring);
1244 priv->rxringtail = tmp2;
1247 /* while there are filled descriptors */
1248 while (!(*(priv->rxringtail) & (1<<31))) {
1249 if (*(priv->rxringtail) & (1<<26))
1250 DMESGW("RX buffer overflow");
1251 if (*(priv->rxringtail) & (1<<12))
1252 priv->stats.rxicverr++;
1254 if (*(priv->rxringtail) & (1<<27)) {
1255 priv->stats.rxdmafail++;
1256 /* DMESG("EE: RX DMA FAILED at buffer pointed by descriptor %x",(u32)priv->rxringtail); */
1260 pci_dma_sync_single_for_cpu(priv->pdev,
1261 priv->rxbuffer->dma,
1262 priv->rxbuffersize * sizeof(u8),
1263 PCI_DMA_FROMDEVICE);
1265 first = *(priv->rxringtail) & (1<<29) ? 1 : 0;
1267 priv->rx_prevlen = 0;
1269 last = *(priv->rxringtail) & (1<<28) ? 1 : 0;
1271 lastlen = ((*priv->rxringtail) & 0xfff);
1273 /* if the last descriptor (that should
1274 * tell us the total packet len) tell
1275 * us something less than the descriptors
1276 * len we had until now, then there is some
1278 * workaround to prevent kernel panic
1280 if (lastlen < priv->rx_prevlen)
1283 len = lastlen-priv->rx_prevlen;
1285 if (*(priv->rxringtail) & (1<<13)) {
1286 if ((*(priv->rxringtail) & 0xfff) < 500)
1287 priv->stats.rxcrcerrmin++;
1288 else if ((*(priv->rxringtail) & 0x0fff) > 1000)
1289 priv->stats.rxcrcerrmax++;
1291 priv->stats.rxcrcerrmid++;
1296 len = priv->rxbuffersize;
1299 if (first && last) {
1300 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
1302 padding = ((*(priv->rxringtail+3))&(0x04000000))>>26;
1309 priv->rx_prevlen += len;
1311 if (priv->rx_prevlen > MAX_FRAG_THRESHOLD + 100) {
1312 /* HW is probably passing several buggy frames
1313 * without FD or LD flag set.
1314 * Throw this garbage away to prevent skb
1317 if (!priv->rx_skb_complete)
1318 dev_kfree_skb_any(priv->rx_skb);
1319 priv->rx_skb_complete = 1;
1322 signal = (unsigned char)(((*(priv->rxringtail+3)) & (0x00ff0000))>>16);
1323 signal = (signal & 0xfe) >> 1;
1325 quality = (unsigned char)((*(priv->rxringtail+3)) & (0xff));
1327 stats.mac_time[0] = *(priv->rxringtail+1);
1328 stats.mac_time[1] = *(priv->rxringtail+2);
1329 rxpower = ((char)(((*(priv->rxringtail+4)) & (0x00ff0000))>>16))/2 - 42;
1330 RSSI = ((u8)(((*(priv->rxringtail+3)) & (0x0000ff00))>>8)) & (0x7f);
1332 rate = ((*(priv->rxringtail)) &
1333 ((1<<23)|(1<<22)|(1<<21)|(1<<20)))>>20;
1335 stats.rate = rtl8180_rate2rate(rate);
1336 Antenna = (((*(priv->rxringtail+3)) & (0x00008000)) == 0) ? 0 : 1;
1337 if (!rtl8180_IsWirelessBMode(stats.rate)) { /* OFDM rate. */
1338 RxAGC_dBm = rxpower+1; /* bias */
1339 } else { /* CCK rate. */
1340 RxAGC_dBm = signal; /* bit 0 discard */
1342 LNA = (u8) (RxAGC_dBm & 0x60) >> 5; /* bit 6~ bit 5 */
1343 BB = (u8) (RxAGC_dBm & 0x1F); /* bit 4 ~ bit 0 */
1345 RxAGC_dBm = -(LNA_gain[LNA] + (BB*2)); /* Pin_11b=-(LNA_gain+BB_gain) (dBm) */
1347 RxAGC_dBm += 4; /* bias */
1350 if (RxAGC_dBm & 0x80) /* absolute value */
1351 RXAGC = ~(RxAGC_dBm)+1;
1352 bCckRate = rtl8180_IsWirelessBMode(stats.rate);
1353 /* Translate RXAGC into 1-100. */
1354 if (!rtl8180_IsWirelessBMode(stats.rate)) { /* OFDM rate. */
1357 else if (RXAGC < 25)
1359 RXAGC = (90-RXAGC)*100/65;
1360 } else { /* CCK rate. */
1363 else if (RXAGC < 30)
1365 RXAGC = (95-RXAGC)*100/65;
1367 priv->SignalStrength = (u8)RXAGC;
1368 priv->RecvSignalPower = RxAGC_dBm;
1369 priv->RxPower = rxpower;
1371 /* SQ translation formula is provided by SD3 DZ. 2006.06.27 */
1373 quality = 1; /*0; */ /* 0 will cause epc to show signal zero , walk around now; */
1374 else if (quality < 27)
1377 quality = 127 - quality;
1378 priv->SignalQuality = quality;
1380 stats.signal = (u8)quality; /*priv->wstats.qual.level = priv->SignalStrength; */
1381 stats.signalstrength = RXAGC;
1382 if (stats.signalstrength > 100)
1383 stats.signalstrength = 100;
1384 stats.signalstrength = (stats.signalstrength * 70)/100 + 30;
1385 /* printk("==========================>rx : RXAGC is %d,signalstrength is %d\n",RXAGC,stats.signalstrength); */
1386 stats.rssi = priv->wstats.qual.qual = priv->SignalQuality;
1387 stats.noise = priv->wstats.qual.noise = 100 - priv->wstats.qual.qual;
1388 bHwError = (((*(priv->rxringtail)) & (0x00000fff)) == 4080) |
1389 (((*(priv->rxringtail)) & (0x04000000)) != 0) |
1390 (((*(priv->rxringtail)) & (0x08000000)) != 0) |
1391 (((~(*(priv->rxringtail))) & (0x10000000)) != 0) |
1392 (((~(*(priv->rxringtail))) & (0x20000000)) != 0);
1393 bCRC = ((*(priv->rxringtail)) & (0x00002000)) >> 13;
1394 bICV = ((*(priv->rxringtail)) & (0x00001000)) >> 12;
1395 hdr = (struct ieee80211_hdr_4addr *)priv->rxbuffer->buf;
1396 fc = le16_to_cpu(hdr->frame_ctl);
1397 type = WLAN_FC_GET_TYPE(fc);
1399 if (IEEE80211_FTYPE_CTL != type &&
1400 !bHwError && !bCRC && !bICV &&
1401 eqMacAddr(priv->ieee80211->current_network.bssid,
1402 fc & IEEE80211_FCTL_TODS ? hdr->addr1 :
1403 fc & IEEE80211_FCTL_FROMDS ? hdr->addr2 :
1406 /* Perform signal smoothing for dynamic
1407 * mechanism on demand. This is different
1408 * with PerformSignalSmoothing8185 in smoothing
1409 * fomula. No dramatic adjustion is apply
1410 * because dynamic mechanism need some degree
1411 * of correctness. */
1412 PerformUndecoratedSignalSmoothing8185(priv, bCckRate);
1414 /* For good-looking singal strength. */
1415 SignalStrengthIndex = NetgearSignalStrengthTranslate(
1416 priv->LastSignalStrengthInPercent,
1417 priv->SignalStrength);
1419 priv->LastSignalStrengthInPercent = SignalStrengthIndex;
1420 priv->Stats_SignalStrength = TranslateToDbm8185((u8)SignalStrengthIndex);
1422 * We need more correct power of received packets and the "SignalStrength" of RxStats is beautified,
1423 * so we record the correct power here.
1425 priv->Stats_SignalQuality = (long)(priv->Stats_SignalQuality * 5 + (long)priv->SignalQuality + 5) / 6;
1426 priv->Stats_RecvSignalPower = (long)(priv->Stats_RecvSignalPower * 5 + priv->RecvSignalPower - 1) / 6;
1428 /* Figure out which antenna that received the last packet. */
1429 priv->LastRxPktAntenna = Antenna ? 1 : 0; /* 0: aux, 1: main. */
1430 SwAntennaDiversityRxOk8185(dev, priv->SignalStrength);
1434 if (!priv->rx_skb_complete) {
1435 /* seems that HW sometimes fails to receive and
1436 doesn't provide the last descriptor */
1437 dev_kfree_skb_any(priv->rx_skb);
1438 priv->stats.rxnolast++;
1440 priv->rx_skb = dev_alloc_skb(len+2);
1444 priv->rx_skb_complete = 0;
1445 priv->rx_skb->dev = dev;
1447 /* if we are here we should have already RXed
1449 * If we get here and the skb is not allocated then
1450 * we have just throw out garbage (skb not allocated)
1451 * and we are still rxing garbage....
1453 if (!priv->rx_skb_complete) {
1455 tmp_skb = dev_alloc_skb(priv->rx_skb->len+len+2);
1462 memcpy(skb_put(tmp_skb, priv->rx_skb->len),
1466 dev_kfree_skb_any(priv->rx_skb);
1468 priv->rx_skb = tmp_skb;
1472 if (!priv->rx_skb_complete) {
1474 memcpy(skb_put(priv->rx_skb, len),
1475 (((unsigned char *)priv->rxbuffer->buf) + 2), len);
1477 memcpy(skb_put(priv->rx_skb, len),
1478 priv->rxbuffer->buf, len);
1482 if (last && !priv->rx_skb_complete) {
1483 if (priv->rx_skb->len > 4)
1484 skb_trim(priv->rx_skb, priv->rx_skb->len-4);
1485 if (!ieee80211_rtl_rx(priv->ieee80211,
1486 priv->rx_skb, &stats))
1487 dev_kfree_skb_any(priv->rx_skb);
1488 priv->rx_skb_complete = 1;
1491 pci_dma_sync_single_for_device(priv->pdev,
1492 priv->rxbuffer->dma,
1493 priv->rxbuffersize * sizeof(u8),
1494 PCI_DMA_FROMDEVICE);
1496 drop: /* this is used when we have not enough mem */
1497 /* restore the descriptor */
1498 *(priv->rxringtail+2) = priv->rxbuffer->dma;
1499 *(priv->rxringtail) = *(priv->rxringtail) & ~0xfff;
1500 *(priv->rxringtail) =
1501 *(priv->rxringtail) | priv->rxbuffersize;
1503 *(priv->rxringtail) =
1504 *(priv->rxringtail) | (1<<31);
1506 priv->rxringtail += rx_desc_size;
1507 if (priv->rxringtail >=
1508 (priv->rxring)+(priv->rxringcount)*rx_desc_size)
1509 priv->rxringtail = priv->rxring;
1511 priv->rxbuffer = (priv->rxbuffer->next);
1516 void rtl8180_dma_kick(struct net_device *dev, int priority)
1518 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1520 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1521 write_nic_byte(dev, TX_DMA_POLLING,
1522 (1 << (priority + 1)) | priv->dma_poll_mask);
1523 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1525 force_pci_posting(dev);
1528 void rtl8180_data_hard_stop(struct net_device *dev)
1530 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1532 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1533 priv->dma_poll_stop_mask |= TPPOLLSTOP_AC_VIQ;
1534 write_nic_byte(dev, TPPollStop, priv->dma_poll_stop_mask);
1535 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1538 void rtl8180_data_hard_resume(struct net_device *dev)
1540 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1542 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1543 priv->dma_poll_stop_mask &= ~(TPPOLLSTOP_AC_VIQ);
1544 write_nic_byte(dev, TPPollStop, priv->dma_poll_stop_mask);
1545 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1549 * This function TX data frames when the ieee80211 stack requires this.
1550 * It checks also if we need to stop the ieee tx queue, eventually do it
1552 void rtl8180_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int
1554 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1556 struct ieee80211_hdr_3addr *h = (struct ieee80211_hdr_3addr *) skb->data;
1557 short morefrag = (h->frame_control) & IEEE80211_FCTL_MOREFRAGS;
1558 unsigned long flags;
1561 mode = priv->ieee80211->iw_mode;
1563 rate = ieeerate2rtlrate(rate);
1565 * This function doesn't require lock because we make
1566 * sure it's called with the tx_lock already acquired.
1567 * this come from the kernel's hard_xmit callback (through
1568 * the ieee stack, or from the try_wake_queue (again through
1571 priority = AC2Q(skb->priority);
1572 spin_lock_irqsave(&priv->tx_lock, flags);
1574 if (priv->ieee80211->bHwRadioOff) {
1575 spin_unlock_irqrestore(&priv->tx_lock, flags);
1580 if (!check_nic_enought_desc(dev, priority)) {
1581 DMESGW("Error: no descriptor left by previous TX (avail %d) ",
1582 get_curr_tx_free_desc(dev, priority));
1583 ieee80211_rtl_stop_queue(priv->ieee80211);
1585 rtl8180_tx(dev, skb->data, skb->len, priority, morefrag, 0, rate);
1586 if (!check_nic_enought_desc(dev, priority))
1587 ieee80211_rtl_stop_queue(priv->ieee80211);
1589 spin_unlock_irqrestore(&priv->tx_lock, flags);
1593 * This is a rough attempt to TX a frame
1594 * This is called by the ieee 80211 stack to TX management frames.
1595 * If the ring is full packets are dropped (for data frame the queue
1596 * is stopped before this can happen). For this reason it is better
1597 * if the descriptors are larger than the largest management frame
1598 * we intend to TX: i'm unsure what the HW does if it will not find
1599 * the last fragment of a frame because it has been dropped...
1600 * Since queues for Management and Data frames are different we
1601 * might use a different lock than tx_lock (for example mgmt_tx_lock)
1603 /* these function may loop if invoked with 0 descriptors or 0 len buffer */
1604 int rtl8180_hard_start_xmit(struct sk_buff *skb, struct net_device *dev)
1606 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1607 unsigned long flags;
1610 priority = MANAGE_PRIORITY;
1612 spin_lock_irqsave(&priv->tx_lock, flags);
1614 if (priv->ieee80211->bHwRadioOff) {
1615 spin_unlock_irqrestore(&priv->tx_lock, flags);
1616 dev_kfree_skb_any(skb);
1617 return NETDEV_TX_OK;
1620 rtl8180_tx(dev, skb->data, skb->len, priority,
1621 0, 0, ieeerate2rtlrate(priv->ieee80211->basic_rate));
1623 priv->ieee80211->stats.tx_bytes += skb->len;
1624 priv->ieee80211->stats.tx_packets++;
1625 spin_unlock_irqrestore(&priv->tx_lock, flags);
1627 dev_kfree_skb_any(skb);
1628 return NETDEV_TX_OK;
1631 /* longpre 144+48 shortpre 72+24 */
1632 u16 rtl8180_len2duration(u32 len, short rate, short *ext)
1641 duration = ((len+4)<<4) / 0x2;
1642 drift = ((len+4)<<4) % 0x2;
1649 duration = ((len+4)<<4) / 0x4;
1650 drift = ((len+4)<<4) % 0x4;
1655 case 2: /* 5.5mbps */
1657 duration = ((len+4)<<4) / 0xb;
1658 drift = ((len+4)<<4) % 0xb;
1664 case 3: /* 11mbps */
1666 duration = ((len+4)<<4) / 0x16;
1667 drift = ((len+4)<<4) % 0x16;
1680 void rtl8180_prepare_beacon(struct net_device *dev)
1682 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1683 struct sk_buff *skb;
1685 u16 word = read_nic_word(dev, BcnItv);
1686 word &= ~BcnItv_BcnItv; /* clear Bcn_Itv */
1687 word |= cpu_to_le16(priv->ieee80211->current_network.beacon_interval); /* 0x64; */
1688 write_nic_word(dev, BcnItv, word);
1690 skb = ieee80211_get_beacon(priv->ieee80211);
1692 rtl8180_tx(dev, skb->data, skb->len, BEACON_PRIORITY,
1693 0, 0, ieeerate2rtlrate(priv->ieee80211->basic_rate));
1694 dev_kfree_skb_any(skb);
1699 * This function do the real dirty work: it enqueues a TX command
1700 * descriptor in the ring buffer, copyes the frame in a TX buffer
1701 * and kicks the NIC to ensure it does the DMA transfer.
1703 short rtl8180_tx(struct net_device *dev, u8 *txbuf, int len, int priority,
1704 short morefrag, short descfrag, int rate)
1706 struct r8180_priv *priv = ieee80211_priv(dev);
1707 u32 *tail, *temp_tail;
1714 struct buffer *buflist;
1715 struct ieee80211_hdr_3addr *frag_hdr = (struct ieee80211_hdr_3addr *)txbuf;
1717 u8 bUseShortPreamble = 0;
1722 u16 ThisFrameTime = 0;
1723 u16 TxDescDuration = 0;
1724 u8 ownbit_flag = false;
1727 case MANAGE_PRIORITY:
1728 tail = priv->txmapringtail;
1729 begin = priv->txmapring;
1730 buflist = priv->txmapbufstail;
1731 count = priv->txringcount;
1734 tail = priv->txbkpringtail;
1735 begin = priv->txbkpring;
1736 buflist = priv->txbkpbufstail;
1737 count = priv->txringcount;
1740 tail = priv->txbepringtail;
1741 begin = priv->txbepring;
1742 buflist = priv->txbepbufstail;
1743 count = priv->txringcount;
1746 tail = priv->txvipringtail;
1747 begin = priv->txvipring;
1748 buflist = priv->txvipbufstail;
1749 count = priv->txringcount;
1752 tail = priv->txvopringtail;
1753 begin = priv->txvopring;
1754 buflist = priv->txvopbufstail;
1755 count = priv->txringcount;
1758 tail = priv->txhpringtail;
1759 begin = priv->txhpring;
1760 buflist = priv->txhpbufstail;
1761 count = priv->txringcount;
1763 case BEACON_PRIORITY:
1764 tail = priv->txbeaconringtail;
1765 begin = priv->txbeaconring;
1766 buflist = priv->txbeaconbufstail;
1767 count = priv->txbeaconcount;
1774 memcpy(&dest, frag_hdr->addr1, ETH_ALEN);
1775 if (is_multicast_ether_addr(dest)) {
1781 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate),
1782 0, bUseShortPreamble);
1783 TxDescDuration = ThisFrameTime;
1784 } else { /* Unicast packet */
1787 /* YJ,add,080828,for Keep alive */
1788 priv->NumTxUnicast++;
1790 /* Figure out ACK rate according to BSS basic rate
1792 AckTime = ComputeTxTime(14, 10, 0, 0); /* AckCTSLng = 14 use 1M bps send */
1794 if (((len + sCrcLng) > priv->rts) && priv->rts) { /* RTS/CTS. */
1795 u16 RtsTime, CtsTime;
1800 /* Rate and time required for RTS. */
1801 RtsTime = ComputeTxTime(sAckCtsLng/8, priv->ieee80211->basic_rate, 0, 0);
1802 /* Rate and time required for CTS. */
1803 CtsTime = ComputeTxTime(14, 10, 0, 0); /* AckCTSLng = 14 use 1M bps send */
1805 /* Figure out time required to transmit this frame. */
1806 ThisFrameTime = ComputeTxTime(len + sCrcLng,
1807 rtl8180_rate2rate(rate),
1811 /* RTS-CTS-ThisFrame-ACK. */
1812 RtsDur = CtsTime + ThisFrameTime + AckTime + 3*aSifsTime;
1814 TxDescDuration = RtsTime + RtsDur;
1815 } else { /* Normal case. */
1820 ThisFrameTime = ComputeTxTime(len + sCrcLng, rtl8180_rate2rate(rate),
1821 0, bUseShortPreamble);
1822 TxDescDuration = ThisFrameTime + aSifsTime + AckTime;
1825 if (!(frag_hdr->frame_control & IEEE80211_FCTL_MOREFRAGS)) {
1826 /* ThisFrame-ACK. */
1827 Duration = aSifsTime + AckTime;
1828 } else { /* One or more fragments remained. */
1830 NextFragTime = ComputeTxTime(len + sCrcLng, /* pretend following packet length equal current packet */
1831 rtl8180_rate2rate(rate),
1835 /* ThisFrag-ACk-NextFrag-ACK. */
1836 Duration = NextFragTime + 3*aSifsTime + 2*AckTime;
1839 } /* End of Unicast packet */
1841 frag_hdr->duration_id = Duration;
1843 buflen = priv->txbuffsize;
1847 while (remain != 0) {
1850 DMESGE("TX buffer error, cannot TX frames. pri %d.", priority);
1855 if ((*tail & (1 << 31)) && (priority != BEACON_PRIORITY)) {
1856 DMESGW("No more TX desc, returning %x of %x",
1858 priv->stats.txrdu++;
1862 *tail = 0; /* zeroes header */
1869 /* FIXME: this should be triggered by HW encryption parameters.*/
1870 *tail |= (1<<15); /* no encrypt */
1872 if (remain == len && !descfrag) {
1873 ownbit_flag = false;
1874 *tail = *tail | (1<<29) ; /* fist segment of the packet */
1875 *tail = *tail | (len);
1880 for (i = 0; i < buflen && remain > 0; i++, remain--) {
1881 ((u8 *)buf)[i] = txbuf[i]; /* copy data into descriptor pointed DMAble buffer */
1882 if (remain == 4 && i+4 >= buflen)
1884 /* ensure the last desc has at least 4 bytes payload */
1888 *(tail+3) = *(tail+3) & ~0xfff;
1889 *(tail+3) = *(tail+3) | i; /* buffer length */
1890 /* Use short preamble or not */
1891 if (priv->ieee80211->current_network.capability&WLAN_CAPABILITY_SHORT_PREAMBLE)
1892 if (priv->plcp_preamble_mode == 1 && rate != 0) /* short mode now, not long! */
1893 ; /* *tail |= (1<<16); */ /* enable short preamble mode. */
1898 if (bRTSEnable) { /* rts enable */
1899 *tail |= ((ieeerate2rtlrate(priv->ieee80211->basic_rate))<<19); /* RTS RATE */
1900 *tail |= (1<<23); /* rts enable */
1901 *(tail+1) |= (RtsDur&0xffff); /* RTS Duration */
1903 *(tail+3) |= ((TxDescDuration&0xffff)<<16); /* DURATION */
1904 /* *(tail+3) |= (0xe6<<16); */
1905 *(tail+5) |= (11<<8); /* (priv->retry_data<<8); */ /* retry lim; */
1907 *tail = *tail | ((rate&0xf) << 24);
1910 *tail = (*tail) | (1<<17); /* more fragment */
1912 *tail = (*tail) | (1<<28); /* last segment of frame */
1914 *(tail+5) = *(tail+5)|(2<<27);
1915 *(tail+7) = *(tail+7)|(1<<4);
1919 *tail = *tail | (1<<31); /* descriptor ready to be txed */
1921 if ((tail - begin)/8 == count-1)
1926 buflist = buflist->next;
1931 case MANAGE_PRIORITY:
1932 priv->txmapringtail = tail;
1933 priv->txmapbufstail = buflist;
1936 priv->txbkpringtail = tail;
1937 priv->txbkpbufstail = buflist;
1940 priv->txbepringtail = tail;
1941 priv->txbepbufstail = buflist;
1944 priv->txvipringtail = tail;
1945 priv->txvipbufstail = buflist;
1948 priv->txvopringtail = tail;
1949 priv->txvopbufstail = buflist;
1952 priv->txhpringtail = tail;
1953 priv->txhpbufstail = buflist;
1955 case BEACON_PRIORITY:
1957 * The HW seems to be happy with the 1st
1958 * descriptor filled and the 2nd empty...
1959 * So always update descriptor 1 and never
1965 *temp_tail = *temp_tail | (1<<31); /* descriptor ready to be txed */
1966 rtl8180_dma_kick(dev, priority);
1971 void rtl8180_irq_rx_tasklet(struct r8180_priv *priv);
1973 void rtl8180_link_change(struct net_device *dev)
1975 struct r8180_priv *priv = ieee80211_priv(dev);
1976 u16 beacon_interval;
1977 struct ieee80211_network *net = &priv->ieee80211->current_network;
1979 rtl8180_update_msr(dev);
1981 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
1983 write_nic_dword(dev, BSSID, ((u32 *)net->bssid)[0]);
1984 write_nic_word(dev, BSSID+4, ((u16 *)net->bssid)[2]);
1986 beacon_interval = read_nic_word(dev, BEACON_INTERVAL);
1987 beacon_interval &= ~BEACON_INTERVAL_MASK;
1988 beacon_interval |= net->beacon_interval;
1989 write_nic_word(dev, BEACON_INTERVAL, beacon_interval);
1991 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
1993 rtl8180_set_chan(dev, priv->chan);
1996 void rtl8180_rq_tx_ack(struct net_device *dev)
1999 struct r8180_priv *priv = ieee80211_priv(dev);
2001 write_nic_byte(dev, CONFIG4, read_nic_byte(dev, CONFIG4) | CONFIG4_PWRMGT);
2002 priv->ack_tx_to_ieee = 1;
2005 short rtl8180_is_tx_queue_empty(struct net_device *dev)
2008 struct r8180_priv *priv = ieee80211_priv(dev);
2011 for (d = priv->txmapring;
2012 d < priv->txmapring + priv->txringcount; d += 8)
2016 for (d = priv->txbkpring;
2017 d < priv->txbkpring + priv->txringcount; d += 8)
2021 for (d = priv->txbepring;
2022 d < priv->txbepring + priv->txringcount; d += 8)
2026 for (d = priv->txvipring;
2027 d < priv->txvipring + priv->txringcount; d += 8)
2031 for (d = priv->txvopring;
2032 d < priv->txvopring + priv->txringcount; d += 8)
2036 for (d = priv->txhpring;
2037 d < priv->txhpring + priv->txringcount; d += 8)
2043 void rtl8180_hw_wakeup(struct net_device *dev)
2045 unsigned long flags;
2046 struct r8180_priv *priv = ieee80211_priv(dev);
2048 spin_lock_irqsave(&priv->ps_lock, flags);
2049 write_nic_byte(dev, CONFIG4, read_nic_byte(dev, CONFIG4) & ~CONFIG4_PWRMGT);
2050 if (priv->rf_wakeup)
2051 priv->rf_wakeup(dev);
2052 spin_unlock_irqrestore(&priv->ps_lock, flags);
2055 void rtl8180_hw_sleep_down(struct net_device *dev)
2057 unsigned long flags;
2058 struct r8180_priv *priv = ieee80211_priv(dev);
2060 spin_lock_irqsave(&priv->ps_lock, flags);
2062 priv->rf_sleep(dev);
2063 spin_unlock_irqrestore(&priv->ps_lock, flags);
2066 void rtl8180_hw_sleep(struct net_device *dev, u32 th, u32 tl)
2068 struct r8180_priv *priv = ieee80211_priv(dev);
2070 unsigned long flags;
2072 spin_lock_irqsave(&priv->ps_lock, flags);
2075 * Writing HW register with 0 equals to disable
2076 * the timer, that is not really what we want
2078 tl -= MSECS(4+16+7);
2081 * If the interval in witch we are requested to sleep is too
2082 * short then give up and remain awake
2084 if (((tl >= rb) && (tl-rb) <= MSECS(MIN_SLEEP_TIME))
2085 || ((rb > tl) && (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
2086 spin_unlock_irqrestore(&priv->ps_lock, flags);
2087 printk("too short to sleep\n");
2092 u32 tmp = (tl > rb) ? (tl-rb) : (rb-tl);
2094 priv->DozePeriodInPast2Sec += jiffies_to_msecs(tmp);
2095 /* as tl may be less than rb */
2096 queue_delayed_work(priv->ieee80211->wq, &priv->ieee80211->hw_wakeup_wq, tmp);
2099 * If we suspect the TimerInt is gone beyond tl
2100 * while setting it, then give up
2103 if (((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME))) ||
2104 ((tl < rb) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))) {
2105 spin_unlock_irqrestore(&priv->ps_lock, flags);
2109 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_sleep_wq);
2110 spin_unlock_irqrestore(&priv->ps_lock, flags);
2113 void rtl8180_wmm_param_update(struct work_struct *work)
2115 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, wmm_param_update_wq);
2116 struct net_device *dev = ieee->dev;
2117 u8 *ac_param = (u8 *)(ieee->current_network.wmm_param);
2118 u8 mode = ieee->current_network.mode;
2124 if (!ieee->current_network.QoS_Enable) {
2125 /* legacy ac_xx_param update */
2126 AcParam.longData = 0;
2127 AcParam.f.AciAifsn.f.AIFSN = 2; /* Follow 802.11 DIFS. */
2128 AcParam.f.AciAifsn.f.ACM = 0;
2129 AcParam.f.Ecw.f.ECWmin = 3; /* Follow 802.11 CWmin. */
2130 AcParam.f.Ecw.f.ECWmax = 7; /* Follow 802.11 CWmax. */
2131 AcParam.f.TXOPLimit = 0;
2132 for (eACI = 0; eACI < AC_MAX; eACI++) {
2133 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
2137 pAcParam = (PAC_PARAM)(&AcParam);
2138 /* Retrieve parameters to update. */
2139 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G) ? 9 : 20) + aSifsTime;
2140 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit))<<AC_PARAM_TXOP_LIMIT_OFFSET)|
2141 (((u32)(pAcParam->f.Ecw.f.ECWmax))<<AC_PARAM_ECW_MAX_OFFSET)|
2142 (((u32)(pAcParam->f.Ecw.f.ECWmin))<<AC_PARAM_ECW_MIN_OFFSET)|
2143 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
2146 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
2149 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
2152 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
2155 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
2158 pr_warn("SetHwReg8185():invalid ACI: %d!\n",
2167 for (i = 0; i < AC_MAX; i++) {
2168 /* AcParam.longData = 0; */
2169 pAcParam = (AC_PARAM *)ac_param;
2175 /* Retrieve parameters to update. */
2176 eACI = pAcParam->f.AciAifsn.f.ACI;
2177 /* Mode G/A: slotTimeTimer = 9; Mode B: 20 */
2178 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * (((mode&IEEE_G) == IEEE_G) ? 9 : 20) + aSifsTime;
2179 u4bAcParam = ((((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
2180 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
2181 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
2182 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
2186 write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
2189 write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
2192 write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
2195 write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
2198 pr_warn("SetHwReg8185(): invalid ACI: %d !\n",
2203 ac_param += (sizeof(AC_PARAM));
2207 void rtl8180_restart_wq(struct work_struct *work);
2208 /* void rtl8180_rq_tx_ack(struct work_struct *work); */
2209 void rtl8180_watch_dog_wq(struct work_struct *work);
2210 void rtl8180_hw_wakeup_wq(struct work_struct *work);
2211 void rtl8180_hw_sleep_wq(struct work_struct *work);
2212 void rtl8180_sw_antenna_wq(struct work_struct *work);
2213 void rtl8180_watch_dog(struct net_device *dev);
2215 void watch_dog_adaptive(unsigned long data)
2217 struct r8180_priv *priv = ieee80211_priv((struct net_device *)data);
2220 DMESG("<----watch_dog_adaptive():driver is not up!\n");
2224 /* Tx High Power Mechanism. */
2225 if (CheckHighPower((struct net_device *)data))
2226 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->tx_pw_wq);
2228 /* Tx Power Tracking on 87SE. */
2229 if (CheckTxPwrTracking((struct net_device *)data))
2230 TxPwrTracking87SE((struct net_device *)data);
2232 /* Perform DIG immediately. */
2233 if (CheckDig((struct net_device *)data) == true)
2234 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->hw_dig_wq);
2235 rtl8180_watch_dog((struct net_device *)data);
2237 queue_work(priv->ieee80211->wq, (void *)&priv->ieee80211->GPIOChangeRFWorkItem);
2239 priv->watch_dog_timer.expires = jiffies + MSECS(IEEE80211_WATCH_DOG_TIME);
2240 add_timer(&priv->watch_dog_timer);
2243 static CHANNEL_LIST ChannelPlan[] = {
2244 {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64},19}, /* FCC */
2245 {{1,2,3,4,5,6,7,8,9,10,11},11}, /* IC */
2246 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, /* ETSI */
2247 {{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. */
2248 {{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. */
2249 {{14,36,40,44,48,52,56,60,64},9}, /* MKK */
2250 {{1,2,3,4,5,6,7,8,9,10,11,12,13,14, 36,40,44,48,52,56,60,64},22},/* MKK1 */
2251 {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, /* Israel. */
2252 {{1,2,3,4,5,6,7,8,9,10,11,12,13,34,38,42,46},17}, /* For 11a , TELEC */
2253 {{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 */
2254 {{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 */
2257 static void rtl8180_set_channel_map(u8 channel_plan, struct ieee80211_device *ieee)
2261 /* lzm add 080826 */
2262 ieee->MinPassiveChnlNum = MAX_CHANNEL_NUMBER+1;
2263 ieee->IbssStartChnl = 0;
2265 switch (channel_plan) {
2266 case COUNTRY_CODE_FCC:
2267 case COUNTRY_CODE_IC:
2268 case COUNTRY_CODE_ETSI:
2269 case COUNTRY_CODE_SPAIN:
2270 case COUNTRY_CODE_FRANCE:
2271 case COUNTRY_CODE_MKK:
2272 case COUNTRY_CODE_MKK1:
2273 case COUNTRY_CODE_ISRAEL:
2274 case COUNTRY_CODE_TELEC:
2277 ieee->bGlobalDomain = false;
2278 if (ChannelPlan[channel_plan].Len != 0) {
2279 /* Clear old channel map */
2280 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
2281 /* Set new channel map */
2282 for (i = 0; i < ChannelPlan[channel_plan].Len; i++) {
2283 if (ChannelPlan[channel_plan].Channel[i] <= 14)
2284 GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1;
2289 case COUNTRY_CODE_GLOBAL_DOMAIN:
2291 GET_DOT11D_INFO(ieee)->bEnabled = 0;
2293 ieee->bGlobalDomain = true;
2296 case COUNTRY_CODE_WORLD_WIDE_13_INDEX:/* lzm add 080826 */
2298 ieee->MinPassiveChnlNum = 12;
2299 ieee->IbssStartChnl = 10;
2305 ieee->bGlobalDomain = false;
2306 memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map));
2307 for (i = 1; i <= 14; i++)
2308 GET_DOT11D_INFO(ieee)->channel_map[i] = 1;
2314 void GPIOChangeRFWorkItemCallBack(struct work_struct *work);
2317 static void rtl8180_statistics_init(struct Stats *pstats)
2319 memset(pstats, 0, sizeof(struct Stats));
2322 static void rtl8180_link_detect_init(plink_detect_t plink_detect)
2324 memset(plink_detect, 0, sizeof(link_detect_t));
2325 plink_detect->SlotNum = DEFAULT_SLOT_NUM;
2328 /* YJ,add,080828,end */
2329 static void rtl8187se_eeprom_register_read(struct eeprom_93cx6 *eeprom)
2331 struct net_device *dev = eeprom->data;
2332 u8 reg = read_nic_byte(dev, EPROM_CMD);
2334 eeprom->reg_data_in = reg & RTL818X_EEPROM_CMD_WRITE;
2335 eeprom->reg_data_out = reg & RTL818X_EEPROM_CMD_READ;
2336 eeprom->reg_data_clock = reg & RTL818X_EEPROM_CMD_CK;
2337 eeprom->reg_chip_select = reg & RTL818X_EEPROM_CMD_CS;
2340 static void rtl8187se_eeprom_register_write(struct eeprom_93cx6 *eeprom)
2342 struct net_device *dev = eeprom->data;
2345 if (eeprom->reg_data_in)
2346 reg |= RTL818X_EEPROM_CMD_WRITE;
2347 if (eeprom->reg_data_out)
2348 reg |= RTL818X_EEPROM_CMD_READ;
2349 if (eeprom->reg_data_clock)
2350 reg |= RTL818X_EEPROM_CMD_CK;
2351 if (eeprom->reg_chip_select)
2352 reg |= RTL818X_EEPROM_CMD_CS;
2354 write_nic_byte(dev, EPROM_CMD, reg);
2355 read_nic_byte(dev, EPROM_CMD);
2359 short rtl8180_init(struct net_device *dev)
2361 struct r8180_priv *priv = ieee80211_priv(dev);
2366 struct eeprom_93cx6 eeprom;
2370 eeprom.register_read = rtl8187se_eeprom_register_read;
2371 eeprom.register_write = rtl8187se_eeprom_register_write;
2372 eeprom.width = PCI_EEPROM_WIDTH_93C46;
2374 eeprom_93cx6_read(&eeprom, EEPROM_COUNTRY_CODE>>1, &eeprom_val);
2375 priv->channel_plan = eeprom_val & 0xFF;
2376 if (priv->channel_plan > COUNTRY_CODE_GLOBAL_DOMAIN) {
2377 printk("rtl8180_init:Error channel plan! Set to default.\n");
2378 priv->channel_plan = 0;
2381 DMESG("Channel plan is %d\n", priv->channel_plan);
2382 rtl8180_set_channel_map(priv->channel_plan, priv->ieee80211);
2384 /* FIXME: these constants are placed in a bad pleace. */
2385 priv->txbuffsize = 2048; /* 1024; */
2386 priv->txringcount = 32; /* 32; */
2387 priv->rxbuffersize = 2048; /* 1024; */
2388 priv->rxringcount = 64; /* 32; */
2389 priv->txbeaconcount = 2;
2390 priv->rx_skb_complete = 1;
2392 priv->RFChangeInProgress = false;
2393 priv->SetRFPowerStateInProgress = false;
2394 priv->RFProgType = 0;
2396 priv->irq_enabled = 0;
2398 rtl8180_statistics_init(&priv->stats);
2399 rtl8180_link_detect_init(&priv->link_detect);
2401 priv->ack_tx_to_ieee = 0;
2402 priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
2403 priv->ieee80211->iw_mode = IW_MODE_INFRA;
2404 priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN |
2405 IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ |
2406 IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;
2407 priv->ieee80211->active_scan = 1;
2408 priv->ieee80211->rate = 110; /* 11 mbps */
2409 priv->ieee80211->modulation = IEEE80211_CCK_MODULATION;
2410 priv->ieee80211->host_encrypt = 1;
2411 priv->ieee80211->host_decrypt = 1;
2412 priv->ieee80211->sta_wake_up = rtl8180_hw_wakeup;
2413 priv->ieee80211->ps_request_tx_ack = rtl8180_rq_tx_ack;
2414 priv->ieee80211->enter_sleep_state = rtl8180_hw_sleep;
2415 priv->ieee80211->ps_is_queue_empty = rtl8180_is_tx_queue_empty;
2417 priv->hw_wep = hwwep;
2419 priv->retry_rts = DEFAULT_RETRY_RTS;
2420 priv->retry_data = DEFAULT_RETRY_DATA;
2421 priv->RFChangeInProgress = false;
2422 priv->SetRFPowerStateInProgress = false;
2423 priv->RFProgType = 0;
2424 priv->bInactivePs = true; /* false; */
2425 priv->ieee80211->bInactivePs = priv->bInactivePs;
2426 priv->bSwRfProcessing = false;
2427 priv->eRFPowerState = eRfOff;
2428 priv->RfOffReason = 0;
2429 priv->LedStrategy = SW_LED_MODE0;
2430 priv->TxPollingTimes = 0; /* lzm add 080826 */
2431 priv->bLeisurePs = true;
2432 priv->dot11PowerSaveMode = eActive;
2433 priv->AdMinCheckPeriod = 5;
2434 priv->AdMaxCheckPeriod = 10;
2435 priv->AdMaxRxSsThreshold = 30; /* 60->30 */
2436 priv->AdRxSsThreshold = 20; /* 50->20 */
2437 priv->AdCheckPeriod = priv->AdMinCheckPeriod;
2438 priv->AdTickCount = 0;
2439 priv->AdRxSignalStrength = -1;
2440 priv->RegSwAntennaDiversityMechanism = 0;
2441 priv->RegDefaultAntenna = 0;
2442 priv->SignalStrength = 0;
2443 priv->AdRxOkCnt = 0;
2444 priv->CurrAntennaIndex = 0;
2445 priv->AdRxSsBeforeSwitched = 0;
2446 init_timer(&priv->SwAntennaDiversityTimer);
2447 priv->SwAntennaDiversityTimer.data = (unsigned long)dev;
2448 priv->SwAntennaDiversityTimer.function = (void *)SwAntennaDiversityTimerCallback;
2449 priv->bDigMechanism = 1;
2450 priv->InitialGain = 6;
2451 priv->bXtalCalibration = false;
2452 priv->XtalCal_Xin = 0;
2453 priv->XtalCal_Xout = 0;
2454 priv->bTxPowerTrack = false;
2455 priv->ThermalMeter = 0;
2456 priv->FalseAlarmRegValue = 0;
2457 priv->RegDigOfdmFaUpTh = 0xc; /* Upper threshold of OFDM false alarm, which is used in DIG. */
2458 priv->DIG_NumberFallbackVote = 0;
2459 priv->DIG_NumberUpgradeVote = 0;
2460 priv->LastSignalStrengthInPercent = 0;
2461 priv->Stats_SignalStrength = 0;
2462 priv->LastRxPktAntenna = 0;
2463 priv->SignalQuality = 0; /* in 0-100 index. */
2464 priv->Stats_SignalQuality = 0;
2465 priv->RecvSignalPower = 0; /* in dBm. */
2466 priv->Stats_RecvSignalPower = 0;
2467 priv->AdMainAntennaRxOkCnt = 0;
2468 priv->AdAuxAntennaRxOkCnt = 0;
2469 priv->bHWAdSwitched = false;
2470 priv->bRegHighPowerMechanism = true;
2471 priv->RegHiPwrUpperTh = 77;
2472 priv->RegHiPwrLowerTh = 75;
2473 priv->RegRSSIHiPwrUpperTh = 70;
2474 priv->RegRSSIHiPwrLowerTh = 20;
2475 priv->bCurCCKPkt = false;
2476 priv->UndecoratedSmoothedSS = -1;
2477 priv->bToUpdateTxPwr = false;
2478 priv->CurCCKRSSI = 0;
2481 priv->NumTxOkTotal = 0;
2482 priv->NumTxUnicast = 0;
2483 priv->keepAliveLevel = DEFAULT_KEEP_ALIVE_LEVEL;
2484 priv->CurrRetryCnt = 0;
2485 priv->LastRetryCnt = 0;
2486 priv->LastTxokCnt = 0;
2487 priv->LastRxokCnt = 0;
2488 priv->LastRetryRate = 0;
2489 priv->bTryuping = 0;
2490 priv->CurrTxRate = 0;
2491 priv->CurrRetryRate = 0;
2492 priv->TryupingCount = 0;
2493 priv->TryupingCountNoData = 0;
2494 priv->TryDownCountLowData = 0;
2495 priv->LastTxOKBytes = 0;
2496 priv->LastFailTxRate = 0;
2497 priv->LastFailTxRateSS = 0;
2498 priv->FailTxRateCount = 0;
2499 priv->LastTxThroughput = 0;
2500 priv->NumTxOkBytesTotal = 0;
2501 priv->ForcedDataRate = 0;
2502 priv->RegBModeGainStage = 1;
2504 priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
2505 spin_lock_init(&priv->irq_th_lock);
2506 spin_lock_init(&priv->tx_lock);
2507 spin_lock_init(&priv->ps_lock);
2508 spin_lock_init(&priv->rf_ps_lock);
2509 sema_init(&priv->wx_sem, 1);
2510 INIT_WORK(&priv->reset_wq, (void *)rtl8180_restart_wq);
2511 INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,
2512 (void *)rtl8180_hw_wakeup_wq);
2513 INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,
2514 (void *)rtl8180_hw_sleep_wq);
2515 INIT_WORK(&priv->ieee80211->wmm_param_update_wq,
2516 (void *)rtl8180_wmm_param_update);
2517 INIT_DELAYED_WORK(&priv->ieee80211->rate_adapter_wq,
2518 (void *)rtl8180_rate_adapter);
2519 INIT_DELAYED_WORK(&priv->ieee80211->hw_dig_wq,
2520 (void *)rtl8180_hw_dig_wq);
2521 INIT_DELAYED_WORK(&priv->ieee80211->tx_pw_wq,
2522 (void *)rtl8180_tx_pw_wq);
2523 INIT_DELAYED_WORK(&priv->ieee80211->GPIOChangeRFWorkItem,
2524 (void *) GPIOChangeRFWorkItemCallBack);
2525 tasklet_init(&priv->irq_rx_tasklet,
2526 (void(*)(unsigned long)) rtl8180_irq_rx_tasklet,
2527 (unsigned long)priv);
2529 init_timer(&priv->watch_dog_timer);
2530 priv->watch_dog_timer.data = (unsigned long)dev;
2531 priv->watch_dog_timer.function = watch_dog_adaptive;
2533 init_timer(&priv->rateadapter_timer);
2534 priv->rateadapter_timer.data = (unsigned long)dev;
2535 priv->rateadapter_timer.function = timer_rate_adaptive;
2536 priv->RateAdaptivePeriod = RATE_ADAPTIVE_TIMER_PERIOD;
2537 priv->bEnhanceTxPwr = false;
2539 priv->ieee80211->softmac_hard_start_xmit = rtl8180_hard_start_xmit;
2540 priv->ieee80211->set_chan = rtl8180_set_chan;
2541 priv->ieee80211->link_change = rtl8180_link_change;
2542 priv->ieee80211->softmac_data_hard_start_xmit = rtl8180_hard_data_xmit;
2543 priv->ieee80211->data_hard_stop = rtl8180_data_hard_stop;
2544 priv->ieee80211->data_hard_resume = rtl8180_data_hard_resume;
2546 priv->ieee80211->init_wmmparam_flag = 0;
2548 priv->ieee80211->start_send_beacons = rtl8180_start_tx_beacon;
2549 priv->ieee80211->stop_send_beacons = rtl8180_beacon_tx_disable;
2550 priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD;
2552 priv->ShortRetryLimit = 7;
2553 priv->LongRetryLimit = 7;
2554 priv->EarlyRxThreshold = 7;
2556 priv->TransmitConfig = (1<<TCR_DurProcMode_OFFSET) |
2557 (7<<TCR_MXDMA_OFFSET) |
2558 (priv->ShortRetryLimit<<TCR_SRL_OFFSET) |
2559 (priv->LongRetryLimit<<TCR_LRL_OFFSET);
2561 priv->ReceiveConfig = RCR_AMF | RCR_ADF | RCR_ACF |
2562 RCR_AB | RCR_AM | RCR_APM |
2563 (7<<RCR_MXDMA_OFFSET) |
2564 (priv->EarlyRxThreshold<<RCR_FIFO_OFFSET) |
2565 (priv->EarlyRxThreshold == 7 ?
2566 RCR_ONLYERLPKT : 0);
2568 priv->IntrMask = IMR_TMGDOK | IMR_TBDER | IMR_THPDER |
2569 IMR_THPDER | IMR_THPDOK |
2570 IMR_TVODER | IMR_TVODOK |
2571 IMR_TVIDER | IMR_TVIDOK |
2572 IMR_TBEDER | IMR_TBEDOK |
2573 IMR_TBKDER | IMR_TBKDOK |
2578 priv->InitialGain = 6;
2580 DMESG("MAC controller is a RTL8187SE b/g");
2582 priv->ieee80211->modulation |= IEEE80211_OFDM_MODULATION;
2583 priv->ieee80211->short_slot = 1;
2585 eeprom_93cx6_read(&eeprom, EEPROM_SW_REVD_OFFSET, &usValue);
2586 DMESG("usValue is %#hx\n", usValue);
2587 /* 3Read AntennaDiversity */
2589 /* SW Antenna Diversity. */
2590 priv->EEPROMSwAntennaDiversity = (usValue & EEPROM_SW_AD_MASK) ==
2591 EEPROM_SW_AD_ENABLE;
2593 /* Default Antenna to use. */
2594 priv->EEPROMDefaultAntenna1 = (usValue & EEPROM_DEF_ANT_MASK) ==
2597 if (priv->RegSwAntennaDiversityMechanism == 0) /* Auto */
2598 /* 0: default from EEPROM. */
2599 priv->bSwAntennaDiverity = priv->EEPROMSwAntennaDiversity;
2601 /* 1:disable antenna diversity, 2: enable antenna diversity. */
2602 priv->bSwAntennaDiverity = priv->RegSwAntennaDiversityMechanism == 2;
2604 if (priv->RegDefaultAntenna == 0)
2605 /* 0: default from EEPROM. */
2606 priv->bDefaultAntenna1 = priv->EEPROMDefaultAntenna1;
2608 /* 1: main, 2: aux. */
2609 priv->bDefaultAntenna1 = priv->RegDefaultAntenna == 2;
2611 priv->plcp_preamble_mode = 2;
2612 /* the eeprom type is stored in RCR register bit #6 */
2613 if (RCR_9356SEL & read_nic_dword(dev, RCR))
2614 priv->epromtype = EPROM_93c56;
2616 priv->epromtype = EPROM_93c46;
2618 eeprom_93cx6_multiread(&eeprom, 0x7, (__le16 *)
2621 for (i = 1, j = 0; i < 14; i += 2, j++) {
2622 eeprom_93cx6_read(&eeprom, EPROM_TXPW_CH1_2 + j, &word);
2623 priv->chtxpwr[i] = word & 0xff;
2624 priv->chtxpwr[i+1] = (word & 0xff00)>>8;
2626 for (i = 1, j = 0; i < 14; i += 2, j++) {
2627 eeprom_93cx6_read(&eeprom, EPROM_TXPW_OFDM_CH1_2 + j, &word);
2628 priv->chtxpwr_ofdm[i] = word & 0xff;
2629 priv->chtxpwr_ofdm[i+1] = (word & 0xff00) >> 8;
2632 /* 3Read crystal calibration and thermal meter indication on 87SE. */
2633 eeprom_93cx6_read(&eeprom, EEPROM_RSV>>1, &tmpu16);
2635 /* Crystal calibration for Xin and Xout resp. */
2636 priv->XtalCal_Xout = tmpu16 & EEPROM_XTAL_CAL_XOUT_MASK;
2637 priv->XtalCal_Xin = (tmpu16 & EEPROM_XTAL_CAL_XIN_MASK) >> 4;
2638 if ((tmpu16 & EEPROM_XTAL_CAL_ENABLE) >> 12)
2639 priv->bXtalCalibration = true;
2641 /* Thermal meter reference indication. */
2642 priv->ThermalMeter = (u8)((tmpu16 & EEPROM_THERMAL_METER_MASK) >> 8);
2643 if ((tmpu16 & EEPROM_THERMAL_METER_ENABLE) >> 13)
2644 priv->bTxPowerTrack = true;
2646 priv->rf_sleep = rtl8225z4_rf_sleep;
2647 priv->rf_wakeup = rtl8225z4_rf_wakeup;
2648 DMESGW("**PLEASE** REPORT SUCCESSFUL/UNSUCCESSFUL TO Realtek!");
2650 priv->rf_close = rtl8225z2_rf_close;
2651 priv->rf_init = rtl8225z2_rf_init;
2652 priv->rf_set_chan = rtl8225z2_rf_set_chan;
2653 priv->rf_set_sens = NULL;
2655 if (0 != alloc_rx_desc_ring(dev, priv->rxbuffersize, priv->rxringcount))
2658 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2659 TX_MANAGEPRIORITY_RING_ADDR))
2662 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2663 TX_BKPRIORITY_RING_ADDR))
2666 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2667 TX_BEPRIORITY_RING_ADDR))
2670 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2671 TX_VIPRIORITY_RING_ADDR))
2674 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2675 TX_VOPRIORITY_RING_ADDR))
2678 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txringcount,
2679 TX_HIGHPRIORITY_RING_ADDR))
2682 if (0 != alloc_tx_desc_ring(dev, priv->txbuffsize, priv->txbeaconcount,
2683 TX_BEACON_RING_ADDR))
2686 if (request_irq(dev->irq, (void *)rtl8180_interrupt, IRQF_SHARED, dev->name, dev)) {
2687 DMESGE("Error allocating IRQ %d", dev->irq);
2690 priv->irq = dev->irq;
2691 DMESG("IRQ %d", dev->irq);
2697 void rtl8180_no_hw_wep(struct net_device *dev)
2701 void rtl8180_set_hw_wep(struct net_device *dev)
2703 struct r8180_priv *priv = ieee80211_priv(dev);
2708 pgreg = read_nic_byte(dev, PGSELECT);
2709 write_nic_byte(dev, PGSELECT, pgreg & ~(1<<PGSELECT_PG_SHIFT));
2711 key0_word4 = read_nic_dword(dev, KEY0+4+4+4);
2712 key0_word4 &= ~0xff;
2713 key0_word4 |= priv->key0[3] & 0xff;
2714 write_nic_dword(dev, KEY0, (priv->key0[0]));
2715 write_nic_dword(dev, KEY0+4, (priv->key0[1]));
2716 write_nic_dword(dev, KEY0+4+4, (priv->key0[2]));
2717 write_nic_dword(dev, KEY0+4+4+4, (key0_word4));
2719 security = read_nic_byte(dev, SECURITY);
2720 security |= (1<<SECURITY_WEP_TX_ENABLE_SHIFT);
2721 security |= (1<<SECURITY_WEP_RX_ENABLE_SHIFT);
2722 security &= ~SECURITY_ENCRYP_MASK;
2723 security |= (SECURITY_ENCRYP_104<<SECURITY_ENCRYP_SHIFT);
2725 write_nic_byte(dev, SECURITY, security);
2727 DMESG("key %x %x %x %x", read_nic_dword(dev, KEY0+4+4+4),
2728 read_nic_dword(dev, KEY0+4+4), read_nic_dword(dev, KEY0+4),
2729 read_nic_dword(dev, KEY0));
2733 void rtl8185_rf_pins_enable(struct net_device *dev)
2736 /* tmp = read_nic_word(dev, RFPinsEnable); */
2737 write_nic_word(dev, RFPinsEnable, 0x1fff); /* | tmp); */
2740 void rtl8185_set_anaparam2(struct net_device *dev, u32 a)
2744 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
2746 conf3 = read_nic_byte(dev, CONFIG3);
2747 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
2748 write_nic_dword(dev, ANAPARAM2, a);
2750 conf3 = read_nic_byte(dev, CONFIG3);
2751 write_nic_byte(dev, CONFIG3, conf3 & ~(1<<CONFIG3_ANAPARAM_W_SHIFT));
2752 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2755 void rtl8180_set_anaparam(struct net_device *dev, u32 a)
2759 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
2761 conf3 = read_nic_byte(dev, CONFIG3);
2762 write_nic_byte(dev, CONFIG3, conf3 | (1<<CONFIG3_ANAPARAM_W_SHIFT));
2763 write_nic_dword(dev, ANAPARAM, a);
2765 conf3 = read_nic_byte(dev, CONFIG3);
2766 write_nic_byte(dev, CONFIG3, conf3 & ~(1<<CONFIG3_ANAPARAM_W_SHIFT));
2767 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2770 void rtl8185_tx_antenna(struct net_device *dev, u8 ant)
2772 write_nic_byte(dev, TX_ANTENNA, ant);
2773 force_pci_posting(dev);
2777 void rtl8185_write_phy(struct net_device *dev, u8 adr, u32 data)
2783 phyw = ((data<<8) | adr);
2785 /* Note that, we must write 0xff7c after 0x7d-0x7f to write BB register. */
2786 write_nic_byte(dev, 0x7f, ((phyw & 0xff000000) >> 24));
2787 write_nic_byte(dev, 0x7e, ((phyw & 0x00ff0000) >> 16));
2788 write_nic_byte(dev, 0x7d, ((phyw & 0x0000ff00) >> 8));
2789 write_nic_byte(dev, 0x7c, ((phyw & 0x000000ff)));
2791 /* this is ok to fail when we write AGC table. check for AGC table might be
2792 * done by masking with 0x7f instead of 0xff
2794 /* if (phyr != (data&0xff)) DMESGW("Phy write timeout %x %x %x", phyr, data, adr); */
2797 inline void write_phy_ofdm(struct net_device *dev, u8 adr, u32 data)
2800 rtl8185_write_phy(dev, adr, data);
2803 void write_phy_cck(struct net_device *dev, u8 adr, u32 data)
2806 rtl8185_write_phy(dev, adr, data | 0x10000);
2810 * This configures registers for beacon tx and enables it via
2811 * rtl8180_beacon_tx_enable(). rtl8180_beacon_tx_disable() might
2812 * be used to stop beacon transmission
2814 void rtl8180_start_tx_beacon(struct net_device *dev)
2818 DMESG("Enabling beacon TX");
2819 rtl8180_prepare_beacon(dev);
2820 rtl8180_irq_disable(dev);
2821 rtl8180_beacon_tx_enable(dev);
2823 word = read_nic_word(dev, AtimWnd) & ~AtimWnd_AtimWnd;
2824 write_nic_word(dev, AtimWnd, word); /* word |= */
2826 word = read_nic_word(dev, BintrItv);
2827 word &= ~BintrItv_BintrItv;
2828 word |= 1000; /* priv->ieee80211->current_network.beacon_interval *
2829 ((priv->txbeaconcount > 1)?(priv->txbeaconcount-1):1);
2830 // FIXME: check if correct ^^ worked with 0x3e8;
2832 write_nic_word(dev, BintrItv, word);
2834 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
2836 rtl8185b_irq_enable(dev);
2839 static struct net_device_stats *rtl8180_stats(struct net_device *dev)
2841 struct r8180_priv *priv = ieee80211_priv(dev);
2843 return &priv->ieee80211->stats;
2847 * Change current and default preamble mode.
2850 MgntActSet_802_11_PowerSaveMode(
2851 struct r8180_priv *priv,
2855 /* Currently, we do not change power save mode on IBSS mode. */
2856 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
2859 priv->ieee80211->ps = rtPsMode;
2864 void LeisurePSEnter(struct r8180_priv *priv)
2866 if (priv->bLeisurePs) {
2867 if (priv->ieee80211->ps == IEEE80211_PS_DISABLED)
2868 /* IEEE80211_PS_ENABLE */
2869 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST);
2873 void LeisurePSLeave(struct r8180_priv *priv)
2875 if (priv->bLeisurePs) {
2876 if (priv->ieee80211->ps != IEEE80211_PS_DISABLED)
2877 MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_DISABLED);
2881 void rtl8180_hw_wakeup_wq(struct work_struct *work)
2883 struct delayed_work *dwork = to_delayed_work(work);
2884 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, hw_wakeup_wq);
2885 struct net_device *dev = ieee->dev;
2887 rtl8180_hw_wakeup(dev);
2890 void rtl8180_hw_sleep_wq(struct work_struct *work)
2892 struct delayed_work *dwork = to_delayed_work(work);
2893 struct ieee80211_device *ieee = container_of(dwork, struct ieee80211_device, hw_sleep_wq);
2894 struct net_device *dev = ieee->dev;
2896 rtl8180_hw_sleep_down(dev);
2899 static void MgntLinkKeepAlive(struct r8180_priv *priv)
2901 if (priv->keepAliveLevel == 0)
2904 if (priv->ieee80211->state == IEEE80211_LINKED) {
2909 if ((priv->keepAliveLevel == 2) ||
2910 (priv->link_detect.LastNumTxUnicast == priv->NumTxUnicast &&
2911 priv->link_detect.LastNumRxUnicast == priv->ieee80211->NumRxUnicast)
2913 priv->link_detect.IdleCount++;
2916 * Send a Keep-Alive packet packet to AP if we had been idle for a while.
2918 if (priv->link_detect.IdleCount >= ((KEEP_ALIVE_INTERVAL / CHECK_FOR_HANG_PERIOD)-1)) {
2919 priv->link_detect.IdleCount = 0;
2920 ieee80211_sta_ps_send_null_frame(priv->ieee80211, false);
2923 priv->link_detect.IdleCount = 0;
2925 priv->link_detect.LastNumTxUnicast = priv->NumTxUnicast;
2926 priv->link_detect.LastNumRxUnicast = priv->ieee80211->NumRxUnicast;
2930 void rtl8180_watch_dog(struct net_device *dev)
2932 struct r8180_priv *priv = ieee80211_priv(dev);
2933 bool bEnterPS = false;
2934 bool bBusyTraffic = false;
2938 if (priv->ieee80211->actscanning == false) {
2939 if ((priv->ieee80211->iw_mode != IW_MODE_ADHOC) &&
2940 (priv->ieee80211->state == IEEE80211_NOLINK) &&
2941 (priv->ieee80211->beinretry == false) &&
2942 (priv->eRFPowerState == eRfOn))
2945 /* YJ,add,080828,for link state check */
2946 if ((priv->ieee80211->state == IEEE80211_LINKED) && (priv->ieee80211->iw_mode == IW_MODE_INFRA)) {
2947 SlotIndex = (priv->link_detect.SlotIndex++) % priv->link_detect.SlotNum;
2948 priv->link_detect.RxFrameNum[SlotIndex] = priv->ieee80211->NumRxDataInPeriod + priv->ieee80211->NumRxBcnInPeriod;
2949 for (i = 0; i < priv->link_detect.SlotNum; i++)
2950 TotalRxNum += priv->link_detect.RxFrameNum[i];
2952 if (TotalRxNum == 0) {
2953 priv->ieee80211->state = IEEE80211_ASSOCIATING;
2954 queue_work(priv->ieee80211->wq, &priv->ieee80211->associate_procedure_wq);
2958 /* YJ,add,080828,for KeepAlive */
2959 MgntLinkKeepAlive(priv);
2961 /* YJ,add,080828,for LPS */
2962 LeisurePSLeave(priv);
2964 if (priv->ieee80211->state == IEEE80211_LINKED) {
2965 priv->link_detect.NumRxOkInPeriod = priv->ieee80211->NumRxDataInPeriod;
2966 if (priv->link_detect.NumRxOkInPeriod > 666 ||
2967 priv->link_detect.NumTxOkInPeriod > 666) {
2968 bBusyTraffic = true;
2970 if (((priv->link_detect.NumRxOkInPeriod + priv->link_detect.NumTxOkInPeriod) > 8)
2971 || (priv->link_detect.NumRxOkInPeriod > 2)) {
2977 LeisurePSEnter(priv);
2979 LeisurePSLeave(priv);
2981 LeisurePSLeave(priv);
2982 priv->link_detect.bBusyTraffic = bBusyTraffic;
2983 priv->link_detect.NumRxOkInPeriod = 0;
2984 priv->link_detect.NumTxOkInPeriod = 0;
2985 priv->ieee80211->NumRxDataInPeriod = 0;
2986 priv->ieee80211->NumRxBcnInPeriod = 0;
2989 int _rtl8180_up(struct net_device *dev)
2991 struct r8180_priv *priv = ieee80211_priv(dev);
2995 DMESG("Bringing up iface");
2996 rtl8185b_adapter_start(dev);
2997 rtl8185b_rx_enable(dev);
2998 rtl8185b_tx_enable(dev);
2999 if (priv->bInactivePs) {
3000 if (priv->ieee80211->iw_mode == IW_MODE_ADHOC)
3003 timer_rate_adaptive((unsigned long)dev);
3004 watch_dog_adaptive((unsigned long)dev);
3005 if (priv->bSwAntennaDiverity)
3006 SwAntennaDiversityTimerCallback(dev);
3007 ieee80211_softmac_start_protocol(priv->ieee80211);
3011 int rtl8180_open(struct net_device *dev)
3013 struct r8180_priv *priv = ieee80211_priv(dev);
3016 down(&priv->wx_sem);
3017 ret = rtl8180_up(dev);
3022 int rtl8180_up(struct net_device *dev)
3024 struct r8180_priv *priv = ieee80211_priv(dev);
3029 return _rtl8180_up(dev);
3032 int rtl8180_close(struct net_device *dev)
3034 struct r8180_priv *priv = ieee80211_priv(dev);
3037 down(&priv->wx_sem);
3038 ret = rtl8180_down(dev);
3044 int rtl8180_down(struct net_device *dev)
3046 struct r8180_priv *priv = ieee80211_priv(dev);
3053 ieee80211_softmac_stop_protocol(priv->ieee80211);
3055 if (!netif_queue_stopped(dev))
3056 netif_stop_queue(dev);
3057 rtl8180_rtx_disable(dev);
3058 rtl8180_irq_disable(dev);
3059 del_timer_sync(&priv->watch_dog_timer);
3060 del_timer_sync(&priv->rateadapter_timer);
3061 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
3062 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
3063 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
3064 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
3065 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
3066 del_timer_sync(&priv->SwAntennaDiversityTimer);
3067 SetZebraRFPowerState8185(dev, eRfOff);
3068 memset(&(priv->ieee80211->current_network), 0, sizeof(struct ieee80211_network));
3069 priv->ieee80211->state = IEEE80211_NOLINK;
3073 void rtl8180_restart_wq(struct work_struct *work)
3075 struct r8180_priv *priv = container_of(work, struct r8180_priv, reset_wq);
3076 struct net_device *dev = priv->dev;
3078 down(&priv->wx_sem);
3080 rtl8180_commit(dev);
3085 void rtl8180_restart(struct net_device *dev)
3087 struct r8180_priv *priv = ieee80211_priv(dev);
3089 schedule_work(&priv->reset_wq);
3092 void rtl8180_commit(struct net_device *dev)
3094 struct r8180_priv *priv = ieee80211_priv(dev);
3099 del_timer_sync(&priv->watch_dog_timer);
3100 del_timer_sync(&priv->rateadapter_timer);
3101 cancel_delayed_work(&priv->ieee80211->rate_adapter_wq);
3102 cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
3103 cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
3104 cancel_delayed_work(&priv->ieee80211->hw_dig_wq);
3105 cancel_delayed_work(&priv->ieee80211->tx_pw_wq);
3106 del_timer_sync(&priv->SwAntennaDiversityTimer);
3107 ieee80211_softmac_stop_protocol(priv->ieee80211);
3108 rtl8180_irq_disable(dev);
3109 rtl8180_rtx_disable(dev);
3113 static void r8180_set_multicast(struct net_device *dev)
3115 struct r8180_priv *priv = ieee80211_priv(dev);
3118 promisc = (dev->flags & IFF_PROMISC) ? 1 : 0;
3120 if (promisc != priv->promisc)
3121 rtl8180_restart(dev);
3123 priv->promisc = promisc;
3126 int r8180_set_mac_adr(struct net_device *dev, void *mac)
3128 struct r8180_priv *priv = ieee80211_priv(dev);
3129 struct sockaddr *addr = mac;
3131 down(&priv->wx_sem);
3133 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
3135 if (priv->ieee80211->iw_mode == IW_MODE_MASTER)
3136 memcpy(priv->ieee80211->current_network.bssid, dev->dev_addr, ETH_ALEN);
3148 /* based on ipw2200 driver */
3149 int rtl8180_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
3151 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3152 struct iwreq *wrq = (struct iwreq *) rq;
3156 case RTL_IOCTL_WPA_SUPPLICANT:
3157 ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
3166 static const struct net_device_ops rtl8180_netdev_ops = {
3167 .ndo_open = rtl8180_open,
3168 .ndo_stop = rtl8180_close,
3169 .ndo_get_stats = rtl8180_stats,
3170 .ndo_tx_timeout = rtl8180_restart,
3171 .ndo_do_ioctl = rtl8180_ioctl,
3172 .ndo_set_rx_mode = r8180_set_multicast,
3173 .ndo_set_mac_address = r8180_set_mac_adr,
3174 .ndo_validate_addr = eth_validate_addr,
3175 .ndo_change_mtu = eth_change_mtu,
3176 .ndo_start_xmit = ieee80211_rtl_xmit,
3179 static int rtl8180_pci_probe(struct pci_dev *pdev,
3180 const struct pci_device_id *id)
3182 unsigned long ioaddr = 0;
3183 struct net_device *dev = NULL;
3184 struct r8180_priv *priv = NULL;
3188 unsigned long pmem_start, pmem_len, pmem_flags;
3190 DMESG("Configuring chip resources");
3192 if (pci_enable_device(pdev)) {
3193 DMESG("Failed to enable PCI device");
3197 pci_set_master(pdev);
3198 pci_set_dma_mask(pdev, 0xffffff00ULL);
3199 pci_set_consistent_dma_mask(pdev, 0xffffff00ULL);
3200 dev = alloc_ieee80211(sizeof(struct r8180_priv));
3205 priv = ieee80211_priv(dev);
3206 priv->ieee80211 = netdev_priv(dev);
3208 pci_set_drvdata(pdev, dev);
3209 SET_NETDEV_DEV(dev, &pdev->dev);
3211 priv = ieee80211_priv(dev);
3214 pmem_start = pci_resource_start(pdev, 1);
3215 pmem_len = pci_resource_len(pdev, 1);
3216 pmem_flags = pci_resource_flags(pdev, 1);
3218 if (!(pmem_flags & IORESOURCE_MEM)) {
3219 DMESG("region #1 not a MMIO resource, aborting");
3223 if (!request_mem_region(pmem_start, pmem_len, RTL8180_MODULE_NAME)) {
3224 DMESG("request_mem_region failed!");
3228 ioaddr = (unsigned long)ioremap_nocache(pmem_start, pmem_len);
3229 if (ioaddr == (unsigned long)NULL) {
3230 DMESG("ioremap failed!");
3234 dev->mem_start = ioaddr; /* shared mem start */
3235 dev->mem_end = ioaddr + pci_resource_len(pdev, 0); /* shared mem end */
3237 pci_read_config_byte(pdev, 0x05, &unit);
3238 pci_write_config_byte(pdev, 0x05, unit & (~0x04));
3240 dev->irq = pdev->irq;
3243 dev->netdev_ops = &rtl8180_netdev_ops;
3244 dev->wireless_handlers = &r8180_wx_handlers_def;
3246 dev->type = ARPHRD_ETHER;
3247 dev->watchdog_timeo = HZ*3;
3249 if (dev_alloc_name(dev, ifname) < 0) {
3250 DMESG("Oops: devname already taken! Trying wlan%%d...\n");
3251 strcpy(ifname, "wlan%d");
3252 dev_alloc_name(dev, ifname);
3255 if (rtl8180_init(dev) != 0) {
3256 DMESG("Initialization failed");
3260 netif_carrier_off(dev);
3262 if (register_netdev(dev))
3265 rtl8180_proc_init_one(dev);
3267 DMESG("Driver probe completed\n");
3270 if (dev->mem_start != (unsigned long)NULL) {
3271 iounmap((void *)dev->mem_start);
3272 release_mem_region(pci_resource_start(pdev, 1),
3273 pci_resource_len(pdev, 1));
3278 free_irq(dev->irq, dev);
3281 free_ieee80211(dev);
3285 pci_disable_device(pdev);
3287 DMESG("wlan driver load failed\n");
3288 pci_set_drvdata(pdev, NULL);
3292 static void rtl8180_pci_remove(struct pci_dev *pdev)
3294 struct r8180_priv *priv;
3295 struct net_device *dev = pci_get_drvdata(pdev);
3298 unregister_netdev(dev);
3300 priv = ieee80211_priv(dev);
3302 rtl8180_proc_remove_one(dev);
3304 priv->rf_close(dev);
3309 DMESG("Freeing irq %d", dev->irq);
3310 free_irq(dev->irq, dev);
3314 free_rx_desc_ring(dev);
3315 free_tx_desc_rings(dev);
3317 if (dev->mem_start != (unsigned long)NULL) {
3318 iounmap((void *)dev->mem_start);
3319 release_mem_region(pci_resource_start(pdev, 1),
3320 pci_resource_len(pdev, 1));
3323 free_ieee80211(dev);
3325 pci_disable_device(pdev);
3327 DMESG("wlan driver removed\n");
3330 /* fun with the built-in ieee80211 stack... */
3331 extern int ieee80211_crypto_init(void);
3332 extern void ieee80211_crypto_deinit(void);
3333 extern int ieee80211_crypto_tkip_init(void);
3334 extern void ieee80211_crypto_tkip_exit(void);
3335 extern int ieee80211_crypto_ccmp_init(void);
3336 extern void ieee80211_crypto_ccmp_exit(void);
3337 extern int ieee80211_crypto_wep_init(void);
3338 extern void ieee80211_crypto_wep_exit(void);
3340 static int __init rtl8180_pci_module_init(void)
3344 ret = ieee80211_crypto_init();
3346 pr_err("ieee80211_crypto_init() failed %d\n", ret);
3349 ret = ieee80211_crypto_tkip_init();
3351 pr_err("ieee80211_crypto_tkip_init() failed %d\n", ret);
3354 ret = ieee80211_crypto_ccmp_init();
3356 pr_err("ieee80211_crypto_ccmp_init() failed %d\n", ret);
3359 ret = ieee80211_crypto_wep_init();
3361 pr_err("ieee80211_crypto_wep_init() failed %d\n", ret);
3365 pr_info("\nLinux kernel driver for RTL8180 / RTL8185 based WLAN cards\n");
3366 pr_info("Copyright (c) 2004-2005, Andrea Merello\n");
3367 DMESG("Initializing module");
3368 DMESG("Wireless extensions version %d", WIRELESS_EXT);
3369 rtl8180_proc_module_init();
3371 if (pci_register_driver(&rtl8180_pci_driver)) {
3372 DMESG("No device found");
3378 static void __exit rtl8180_pci_module_exit(void)
3380 pci_unregister_driver(&rtl8180_pci_driver);
3381 rtl8180_proc_module_remove();
3382 ieee80211_crypto_tkip_exit();
3383 ieee80211_crypto_ccmp_exit();
3384 ieee80211_crypto_wep_exit();
3385 ieee80211_crypto_deinit();
3389 void rtl8180_try_wake_queue(struct net_device *dev, int pri)
3391 unsigned long flags;
3393 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3395 spin_lock_irqsave(&priv->tx_lock, flags);
3396 enough_desc = check_nic_enought_desc(dev, pri);
3397 spin_unlock_irqrestore(&priv->tx_lock, flags);
3400 ieee80211_rtl_wake_queue(priv->ieee80211);
3403 void rtl8180_tx_isr(struct net_device *dev, int pri, short error)
3405 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3406 u32 *tail; /* tail virtual addr */
3407 u32 *head; /* head virtual addr */
3408 u32 *begin; /* start of ring virtual addr */
3409 u32 *nicv; /* nic pointer virtual addr */
3410 u32 nic; /* nic pointer physical addr */
3411 u32 nicbegin; /* start of ring physical addr */
3413 /* physical addr are ok on 32 bits since we set DMA mask */
3418 priv->stats.txretry++; /* tony 20060601 */
3419 spin_lock_irqsave(&priv->tx_lock, flag);
3421 case MANAGE_PRIORITY:
3422 tail = priv->txmapringtail;
3423 begin = priv->txmapring;
3424 head = priv->txmapringhead;
3425 nic = read_nic_dword(dev, TX_MANAGEPRIORITY_RING_ADDR);
3426 nicbegin = priv->txmapringdma;
3429 tail = priv->txbkpringtail;
3430 begin = priv->txbkpring;
3431 head = priv->txbkpringhead;
3432 nic = read_nic_dword(dev, TX_BKPRIORITY_RING_ADDR);
3433 nicbegin = priv->txbkpringdma;
3436 tail = priv->txbepringtail;
3437 begin = priv->txbepring;
3438 head = priv->txbepringhead;
3439 nic = read_nic_dword(dev, TX_BEPRIORITY_RING_ADDR);
3440 nicbegin = priv->txbepringdma;
3443 tail = priv->txvipringtail;
3444 begin = priv->txvipring;
3445 head = priv->txvipringhead;
3446 nic = read_nic_dword(dev, TX_VIPRIORITY_RING_ADDR);
3447 nicbegin = priv->txvipringdma;
3450 tail = priv->txvopringtail;
3451 begin = priv->txvopring;
3452 head = priv->txvopringhead;
3453 nic = read_nic_dword(dev, TX_VOPRIORITY_RING_ADDR);
3454 nicbegin = priv->txvopringdma;
3457 tail = priv->txhpringtail;
3458 begin = priv->txhpring;
3459 head = priv->txhpringhead;
3460 nic = read_nic_dword(dev, TX_HIGHPRIORITY_RING_ADDR);
3461 nicbegin = priv->txhpringdma;
3465 spin_unlock_irqrestore(&priv->tx_lock, flag);
3469 nicv = (u32 *)((nic - nicbegin) + (u8 *)begin);
3470 if ((head <= tail && (nicv > tail || nicv < head)) ||
3471 (head > tail && (nicv > tail && nicv < head))) {
3472 DMESGW("nic has lost pointer");
3473 spin_unlock_irqrestore(&priv->tx_lock, flag);
3474 rtl8180_restart(dev);
3479 * We check all the descriptors between the head and the nic,
3480 * but not the currently pointed by the nic (the next to be txed)
3481 * and the previous of the pointed (might be in process ??)
3483 offs = (nic - nicbegin);
3484 offs = offs / 8 / 4;
3485 hd = (head - begin) / 8;
3490 j = offs + (priv->txringcount-1-hd);
3496 for (i = 0; i < j; i++) {
3497 if ((*head) & (1<<31))
3499 if (((*head)&(0x10000000)) != 0) {
3500 priv->CurrRetryCnt += (u16)((*head) & (0x000000ff));
3502 priv->NumTxOkTotal++;
3506 priv->NumTxOkBytesTotal += (*(head+3)) & (0x00000fff);
3508 *head = *head & ~(1<<31);
3510 if ((head - begin)/8 == priv->txringcount-1)
3517 * The head has been moved to the last certainly TXed
3518 * (or at least processed by the nic) packet.
3519 * The driver take forcefully owning of all these packets
3520 * If the packet previous of the nic pointer has been
3521 * processed this doesn't matter: it will be checked
3522 * here at the next round. Anyway if no more packet are
3523 * TXed no memory leak occur at all.
3527 case MANAGE_PRIORITY:
3528 priv->txmapringhead = head;
3530 if (priv->ack_tx_to_ieee) {
3531 if (rtl8180_is_tx_queue_empty(dev)) {
3532 priv->ack_tx_to_ieee = 0;
3533 ieee80211_ps_tx_ack(priv->ieee80211, !error);
3538 priv->txbkpringhead = head;
3541 priv->txbepringhead = head;
3544 priv->txvipringhead = head;
3547 priv->txvopringhead = head;
3550 priv->txhpringhead = head;
3554 spin_unlock_irqrestore(&priv->tx_lock, flag);
3557 irqreturn_t rtl8180_interrupt(int irq, void *netdev, struct pt_regs *regs)
3559 struct net_device *dev = (struct net_device *) netdev;
3560 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3561 unsigned long flags;
3564 /* We should return IRQ_NONE, but for now let me keep this */
3565 if (priv->irq_enabled == 0)
3568 spin_lock_irqsave(&priv->irq_th_lock, flags);
3571 inta = read_nic_dword(dev, ISR); /* & priv->IntrMask; */
3572 write_nic_dword(dev, ISR, inta); /* reset int situation */
3574 priv->stats.shints++;
3577 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3580 * most probably we can safely return IRQ_NONE,
3581 * but for now is better to avoid problems
3585 if (inta == 0xffff) {
3586 /* HW disappeared */
3587 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3593 if (!netif_running(dev)) {
3594 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3598 if (inta & ISR_TimeOut)
3599 write_nic_dword(dev, TimerInt, 0);
3601 if (inta & ISR_TBDOK)
3602 priv->stats.txbeacon++;
3604 if (inta & ISR_TBDER)
3605 priv->stats.txbeaconerr++;
3607 if (inta & IMR_TMGDOK)
3608 rtl8180_tx_isr(dev, MANAGE_PRIORITY, 0);
3610 if (inta & ISR_THPDER) {
3611 priv->stats.txhperr++;
3612 rtl8180_tx_isr(dev, HI_PRIORITY, 1);
3613 priv->ieee80211->stats.tx_errors++;
3616 if (inta & ISR_THPDOK) { /* High priority tx ok */
3617 priv->link_detect.NumTxOkInPeriod++; /* YJ,add,080828 */
3618 priv->stats.txhpokint++;
3619 rtl8180_tx_isr(dev, HI_PRIORITY, 0);
3623 priv->stats.rxerr++;
3625 if (inta & ISR_TBKDER) { /* corresponding to BK_PRIORITY */
3626 priv->stats.txbkperr++;
3627 priv->ieee80211->stats.tx_errors++;
3628 rtl8180_tx_isr(dev, BK_PRIORITY, 1);
3629 rtl8180_try_wake_queue(dev, BK_PRIORITY);
3632 if (inta & ISR_TBEDER) { /* corresponding to BE_PRIORITY */
3633 priv->stats.txbeperr++;
3634 priv->ieee80211->stats.tx_errors++;
3635 rtl8180_tx_isr(dev, BE_PRIORITY, 1);
3636 rtl8180_try_wake_queue(dev, BE_PRIORITY);
3638 if (inta & ISR_TNPDER) { /* corresponding to VO_PRIORITY */
3639 priv->stats.txnperr++;
3640 priv->ieee80211->stats.tx_errors++;
3641 rtl8180_tx_isr(dev, NORM_PRIORITY, 1);
3642 rtl8180_try_wake_queue(dev, NORM_PRIORITY);
3645 if (inta & ISR_TLPDER) { /* corresponding to VI_PRIORITY */
3646 priv->stats.txlperr++;
3647 priv->ieee80211->stats.tx_errors++;
3648 rtl8180_tx_isr(dev, LOW_PRIORITY, 1);
3649 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
3652 if (inta & ISR_ROK) {
3653 priv->stats.rxint++;
3654 tasklet_schedule(&priv->irq_rx_tasklet);
3657 if (inta & ISR_RQoSOK) {
3658 priv->stats.rxint++;
3659 tasklet_schedule(&priv->irq_rx_tasklet);
3662 if (inta & ISR_BcnInt)
3663 rtl8180_prepare_beacon(dev);
3665 if (inta & ISR_RDU) {
3666 DMESGW("No RX descriptor available");
3667 priv->stats.rxrdu++;
3668 tasklet_schedule(&priv->irq_rx_tasklet);
3671 if (inta & ISR_RXFOVW) {
3672 priv->stats.rxoverflow++;
3673 tasklet_schedule(&priv->irq_rx_tasklet);
3676 if (inta & ISR_TXFOVW)
3677 priv->stats.txoverflow++;
3679 if (inta & ISR_TNPDOK) { /* Normal priority tx ok */
3680 priv->link_detect.NumTxOkInPeriod++; /* YJ,add,080828 */
3681 priv->stats.txnpokint++;
3682 rtl8180_tx_isr(dev, NORM_PRIORITY, 0);
3683 rtl8180_try_wake_queue(dev, NORM_PRIORITY);
3686 if (inta & ISR_TLPDOK) { /* Low priority tx ok */
3687 priv->link_detect.NumTxOkInPeriod++; /* YJ,add,080828 */
3688 priv->stats.txlpokint++;
3689 rtl8180_tx_isr(dev, LOW_PRIORITY, 0);
3690 rtl8180_try_wake_queue(dev, LOW_PRIORITY);
3693 if (inta & ISR_TBKDOK) { /* corresponding to BK_PRIORITY */
3694 priv->stats.txbkpokint++;
3695 priv->link_detect.NumTxOkInPeriod++; /* YJ,add,080828 */
3696 rtl8180_tx_isr(dev, BK_PRIORITY, 0);
3697 rtl8180_try_wake_queue(dev, BE_PRIORITY);
3700 if (inta & ISR_TBEDOK) { /* corresponding to BE_PRIORITY */
3701 priv->stats.txbeperr++;
3702 priv->link_detect.NumTxOkInPeriod++; /* YJ,add,080828 */
3703 rtl8180_tx_isr(dev, BE_PRIORITY, 0);
3704 rtl8180_try_wake_queue(dev, BE_PRIORITY);
3706 force_pci_posting(dev);
3707 spin_unlock_irqrestore(&priv->irq_th_lock, flags);
3712 void rtl8180_irq_rx_tasklet(struct r8180_priv *priv)
3714 rtl8180_rx(priv->dev);
3717 void GPIOChangeRFWorkItemCallBack(struct work_struct *work)
3719 struct ieee80211_device *ieee = container_of(work, struct ieee80211_device, GPIOChangeRFWorkItem.work);
3720 struct net_device *dev = ieee->dev;
3721 struct r8180_priv *priv = ieee80211_priv(dev);
3724 RT_RF_POWER_STATE eRfPowerStateToSet;
3725 bool bActuallySet = false;
3728 static char *RadioPowerPath = "/etc/acpi/events/RadioPower.sh";
3729 static char *envp[] = {"HOME=/", "TERM=linux", "PATH=/usr/bin:/bin", NULL};
3730 static int readf_count;
3732 readf_count = (readf_count+1)%0xffff;
3733 /* We should turn off LED before polling FF51[4]. */
3736 btPSR = read_nic_byte(dev, PSR);
3737 write_nic_byte(dev, PSR, (btPSR & ~BIT3));
3739 /* It need to delay 4us suggested by Jong, 2008-01-16 */
3742 /* HW radio On/Off according to the value of FF51[4](config0) */
3743 btConfig0 = btPSR = read_nic_byte(dev, CONFIG0);
3745 eRfPowerStateToSet = (btConfig0 & BIT4) ? eRfOn : eRfOff;
3747 /* Turn LED back on when radio enabled */
3748 if (eRfPowerStateToSet == eRfOn)
3749 write_nic_byte(dev, PSR, btPSR | BIT3);
3751 if ((priv->ieee80211->bHwRadioOff == true) &&
3752 (eRfPowerStateToSet == eRfOn)) {
3753 priv->ieee80211->bHwRadioOff = false;
3754 bActuallySet = true;
3755 } else if ((priv->ieee80211->bHwRadioOff == false) &&
3756 (eRfPowerStateToSet == eRfOff)) {
3757 priv->ieee80211->bHwRadioOff = true;
3758 bActuallySet = true;
3762 MgntActSet_RF_State(dev, eRfPowerStateToSet, RF_CHANGE_BY_HW);
3764 /* To update the UI status for Power status changed */
3765 if (priv->ieee80211->bHwRadioOff == true)
3769 argv[0] = RadioPowerPath;
3772 call_usermodehelper(RadioPowerPath, argv, envp, UMH_WAIT_PROC);
3776 module_init(rtl8180_pci_module_init);
3777 module_exit(rtl8180_pci_module_exit);