staging: rtl8192e: Pass ieee80211_device to callbacks
[deliverable/linux.git] / drivers / staging / rtl8192e / r8192E_core.c
index 84b56cc27ff7c428a64bdca0f6844377fae644fc..c392f19b0bdbfb43dc3d9fceb3c4613db83ac2f2 100644 (file)
@@ -24,7 +24,7 @@
  * Jerry chuang <wlanfae@realtek.com>
  */
 
-//#define CONFIG_RTL8192_IO_MAP
+
 #include <linux/vmalloc.h>
 #include <linux/slab.h>
 #include <asm/uaccess.h>
@@ -96,19 +96,20 @@ static struct pci_driver rtl8192_pci_driver = {
 #endif
 };
 
-static void rtl8192_start_beacon(struct net_device *dev);
-static void rtl8192_stop_beacon(struct net_device *dev);
+static void rtl8192_start_beacon(struct ieee80211_device *ieee80211);
+static void rtl8192_stop_beacon(struct ieee80211_device *ieee80211);
 static void rtl819x_watchdog_wqcallback(struct work_struct *work);
 static void rtl8192_irq_rx_tasklet(unsigned long arg);
 static void rtl8192_irq_tx_tasklet(unsigned long arg);
 static void rtl8192_prepare_beacon(unsigned long arg);
 static irqreturn_t rtl8192_interrupt(int irq, void *netdev);
-static void rtl819xE_tx_cmd(struct net_device *dev, struct sk_buff *skb);
-static void rtl8192_update_ratr_table(struct net_device* dev);
+static void rtl819xE_tx_cmd(struct r8192_priv *priv, struct sk_buff *skb);
+static void rtl8192_update_ratr_table(struct r8192_priv *priv);
 static void rtl8192_restart(struct work_struct *work);
 static void watch_dog_timer_callback(unsigned long data);
-static int _rtl8192_up(struct net_device *dev);
+static int _rtl8192_up(struct r8192_priv *priv);
 static void rtl8192_cancel_deferred_work(struct r8192_priv* priv);
+static short rtl8192_tx(struct r8192_priv *priv, struct sk_buff* skb);
 
 #ifdef ENABLE_DOT11D
 
@@ -190,9 +191,8 @@ static inline bool rx_hal_is_cck_rate(prx_fwinfo_819x_pci pdrvinfo)
                !pdrvinfo->RxHT;
 }
 
-void CamResetAllEntry(struct net_device *dev)
+void CamResetAllEntry(struct r8192_priv* priv)
 {
-       struct r8192_priv* priv = ieee80211_priv(dev);
        write_nic_dword(priv, RWCAM, BIT31|BIT30);
 }
 
@@ -208,87 +208,39 @@ u32 read_cam(struct r8192_priv *priv, u8 addr)
         return read_nic_dword(priv, 0xa8);
 }
 
-#ifdef CONFIG_RTL8180_IO_MAP
-
-u8 read_nic_byte(struct r8192_priv *priv, int x)
-{
-       struct net_device *dev = priv->ieee80211->dev;
-        return 0xff&inb(dev->base_addr +x);
-}
-
-u32 read_nic_dword(struct r8192_priv *priv, int x)
-{
-       struct net_device *dev = priv->ieee80211->dev;
-        return inl(dev->base_addr +x);
-}
-
-u16 read_nic_word(struct r8192_priv *priv, int x)
-{
-       struct net_device *dev = priv->ieee80211->dev;
-        return inw(dev->base_addr +x);
-}
-
-void write_nic_byte(struct r8192_priv *priv, int x,u8 y)
-{
-       struct net_device *dev = priv->ieee80211->dev;
-        outb(y&0xff,dev->base_addr +x);
-}
-
-void write_nic_word(struct r8192_priv *priv, int x,u16 y)
-{
-       struct net_device *dev = priv->ieee80211->dev;
-        outw(y,dev->base_addr +x);
-}
-
-void write_nic_dword(struct r8192_priv *priv, int x,u32 y)
-{
-       struct net_device *dev = priv->ieee80211->dev;
-        outl(y,dev->base_addr +x);
-}
-
-#else /* RTL_IO_MAP */
-
 u8 read_nic_byte(struct r8192_priv *priv, int x)
 {
-       struct net_device *dev = priv->ieee80211->dev;
-        return 0xff&readb((u8*)dev->mem_start +x);
+        return 0xff & readb(priv->mem_start + x);
 }
 
 u32 read_nic_dword(struct r8192_priv *priv, int x)
 {
-       struct net_device *dev = priv->ieee80211->dev;
-        return readl((u8*)dev->mem_start +x);
+        return readl(priv->mem_start + x);
 }
 
 u16 read_nic_word(struct r8192_priv *priv, int x)
 {
-       struct net_device *dev = priv->ieee80211->dev;
-        return readw((u8*)dev->mem_start +x);
+        return readw(priv->mem_start + x);
 }
 
 void write_nic_byte(struct r8192_priv *priv, int x,u8 y)
 {
-       struct net_device *dev = priv->ieee80211->dev;
-        writeb(y,(u8*)dev->mem_start +x);
+        writeb(y, priv->mem_start + x);
        udelay(20);
 }
 
 void write_nic_dword(struct r8192_priv *priv, int x,u32 y)
 {
-       struct net_device *dev = priv->ieee80211->dev;
-        writel(y,(u8*)dev->mem_start +x);
+        writel(y, priv->mem_start + x);
        udelay(20);
 }
 
 void write_nic_word(struct r8192_priv *priv, int x,u16 y)
 {
-       struct net_device *dev = priv->ieee80211->dev;
-        writew(y,(u8*)dev->mem_start +x);
+        writew(y, priv->mem_start + x);
        udelay(20);
 }
 
-#endif /* RTL_IO_MAP */
-
 u8 rtl8192e_ap_sec_type(struct ieee80211_device *ieee)
 {
        static const u8 ccmp_ie[4] = {0x00,0x50,0xf2,0x04};
@@ -416,8 +368,7 @@ static int proc_get_stats_ap(char *page, char **start,
                          off_t offset, int count,
                          int *eof, void *data)
 {
-       struct net_device *dev = data;
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
+       struct r8192_priv *priv = data;
        struct ieee80211_device *ieee = priv->ieee80211;
        struct ieee80211_network *target;
        int len = 0;
@@ -446,8 +397,7 @@ static int proc_get_registers(char *page, char **start,
                          off_t offset, int count,
                          int *eof, void *data)
 {
-       struct net_device *dev = data;
-       struct r8192_priv *priv = ieee80211_priv(dev);
+       struct r8192_priv *priv = data;
        int len = 0;
        int i,n;
        int max=0xff;
@@ -499,8 +449,7 @@ static int proc_get_stats_tx(char *page, char **start,
                          off_t offset, int count,
                          int *eof, void *data)
 {
-       struct net_device *dev = data;
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
+       struct r8192_priv *priv = data;
 
        int len = 0;
 
@@ -525,7 +474,7 @@ static int proc_get_stats_tx(char *page, char **start,
                priv->stats.txbeaconokint,
                priv->stats.txbeaconerr,
                priv->stats.txcmdpktokint,
-               netif_queue_stopped(dev),
+               netif_queue_stopped(priv->ieee80211->dev),
                priv->stats.txoverflow,
                priv->ieee80211->stats.tx_packets,
                priv->ieee80211->stats.tx_bytes);
@@ -540,9 +489,7 @@ static int proc_get_stats_rx(char *page, char **start,
                          off_t offset, int count,
                          int *eof, void *data)
 {
-       struct net_device *dev = data;
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
-
+       struct r8192_priv *priv = data;
        int len = 0;
 
        len += snprintf(page + len, count - len,
@@ -559,7 +506,7 @@ static int proc_get_stats_rx(char *page, char **start,
 
 static void rtl8192_proc_module_init(void)
 {
-       RT_TRACE(COMP_INIT, "Initializing proc filesystem");
+       RT_TRACE(COMP_INIT, "Initializing proc filesystem\n");
        rtl8192_proc=create_proc_entry(RTL819xE_MODULE_NAME, S_IFDIR, init_net.proc_net);
 }
 
@@ -570,32 +517,28 @@ static void rtl8192_proc_module_remove(void)
 }
 
 
-static void rtl8192_proc_remove_one(struct net_device *dev)
+static void rtl8192_proc_remove_one(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
+       struct net_device *dev = priv->ieee80211->dev;
 
        printk("dev name=======> %s\n",dev->name);
 
        if (priv->dir_dev) {
-       //      remove_proc_entry("stats-hw", priv->dir_dev);
                remove_proc_entry("stats-tx", priv->dir_dev);
                remove_proc_entry("stats-rx", priv->dir_dev);
-       //      remove_proc_entry("stats-ieee", priv->dir_dev);
                remove_proc_entry("stats-ap", priv->dir_dev);
                remove_proc_entry("registers", priv->dir_dev);
-       //      remove_proc_entry("cck-registers",priv->dir_dev);
-       //      remove_proc_entry("ofdm-registers",priv->dir_dev);
-               //remove_proc_entry(dev->name, rtl8192_proc);
                remove_proc_entry("wlan0", rtl8192_proc);
                priv->dir_dev = NULL;
        }
 }
 
 
-static void rtl8192_proc_init_one(struct net_device *dev)
+static void rtl8192_proc_init_one(struct r8192_priv *priv)
 {
+       struct net_device *dev = priv->ieee80211->dev;
        struct proc_dir_entry *e;
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
+
        priv->dir_dev = create_proc_entry(dev->name,
                                          S_IFDIR | S_IRUGO | S_IXUGO,
                                          rtl8192_proc);
@@ -605,7 +548,7 @@ static void rtl8192_proc_init_one(struct net_device *dev)
                return;
        }
        e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO,
-                                  priv->dir_dev, proc_get_stats_rx, dev);
+                                  priv->dir_dev, proc_get_stats_rx, priv);
 
        if (!e) {
                RT_TRACE(COMP_ERR,"Unable to initialize "
@@ -615,7 +558,7 @@ static void rtl8192_proc_init_one(struct net_device *dev)
 
 
        e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO,
-                                  priv->dir_dev, proc_get_stats_tx, dev);
+                                  priv->dir_dev, proc_get_stats_tx, priv);
 
        if (!e) {
                RT_TRACE(COMP_ERR, "Unable to initialize "
@@ -624,7 +567,7 @@ static void rtl8192_proc_init_one(struct net_device *dev)
        }
 
        e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO,
-                                  priv->dir_dev, proc_get_stats_ap, dev);
+                                  priv->dir_dev, proc_get_stats_ap, priv);
 
        if (!e) {
                RT_TRACE(COMP_ERR, "Unable to initialize "
@@ -633,7 +576,7 @@ static void rtl8192_proc_init_one(struct net_device *dev)
        }
 
        e = create_proc_read_entry("registers", S_IFREG | S_IRUGO,
-                                  priv->dir_dev, proc_get_registers, dev);
+                                  priv->dir_dev, proc_get_registers, priv);
        if (!e) {
                RT_TRACE(COMP_ERR, "Unable to initialize "
                      "/proc/net/rtl8192/%s/registers\n",
@@ -641,7 +584,7 @@ static void rtl8192_proc_init_one(struct net_device *dev)
        }
 }
 
-short check_nic_enough_desc(struct net_device *dev, int prio)
+static short check_nic_enough_desc(struct net_device *dev, int prio)
 {
     struct r8192_priv *priv = ieee80211_priv(dev);
     struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
@@ -660,24 +603,26 @@ static void tx_timeout(struct net_device *dev)
        printk("TXTIMEOUT");
 }
 
-static void rtl8192_irq_enable(struct net_device *dev)
+static void rtl8192_irq_enable(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
-       priv->irq_enabled = 1;
-       write_nic_dword(priv, INTA_MASK, priv->irq_mask);
+       u32 mask;
+
+       mask = IMR_ROK | IMR_VODOK | IMR_VIDOK | IMR_BEDOK | IMR_BKDOK |
+              IMR_HCCADOK | IMR_MGNTDOK | IMR_COMDOK | IMR_HIGHDOK |
+              IMR_BDOK | IMR_RXCMDOK | IMR_TIMEOUT0 | IMR_RDU | IMR_RXFOVW |
+              IMR_TXFOVW | IMR_BcnInt | IMR_TBDOK | IMR_TBDER;
+
+       write_nic_dword(priv, INTA_MASK, mask);
 }
 
-void rtl8192_irq_disable(struct net_device *dev)
+static void rtl8192_irq_disable(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
-
        write_nic_dword(priv, INTA_MASK, 0);
-       priv->irq_enabled = 0;
+       synchronize_irq(priv->irq);
 }
 
-void rtl8192_update_msr(struct net_device *dev)
+static void rtl8192_update_msr(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
        u8 msr;
 
        msr  = read_nic_byte(priv, MSR);
@@ -703,23 +648,21 @@ void rtl8192_update_msr(struct net_device *dev)
        write_nic_byte(priv, MSR, msr);
 }
 
-void rtl8192_set_chan(struct net_device *dev,short ch)
+static void rtl8192_set_chan(struct ieee80211_device *ieee80211, short ch)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
+       struct r8192_priv *priv = ieee80211_priv(ieee80211->dev);
 
        priv->chan = ch;
 
        /* need to implement rf set channel here WB */
 
        if (priv->rf_set_chan)
-               priv->rf_set_chan(dev, priv->chan);
+               priv->rf_set_chan(ieee80211, priv->chan);
 }
 
-void rtl8192_rx_enable(struct net_device *dev)
+static void rtl8192_rx_enable(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
-
-       write_nic_dword(priv, RDQDA,priv->rx_ring_dma);
+       write_nic_dword(priv, RDQDA, priv->rx_ring_dma);
 }
 
 /* the TX_DESC_BASE setting is according to the following queue index
@@ -734,9 +677,8 @@ void rtl8192_rx_enable(struct net_device *dev)
  *  BEACON_QUEUE   ===>                        8
  *  */
 static const u32 TX_DESC_BASE[] = {BKQDA, BEQDA, VIQDA, VOQDA, HCCAQDA, CQDA, MQDA, HQDA, BQDA};
-void rtl8192_tx_enable(struct net_device *dev)
+static void rtl8192_tx_enable(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        u32 i;
 
        for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
@@ -746,9 +688,8 @@ void rtl8192_tx_enable(struct net_device *dev)
 }
 
 
-static void rtl8192_free_rx_ring(struct net_device *dev)
+static void rtl8192_free_rx_ring(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
        int i;
 
        for (i = 0; i < priv->rxringcount; i++) {
@@ -767,9 +708,8 @@ static void rtl8192_free_rx_ring(struct net_device *dev)
        priv->rx_ring = NULL;
 }
 
-static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
+static void rtl8192_free_tx_ring(struct r8192_priv *priv, unsigned int prio)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
        struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
 
        while (skb_queue_len(&ring->queue)) {
@@ -787,31 +727,28 @@ static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio)
        ring->desc = NULL;
 }
 
-void PHY_SetRtl8192eRfOff(struct net_device* dev)
+void PHY_SetRtl8192eRfOff(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
-
        //disable RF-Chip A/B
-       rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4, 0x0);
+       rtl8192_setBBreg(priv, rFPGA0_XA_RFInterfaceOE, BIT4, 0x0);
        //analog to digital off, for power save
-       rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x0);
+       rtl8192_setBBreg(priv, rFPGA0_AnalogParameter4, 0x300, 0x0);
        //digital to analog off, for power save
-       rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18, 0x0);
+       rtl8192_setBBreg(priv, rFPGA0_AnalogParameter1, 0x18, 0x0);
        //rx antenna off
-       rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0x0);
+       rtl8192_setBBreg(priv, rOFDM0_TRxPathEnable, 0xf, 0x0);
        //rx antenna off
-       rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0);
+       rtl8192_setBBreg(priv, rOFDM1_TRxPathEnable, 0xf, 0x0);
        //analog to digital part2 off, for power save
-       rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60, 0x0);
-       rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x4, 0x0);
+       rtl8192_setBBreg(priv, rFPGA0_AnalogParameter1, 0x60, 0x0);
+       rtl8192_setBBreg(priv, rFPGA0_AnalogParameter1, 0x4, 0x0);
        // Analog parameter!!Change bias and Lbus control.
        write_nic_byte(priv, ANAPAR_FOR_8192PciE, 0x07);
-
 }
 
-void rtl8192_halt_adapter(struct net_device *dev, bool reset)
+static void rtl8192_halt_adapter(struct r8192_priv *priv, bool reset)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
+       struct net_device *dev = priv->ieee80211->dev;
        int i;
        u8 OpMode;
        u32 ulRegRead;
@@ -839,7 +776,7 @@ void rtl8192_halt_adapter(struct net_device *dev, bool reset)
                 * prevent RF config race condition.
                 */
                if (!priv->ieee80211->bSupportRemoteWakeUp) {
-                       PHY_SetRtl8192eRfOff(dev);
+                       PHY_SetRtl8192eRfOff(priv);
                        ulRegRead = read_nic_dword(priv, CPU_GEN);
                        ulRegRead |= CPU_GEN_SYSTEM_RESET;
                        write_nic_dword(priv,CPU_GEN, ulRegRead);
@@ -866,18 +803,11 @@ void rtl8192_halt_adapter(struct net_device *dev, bool reset)
        skb_queue_purge(&priv->skb_queue);
 }
 
-static const u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540};
-inline u16 rtl8192_rate2rate(short rate)
-{
-       if (rate >11) return 0;
-       return rtl_rate[rate];
-}
-
-static void rtl8192_data_hard_stop(struct net_device *dev)
+static void rtl8192_data_hard_stop(struct ieee80211_device *ieee80211)
 {
 }
 
-static void rtl8192_data_hard_resume(struct net_device *dev)
+static void rtl8192_data_hard_resume(struct ieee80211_device *ieee80211)
 {
 }
 
@@ -885,9 +815,10 @@ static void rtl8192_data_hard_resume(struct net_device *dev)
  * this function TX data frames when the ieee80211 stack requires this.
  * It checks also if we need to stop the ieee tx queue, eventually do it
  */
-static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate)
+static void rtl8192_hard_data_xmit(struct sk_buff *skb,
+                                  struct ieee80211_device *ieee80211, int rate)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
+       struct r8192_priv *priv = ieee80211_priv(ieee80211->dev);
        int ret;
        cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
        u8 queue_index = tcb_desc->queue_index;
@@ -901,10 +832,10 @@ static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
                return;
        }
 
-       memcpy(skb->cb, &dev, sizeof(dev));
+       memcpy(skb->cb, &ieee80211->dev, sizeof(ieee80211->dev));
 
        skb_push(skb, priv->ieee80211->tx_headroom);
-       ret = rtl8192_tx(dev, skb);
+       ret = rtl8192_tx(priv, skb);
        if (ret != 0) {
                kfree_skb(skb);
        }
@@ -921,9 +852,9 @@ static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev,
  * If the ring is full packet are dropped (for data frame the queue
  * is stopped before this can happen).
  */
-static int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
+static int rtl8192_hard_start_xmit(struct sk_buff *skb, struct ieee80211_device *ieee80211)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
+       struct r8192_priv *priv = ieee80211_priv(ieee80211->dev);
        int ret;
         cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
         u8 queue_index = tcb_desc->queue_index;
@@ -936,9 +867,9 @@ static int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
                }
         }
 
-        memcpy(skb->cb, &dev, sizeof(dev));
+        memcpy(skb->cb, &ieee80211->dev, sizeof(ieee80211->dev));
        if (queue_index == TXCMD_QUEUE) {
-               rtl819xE_tx_cmd(dev, skb);
+               rtl819xE_tx_cmd(priv, skb);
                ret = 0;
                return ret;
        } else {
@@ -946,8 +877,8 @@ static int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
                tcb_desc->bTxDisableRateFallBack = 1;
                tcb_desc->bTxUseDriverAssingedRate = 1;
                tcb_desc->bTxEnableFwCalcDur = 1;
-               skb_push(skb, priv->ieee80211->tx_headroom);
-               ret = rtl8192_tx(dev, skb);
+               skb_push(skb, ieee80211->tx_headroom);
+               ret = rtl8192_tx(priv, skb);
                if (ret != 0) {
                        kfree_skb(skb);
                }
@@ -957,9 +888,8 @@ static int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev)
 }
 
 
-static void rtl8192_tx_isr(struct net_device *dev, int prio)
+static void rtl8192_tx_isr(struct r8192_priv *priv, int prio)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct rtl8192_tx_ring *ring = &priv->tx_ring[prio];
 
        while (skb_queue_len(&ring->queue)) {
@@ -989,13 +919,12 @@ static void rtl8192_tx_isr(struct net_device *dev, int prio)
        }
 }
 
-static void rtl8192_stop_beacon(struct net_device *dev)
+static void rtl8192_stop_beacon(struct ieee80211_device *ieee80211)
 {
 }
 
-static void rtl8192_config_rate(struct net_device* dev, u16* rate_config)
+static void rtl8192_config_rate(struct r8192_priv *priv, u16* rate_config)
 {
-        struct r8192_priv *priv = ieee80211_priv(dev);
         struct ieee80211_network *net;
         u8 i=0, basic_rate = 0;
         net = & priv->ieee80211->current_network;
@@ -1044,11 +973,11 @@ static void rtl8192_config_rate(struct net_device* dev, u16* rate_config)
 #define SHORT_SLOT_TIME 9
 #define NON_SHORT_SLOT_TIME 20
 
-static void rtl8192_update_cap(struct net_device* dev, u16 cap)
+static void rtl8192_update_cap(struct r8192_priv *priv, u16 cap)
 {
        u32 tmp = 0;
-       struct r8192_priv *priv = ieee80211_priv(dev);
        struct ieee80211_network *net = &priv->ieee80211->current_network;
+
        priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE;
        tmp = priv->basic_rate;
        if (priv->short_preamble)
@@ -1070,16 +999,15 @@ static void rtl8192_update_cap(struct net_device* dev, u16 cap)
 
 }
 
-static void rtl8192_net_update(struct net_device *dev)
+static void rtl8192_net_update(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
        struct ieee80211_network *net;
        u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf;
        u16 rate_config = 0;
        net = &priv->ieee80211->current_network;
 
        /* update Basic rate: RR, BRSR */
-       rtl8192_config_rate(dev, &rate_config);
+       rtl8192_config_rate(priv, &rate_config);
 
        /*
         * Select RRSR (in Legacy-OFDM and CCK)
@@ -1112,9 +1040,8 @@ static void rtl8192_net_update(struct net_device *dev)
        }
 }
 
-void rtl819xE_tx_cmd(struct net_device *dev, struct sk_buff *skb)
+static void rtl819xE_tx_cmd(struct r8192_priv *priv, struct sk_buff *skb)
 {
-    struct r8192_priv *priv = ieee80211_priv(dev);
     struct rtl8192_tx_ring *ring;
     tx_desc_819x_pci *entry;
     unsigned int idx;
@@ -1261,9 +1188,8 @@ static u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc)
  * skb->cb will contain all the following information,
  * priority, morefrag, rate, &dev.
  */
-short rtl8192_tx(struct net_device *dev, struct sk_buff* skb)
+static short rtl8192_tx(struct r8192_priv *priv, struct sk_buff* skb)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
        struct rtl8192_tx_ring *ring;
        unsigned long flags;
        cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
@@ -1351,7 +1277,7 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff* skb)
 
        pdesc = &ring->desc[idx];
        if ((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) {
-               RT_TRACE(COMP_ERR, "No more TX desc@%d, ring->idx = %d,idx = %d,%x",
+               RT_TRACE(COMP_ERR, "No more TX desc@%d, ring->idx = %d,idx = %d,%x\n",
                         tcb_desc->queue_index, ring->idx, idx, skb->len);
                spin_unlock_irqrestore(&priv->irq_th_lock, flags);
                return skb->len;
@@ -1411,14 +1337,13 @@ short rtl8192_tx(struct net_device *dev, struct sk_buff* skb)
        __skb_queue_tail(&ring->queue, skb);
        pdesc->OWN = 1;
        spin_unlock_irqrestore(&priv->irq_th_lock, flags);
-       dev->trans_start = jiffies;
+       priv->ieee80211->dev->trans_start = jiffies;
        write_nic_word(priv, TPPoll, 0x01<<tcb_desc->queue_index);
        return 0;
 }
 
-static short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
+static short rtl8192_alloc_rx_desc_ring(struct r8192_priv *priv)
 {
-    struct r8192_priv *priv = ieee80211_priv(dev);
     rx_desc_819x_pci *entry = NULL;
     int i;
 
@@ -1454,10 +1379,9 @@ static short rtl8192_alloc_rx_desc_ring(struct net_device *dev)
     return 0;
 }
 
-static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
+static int rtl8192_alloc_tx_desc_ring(struct r8192_priv *priv,
         unsigned int prio, unsigned int entries)
 {
-    struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
     tx_desc_819x_pci *ring;
     dma_addr_t dma;
     int i;
@@ -1482,19 +1406,18 @@ static int rtl8192_alloc_tx_desc_ring(struct net_device *dev,
     return 0;
 }
 
-static short rtl8192_pci_initdescring(struct net_device *dev)
+static short rtl8192_pci_initdescring(struct r8192_priv *priv)
 {
        u32 ret;
        int i;
-       struct r8192_priv *priv = ieee80211_priv(dev);
 
-       ret = rtl8192_alloc_rx_desc_ring(dev);
+       ret = rtl8192_alloc_rx_desc_ring(priv);
        if (ret)
                return ret;
 
        /* general process for other queue */
        for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) {
-               ret = rtl8192_alloc_tx_desc_ring(dev, i, priv->txringcount);
+               ret = rtl8192_alloc_tx_desc_ring(priv, i, priv->txringcount);
                if (ret)
                        goto err_free_rings;
        }
@@ -1502,16 +1425,15 @@ static short rtl8192_pci_initdescring(struct net_device *dev)
        return 0;
 
 err_free_rings:
-       rtl8192_free_rx_ring(dev);
+       rtl8192_free_rx_ring(priv);
        for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
                if (priv->tx_ring[i].desc)
-                       rtl8192_free_tx_ring(dev, i);
+                       rtl8192_free_tx_ring(priv, i);
        return 1;
 }
 
-static void rtl8192_pci_resetdescring(struct net_device *dev)
+static void rtl8192_pci_resetdescring(struct r8192_priv *priv)
 {
-    struct r8192_priv *priv = ieee80211_priv(dev);
     int i;
 
     /* force the rx_idx to the first one */
@@ -1548,24 +1470,22 @@ static void rtl8192_link_change(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
        struct ieee80211_device* ieee = priv->ieee80211;
-       //write_nic_word(priv, BCN_INTR_ITV, net->beacon_interval);
+
        if (ieee->state == IEEE80211_LINKED)
        {
-               rtl8192_net_update(dev);
-               rtl8192_update_ratr_table(dev);
+               rtl8192_net_update(priv);
+               rtl8192_update_ratr_table(priv);
 
                //add this as in pure N mode, wep encryption will use software way, but there is no chance to set this as wep will not set group key in wext. WB.2008.07.08
                if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type))
-               EnableHWSecurityConfig8192(dev);
+               EnableHWSecurityConfig8192(priv);
        }
        else
        {
                write_nic_byte(priv, 0x173, 0);
        }
-       /*update timing params*/
-       //rtl8192_set_chan(dev, priv->chan);
-       //MSR
-       rtl8192_update_msr(dev);
+
+       rtl8192_update_msr(priv);
 
        // 2007/10/16 MH MAC Will update TSF according to all received beacon, so we have
        //      // To set CBSSID bit when link with any AP or STA.
@@ -1593,14 +1513,13 @@ static const struct ieee80211_qos_parameters def_qos_parameters = {
 static void rtl8192_update_beacon(struct work_struct * work)
 {
         struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work);
-        struct net_device *dev = priv->ieee80211->dev;
        struct ieee80211_device* ieee = priv->ieee80211;
        struct ieee80211_network* net = &ieee->current_network;
 
        if (ieee->pHTInfo->bCurrentHTSupport)
                HTUpdateSelfAndPeerSetting(ieee, net);
        ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime;
-       rtl8192_update_cap(dev, net->capability);
+       rtl8192_update_cap(priv, net->capability);
 }
 
 /*
@@ -1631,7 +1550,6 @@ static void rtl8192_qos_activate(struct work_struct * work)
                                (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)|
                                ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET));
                write_nic_dword(priv, WDCAPARA_ADD[i], u4bAcParam);
-               //write_nic_dword(priv, WDCAPARA_ADD[i], 0x005e4332);
        }
 
 success:
@@ -1672,7 +1590,7 @@ static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv,
 
                if ((network->qos_data.active == 1) && (active_network == 1)) {
                        queue_work(priv->priv_wq, &priv->qos_activate);
-                       RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate \n");
+                       RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate\n");
                }
                network->qos_data.active = 0;
                network->qos_data.supported = 0;
@@ -1759,15 +1677,14 @@ static int rtl8192_handle_assoc_response(struct net_device *dev,
 
 
 /* updateRATRTabel for MCS only. Basic rate is not implemented. */
-static void rtl8192_update_ratr_table(struct net_device* dev)
+static void rtl8192_update_ratr_table(struct r8192_priv* priv)
 {
-       struct r8192_priv* priv = ieee80211_priv(dev);
        struct ieee80211_device* ieee = priv->ieee80211;
        u8* pMcsRate = ieee->dot11HTOperationalRateSet;
        u32 ratr_value = 0;
        u8 rate_index = 0;
 
-       rtl8192_config_rate(dev, (u16*)(&ratr_value));
+       rtl8192_config_rate(priv, (u16*)(&ratr_value));
        ratr_value |= (*(u16*)(pMcsRate)) << 12;
 
        switch (ieee->mode)
@@ -1826,7 +1743,7 @@ static void rtl8192_refresh_supportrate(struct r8192_priv* priv)
                memset(ieee->Regdot11HTOperationalRateSet, 0, 16);
 }
 
-static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
+static u8 rtl8192_getSupportedWireleeMode(void)
 {
        return (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B);
 }
@@ -1834,7 +1751,7 @@ static u8 rtl8192_getSupportedWireleeMode(struct net_device *dev)
 static void rtl8192_SetWirelessMode(struct net_device* dev, u8 wireless_mode)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
-       u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev);
+       u8 bSupportMode = rtl8192_getSupportedWireleeMode();
 
        if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode)==0))
        {
@@ -1881,7 +1798,7 @@ static bool GetHalfNmodeSupportByAPs819xPci(struct net_device* dev)
        return ieee->bHalfWirelessN24GMode;
 }
 
-short rtl8192_is_tx_queue_empty(struct net_device *dev)
+static short rtl8192_is_tx_queue_empty(struct net_device *dev)
 {
        int i=0;
        struct r8192_priv *priv = ieee80211_priv(dev);
@@ -1897,51 +1814,18 @@ short rtl8192_is_tx_queue_empty(struct net_device *dev)
        return 1;
 }
 
-static void rtl8192_hw_sleep_down(struct net_device *dev)
+static void rtl8192_hw_sleep_down(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
-       unsigned long flags = 0;
-
-       spin_lock_irqsave(&priv->rf_ps_lock,flags);
-       if (priv->RFChangeInProgress) {
-               spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
-               RT_TRACE(COMP_RF, "rtl8192_hw_sleep_down(): RF Change in progress! \n");
-               printk("rtl8192_hw_sleep_down(): RF Change in progress!\n");
-               return;
-       }
-       spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
-
-       MgntActSet_RF_State(dev, eRfSleep, RF_CHANGE_BY_PS);
-}
-
-static void rtl8192_hw_sleep_wq (struct work_struct *work)
-{
-        struct delayed_work *dwork = container_of(work,struct delayed_work,work);
-        struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq);
-        struct net_device *dev = ieee->dev;
-
-        rtl8192_hw_sleep_down(dev);
+       MgntActSet_RF_State(priv, eRfSleep, RF_CHANGE_BY_PS);
 }
 
 static void rtl8192_hw_wakeup(struct net_device* dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
-       unsigned long flags = 0;
-
-       spin_lock_irqsave(&priv->rf_ps_lock,flags);
-       if (priv->RFChangeInProgress) {
-               spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
-               RT_TRACE(COMP_RF, "rtl8192_hw_wakeup(): RF Change in progress! \n");
-               printk("rtl8192_hw_wakeup(): RF Change in progress! schedule wake up task again\n");
-               queue_delayed_work(priv->ieee80211->wq,&priv->ieee80211->hw_wakeup_wq,MSECS(10));//PowerSave is not supported if kernel version is below 2.6.20
-               return;
-       }
-       spin_unlock_irqrestore(&priv->rf_ps_lock,flags);
-
-       MgntActSet_RF_State(dev, eRfOn, RF_CHANGE_BY_PS);
+       MgntActSet_RF_State(priv, eRfOn, RF_CHANGE_BY_PS);
 }
 
-void rtl8192_hw_wakeup_wq (struct work_struct *work)
+static void rtl8192_hw_wakeup_wq (struct work_struct *work)
 {
        struct delayed_work *dwork = container_of(work,struct delayed_work,work);
        struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq);
@@ -1958,8 +1842,6 @@ static void rtl8192_hw_to_sleep(struct net_device *dev, u32 th, u32 tl)
        u32 tmp;
        u32 rb = jiffies;
 
-       spin_lock(&priv->ps_lock);
-
        // Writing HW register with 0 equals to disable
        // the timer, that is not really what we want
        //
@@ -1972,31 +1854,27 @@ static void rtl8192_hw_to_sleep(struct net_device *dev, u32 th, u32 tl)
        if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME))
                        ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) {
                printk("too short to sleep::%x, %x, %lx\n",tl, rb,  MSECS(MIN_SLEEP_TIME));
-               goto out_unlock;
+               return;
        }
 
        if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))||
                        ((tl < rb) && (tl>MSECS(69)) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))||
                        ((tl<rb)&&(tl<MSECS(69))&&((tl+0xffffffff-rb)>MSECS(MAX_SLEEP_TIME)))) {
                printk("========>too long to sleep:%x, %x, %lx\n", tl, rb,  MSECS(MAX_SLEEP_TIME));
-               goto out_unlock;
+               return;
        }
 
        tmp = (tl>rb)?(tl-rb):(rb-tl);
        queue_delayed_work(priv->ieee80211->wq,
                           &priv->ieee80211->hw_wakeup_wq,tmp);
 
-       queue_delayed_work(priv->ieee80211->wq,
-                       (void *)&priv->ieee80211->hw_sleep_wq,0);
-out_unlock:
-       spin_unlock(&priv->ps_lock);
+        rtl8192_hw_sleep_down(priv);
 }
 
-static void rtl8192_init_priv_variable(struct net_device* dev)
+static void rtl8192_init_priv_variable(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
        u8 i;
-       PRT_POWER_SAVE_CONTROL  pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
+       PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl;
 
        // Default Halt the NIC if RF is OFF.
        pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_HALT_NIC;
@@ -2004,15 +1882,13 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
        pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_ASPM;
        pPSC->RegRfPsLevel |= RT_RF_LPS_LEVEL_ASPM;
        pPSC->bLeisurePs = true;
-       pPSC->RegMaxLPSAwakeIntvl = 5;
+       priv->ieee80211->RegMaxLPSAwakeIntvl = 5;
        priv->bHwRadioOff = false;
 
        priv->being_init_adapter = false;
        priv->txringcount = 64;//32;
        priv->rxbuffersize = 9100;//2048;//1024;
        priv->rxringcount = MAX_RX_COUNT;//64;
-       priv->irq_enabled=0;
-       priv->rx_skb_complete = 1;
        priv->chan = 1; //set to channel 1
        priv->RegWirelessMode = WIRELESS_MODE_AUTO;
        priv->RegChannelPlan = 0xf;
@@ -2024,7 +1900,7 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
        priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD;
        priv->ieee80211->rate = 110; //11 mbps
        priv->ieee80211->short_slot = 1;
-       priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0;
+       priv->promisc = (priv->ieee80211->dev->flags & IFF_PROMISC) ? 1:0;
        priv->bcck_in_ch14 = false;
        priv->CCKPresentAttentuation = 0;
        priv->rfa_txpowertrackingindex = 0;
@@ -2036,12 +1912,10 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
        priv->bDisableNormalResetCheck = false;
        priv->force_reset = false;
        //added by amy for power save
-       priv->ieee80211->RfOffReason = 0;
-       priv->RFChangeInProgress = false;
+       priv->RfOffReason = 0;
        priv->bHwRfOffAction = 0;
-       priv->SetRFPowerStateInProgress = false;
-       priv->ieee80211->PowerSaveControl.bInactivePs = true;
-       priv->ieee80211->PowerSaveControl.bIPSModeBackup = false;
+       priv->PowerSaveControl.bInactivePs = true;
+       priv->PowerSaveControl.bIPSModeBackup = false;
 
        priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL;
        priv->ieee80211->iw_mode = IW_MODE_INFRA;
@@ -2054,10 +1928,8 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
        priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION;
        priv->ieee80211->host_encrypt = 1;
        priv->ieee80211->host_decrypt = 1;
-       //priv->ieee80211->start_send_beacons = NULL;//rtl819xusb_beacon_tx;//-by amy 080604
-       //priv->ieee80211->stop_send_beacons = NULL;//rtl8192_beacon_stop;//-by amy 080604
-       priv->ieee80211->start_send_beacons = rtl8192_start_beacon;//+by david 081107
-       priv->ieee80211->stop_send_beacons = rtl8192_stop_beacon;//+by david 081107
+       priv->ieee80211->start_send_beacons = rtl8192_start_beacon;
+       priv->ieee80211->stop_send_beacons = rtl8192_stop_beacon;
        priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit;
        priv->ieee80211->set_chan = rtl8192_set_chan;
        priv->ieee80211->link_change = rtl8192_link_change;
@@ -2069,23 +1941,17 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
        priv->ieee80211->check_nic_enough_desc = check_nic_enough_desc;
        priv->ieee80211->tx_headroom = sizeof(TX_FWINFO_8190PCI);
        priv->ieee80211->qos_support = 1;
-       priv->ieee80211->dot11PowerSaveMode = 0;
-       //added by WB
-//     priv->ieee80211->SwChnlByTimerHandler = rtl8192_phy_SwChnl;
        priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode;
        priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response;
        priv->ieee80211->handle_beacon = rtl8192_handle_beacon;
 
        priv->ieee80211->sta_wake_up = rtl8192_hw_wakeup;
-//     priv->ieee80211->ps_request_tx_ack = rtl8192_rq_tx_ack;
        priv->ieee80211->enter_sleep_state = rtl8192_hw_to_sleep;
        priv->ieee80211->ps_is_queue_empty = rtl8192_is_tx_queue_empty;
-       //added by david
        priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8190Pci;
        priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode;
        priv->ieee80211->GetHalfNmodeSupportByAPsHandler = GetHalfNmodeSupportByAPs819xPci;
 
-       //added by amy
        priv->ieee80211->InitialGainHandler = InitialGain819xPci;
 
 #ifdef ENABLE_IPS
@@ -2109,11 +1975,6 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
                RCR_AAP | ((u32)7<<RCR_MXDMA_OFFSET) |
                ((u32)7 << RCR_FIFO_OFFSET) | RCR_ONLYERLPKT;
 
-       priv->irq_mask =        (u32)(IMR_ROK | IMR_VODOK | IMR_VIDOK | IMR_BEDOK | IMR_BKDOK |
-                               IMR_HCCADOK | IMR_MGNTDOK | IMR_COMDOK | IMR_HIGHDOK |
-                               IMR_BDOK | IMR_RXCMDOK | IMR_TIMEOUT0 | IMR_RDU | IMR_RXFOVW |
-                               IMR_TXFOVW | IMR_BcnInt | IMR_TBDOK | IMR_TBDER);
-
        priv->pFirmware = vzalloc(sizeof(rt_firmware));
 
        /* rx related queue */
@@ -2131,10 +1992,8 @@ static void rtl8192_init_priv_variable(struct net_device* dev)
 
 static void rtl8192_init_priv_lock(struct r8192_priv* priv)
 {
-       spin_lock_init(&priv->tx_lock);
        spin_lock_init(&priv->irq_th_lock);
        spin_lock_init(&priv->rf_ps_lock);
-       spin_lock_init(&priv->ps_lock);
        sema_init(&priv->wx_sem,1);
        sema_init(&priv->rf_sem,1);
        mutex_init(&priv->mutex);
@@ -2142,28 +2001,21 @@ static void rtl8192_init_priv_lock(struct r8192_priv* priv)
 
 /* init tasklet and wait_queue here */
 #define DRV_NAME "wlan0"
-static void rtl8192_init_priv_task(struct net_device* dev)
+static void rtl8192_init_priv_task(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
-
        priv->priv_wq = create_workqueue(DRV_NAME);
 
 #ifdef ENABLE_IPS
        INIT_WORK(&priv->ieee80211->ips_leave_wq, IPSLeave_wq);
 #endif
 
-//     INIT_WORK(&priv->reset_wq, (void(*)(void*)) rtl8192_restart);
        INIT_WORK(&priv->reset_wq,  rtl8192_restart);
-//     INIT_DELAYED_WORK(&priv->watch_dog_wq, hal_dm_watchdog);
        INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback);
        INIT_DELAYED_WORK(&priv->txpower_tracking_wq,  dm_txpower_trackingcallback);
        INIT_DELAYED_WORK(&priv->rfpath_check_wq,  dm_rf_pathcheck_workitemcallback);
        INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon);
-       //INIT_WORK(&priv->SwChnlWorkItem,  rtl8192_SwChnl_WorkItem);
-       //INIT_WORK(&priv->SetBWModeWorkItem,  rtl8192_SetBWModeWorkItem);
        INIT_WORK(&priv->qos_activate, rtl8192_qos_activate);
        INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq, rtl8192_hw_wakeup_wq);
-       INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq, rtl8192_hw_sleep_wq);
 
        tasklet_init(&priv->irq_rx_tasklet, rtl8192_irq_rx_tasklet,
                     (unsigned long) priv);
@@ -2173,10 +2025,9 @@ static void rtl8192_init_priv_task(struct net_device* dev)
                     (unsigned long) priv);
 }
 
-static void rtl8192_get_eeprom_size(struct net_device* dev)
+static void rtl8192_get_eeprom_size(struct r8192_priv *priv)
 {
        u16 curCR = 0;
-       struct r8192_priv *priv = ieee80211_priv(dev);
        RT_TRACE(COMP_INIT, "===========>%s()\n", __FUNCTION__);
        curCR = read_nic_dword(priv, EPROM_CMD);
        RT_TRACE(COMP_INIT, "read from Reg Cmd9346CR(%x):%x\n", EPROM_CMD, curCR);
@@ -2203,7 +2054,7 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
        // TODO: I don't know if we need to apply EF function to EEPROM read function
 
        //2 Read EEPROM ID to make sure autoload is success
-       EEPROMId = eprom_read(dev, 0);
+       EEPROMId = eprom_read(priv, 0);
        if( EEPROMId != RTL8190_EEPROM_ID )
        {
                RT_TRACE(COMP_ERR, "EEPROM ID is invalid:%x, %x\n", EEPROMId, RTL8190_EEPROM_ID);
@@ -2221,19 +2072,19 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
        if(!priv->AutoloadFailFlag)
        {
                // VID, PID
-               priv->eeprom_vid = eprom_read(dev, (EEPROM_VID >> 1));
-               priv->eeprom_did = eprom_read(dev, (EEPROM_DID >> 1));
+               priv->eeprom_vid = eprom_read(priv, (EEPROM_VID >> 1));
+               priv->eeprom_did = eprom_read(priv, (EEPROM_DID >> 1));
 
-               usValue = eprom_read(dev, (u16)(EEPROM_Customer_ID>>1)) >> 8 ;
+               usValue = eprom_read(priv, (u16)(EEPROM_Customer_ID>>1)) >> 8 ;
                priv->eeprom_CustomerID = (u8)( usValue & 0xff);
-               usValue = eprom_read(dev, (EEPROM_ICVersion_ChannelPlan>>1));
+               usValue = eprom_read(priv, (EEPROM_ICVersion_ChannelPlan>>1));
                priv->eeprom_ChannelPlan = usValue&0xff;
                IC_Version = ((usValue&0xff00)>>8);
 
                ICVer8192 = (IC_Version&0xf);           //bit0~3; 1:A cut, 2:B cut, 3:C cut...
                ICVer8256 = ((IC_Version&0xf0)>>4);//bit4~6, bit7 reserved for other RF chip; 1:A cut, 2:B cut, 3:C cut...
-               RT_TRACE(COMP_INIT, "\nICVer8192 = 0x%x\n", ICVer8192);
-               RT_TRACE(COMP_INIT, "\nICVer8256 = 0x%x\n", ICVer8256);
+               RT_TRACE(COMP_INIT, "ICVer8192 = 0x%x\n", ICVer8192);
+               RT_TRACE(COMP_INIT, "ICVer8256 = 0x%x\n", ICVer8256);
                if(ICVer8192 == 0x2)    //B-cut
                {
                        if(ICVer8256 == 0x5) //E-cut
@@ -2258,7 +2109,7 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
                priv->eeprom_did = 0;
                priv->eeprom_CustomerID = 0;
                priv->eeprom_ChannelPlan = 0;
-               RT_TRACE(COMP_INIT, "\nIC Version = 0x%x\n", 0xff);
+               RT_TRACE(COMP_INIT, "IC Version = 0x%x\n", 0xff);
        }
 
        RT_TRACE(COMP_INIT, "EEPROM VID = 0x%4x\n", priv->eeprom_vid);
@@ -2270,7 +2121,7 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
        {
                for(i = 0; i < 6; i += 2)
                {
-                       usValue = eprom_read(dev, (u16) ((EEPROM_NODE_ADDRESS_BYTE_0+i)>>1));
+                       usValue = eprom_read(priv, (u16) ((EEPROM_NODE_ADDRESS_BYTE_0+i)>>1));
                        *(u16*)(&dev->dev_addr[i]) = usValue;
                }
        } else {
@@ -2296,7 +2147,7 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
                // Read RF-indication and Tx Power gain index diff of legacy to HT OFDM rate.
                if(!priv->AutoloadFailFlag)
                {
-                       tempval = (eprom_read(dev, (EEPROM_RFInd_PowerDiff>>1))) & 0xff;
+                       tempval = (eprom_read(priv, (EEPROM_RFInd_PowerDiff>>1))) & 0xff;
                        priv->EEPROMLegacyHTTxPowerDiff = tempval & 0xf;        // bit[3:0]
 
                        if (tempval&0x80)       //RF-indication, bit[7]
@@ -2314,7 +2165,7 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
                // Read ThermalMeter from EEPROM
                if(!priv->AutoloadFailFlag)
                {
-                       priv->EEPROMThermalMeter = (u8)(((eprom_read(dev, (EEPROM_ThermalMeter>>1))) & 0xff00)>>8);
+                       priv->EEPROMThermalMeter = (u8)(((eprom_read(priv, (EEPROM_ThermalMeter>>1))) & 0xff00)>>8);
                }
                else
                {
@@ -2329,7 +2180,7 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
                // Read antenna tx power offset of B/C/D to A and CrystalCap from EEPROM
                if(!priv->AutoloadFailFlag)
                {
-                               usValue = eprom_read(dev, (EEPROM_TxPwDiff_CrystalCap>>1));
+                               usValue = eprom_read(priv, (EEPROM_TxPwDiff_CrystalCap>>1));
                                priv->EEPROMAntPwDiff = (usValue&0x0fff);
                                priv->EEPROMCrystalCap = (u8)((usValue&0xf000)>>12);
                }
@@ -2348,7 +2199,7 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
                {
                        if(!priv->AutoloadFailFlag)
                        {
-                               usValue = eprom_read(dev, (u16) ((EEPROM_TxPwIndex_CCK+i)>>1) );
+                               usValue = eprom_read(priv, (u16) ((EEPROM_TxPwIndex_CCK+i)>>1) );
                        }
                        else
                        {
@@ -2362,7 +2213,7 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
                {
                        if(!priv->AutoloadFailFlag)
                        {
-                               usValue = eprom_read(dev, (u16) ((EEPROM_TxPwIndex_OFDM_24G+i)>>1) );
+                               usValue = eprom_read(priv, (u16) ((EEPROM_TxPwIndex_OFDM_24G+i)>>1) );
                        }
                        else
                        {
@@ -2399,10 +2250,6 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
                }
                else if(priv->epromtype == EPROM_93c56)
                {
-                       //char  cck_pwr_diff_a=0, cck_pwr_diff_c=0;
-
-                       //cck_pwr_diff_a = pHalData->EEPROMRfACCKChnl7TxPwLevel - pHalData->EEPROMRfAOfdmChnlTxPwLevel[1];
-                       //cck_pwr_diff_c = pHalData->EEPROMRfCCCKChnl7TxPwLevel - pHalData->EEPROMRfCOfdmChnlTxPwLevel[1];
                        for(i=0; i<3; i++)      // channel 1~3 use the same Tx Power Level.
                        {
                                priv->TxPowerLevelCCK_A[i]  = priv->EEPROMRfACCKChnl1TxPwLevel[0];
@@ -2445,11 +2292,11 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
 
        if(priv->rf_type == RF_1T2R)
        {
-               RT_TRACE(COMP_INIT, "\n1T2R config\n");
+               RT_TRACE(COMP_INIT, "1T2R config\n");
        }
        else if (priv->rf_type == RF_2T4R)
        {
-               RT_TRACE(COMP_INIT, "\n2T4R config\n");
+               RT_TRACE(COMP_INIT, "2T4R config\n");
        }
 
        // 2008/01/16 MH We can only know RF type in the function. So we have to init
@@ -2509,15 +2356,6 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
                        break;
 
                case EEPROM_CID_WHQL:
-                       //Adapter->bInHctTest = TRUE;//do not supported
-
-                       //priv->bSupportTurboMode = FALSE;
-                       //priv->bAutoTurboBy8186 = FALSE;
-
-                       //pMgntInfo->PowerSaveControl.bInactivePs = FALSE;
-                       //pMgntInfo->PowerSaveControl.bIPSModeBackup = FALSE;
-                       //pMgntInfo->PowerSaveControl.bLeisurePs = FALSE;
-
                        break;
                default:
                        // value from RegCustomerID
@@ -2528,42 +2366,6 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
        if(priv->ChannelPlan > CHANNEL_PLAN_LEN - 1)
                priv->ChannelPlan = 0; //FCC
 
-       switch(priv->CustomerID)
-       {
-               case RT_CID_DEFAULT:
-                       priv->LedStrategy = SW_LED_MODE1;
-                       break;
-
-               case RT_CID_819x_CAMEO:
-                       priv->LedStrategy = SW_LED_MODE2;
-                       break;
-
-               case RT_CID_819x_RUNTOP:
-                       priv->LedStrategy = SW_LED_MODE3;
-                       break;
-
-               case RT_CID_819x_Netcore:
-                       priv->LedStrategy = SW_LED_MODE4;
-                       break;
-
-               case RT_CID_Nettronix:
-                       priv->LedStrategy = SW_LED_MODE5;
-                       break;
-
-               case RT_CID_PRONET:
-                       priv->LedStrategy = SW_LED_MODE6;
-                       break;
-
-               case RT_CID_TOSHIBA:   //Modify by Jacken 2008/01/31
-                       // Do nothing.
-                       //break;
-
-               default:
-                       priv->LedStrategy = SW_LED_MODE1;
-                       break;
-       }
-
-
        if( priv->eeprom_vid == 0x1186 &&  priv->eeprom_did == 0x3304)
                priv->ieee80211->bSupportRemoteWakeUp = true;
        else
@@ -2571,17 +2373,13 @@ static void rtl8192_read_eeprom_info(struct r8192_priv *priv)
 
 
        RT_TRACE(COMP_INIT, "RegChannelPlan(%d)\n", priv->RegChannelPlan);
-       RT_TRACE(COMP_INIT, "ChannelPlan = %d \n", priv->ChannelPlan);
-       RT_TRACE(COMP_INIT, "LedStrategy = %d \n", priv->LedStrategy);
+       RT_TRACE(COMP_INIT, "ChannelPlan = %d\n", priv->ChannelPlan);
        RT_TRACE(COMP_TRACE, "<==== ReadAdapterInfo\n");
-
-       return ;
 }
 
 
-static short rtl8192_get_channel_map(struct net_device * dev)
+static short rtl8192_get_channel_map(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
 #ifdef ENABLE_DOT11D
        if(priv->ChannelPlan> COUNTRY_CODE_GLOBAL_DOMAIN){
                printk("rtl8180_init:Error channel plan! Set to default.\n");
@@ -2608,19 +2406,20 @@ static short rtl8192_get_channel_map(struct net_device * dev)
        return 0;
 }
 
-static short rtl8192_init(struct net_device *dev)
+static short rtl8192_init(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
+       struct net_device *dev = priv->ieee80211->dev;
+
        memset(&(priv->stats),0,sizeof(struct Stats));
-       rtl8192_init_priv_variable(dev);
+       rtl8192_init_priv_variable(priv);
        rtl8192_init_priv_lock(priv);
-       rtl8192_init_priv_task(dev);
-       rtl8192_get_eeprom_size(dev);
+       rtl8192_init_priv_task(priv);
+       rtl8192_get_eeprom_size(priv);
        rtl8192_read_eeprom_info(priv);
-       rtl8192_get_channel_map(dev);
+       rtl8192_get_channel_map(priv);
        init_hal_dm(dev);
        init_timer(&priv->watch_dog_timer);
-       priv->watch_dog_timer.data = (unsigned long)dev;
+       priv->watch_dog_timer.data = (unsigned long)priv;
        priv->watch_dog_timer.function = watch_dog_timer_callback;
         if (request_irq(dev->irq, rtl8192_interrupt, IRQF_SHARED, dev->name, dev)) {
                printk("Error allocating IRQ %d",dev->irq);
@@ -2629,13 +2428,11 @@ static short rtl8192_init(struct net_device *dev)
                priv->irq=dev->irq;
                printk("IRQ %d",dev->irq);
        }
-       if(rtl8192_pci_initdescring(dev)!=0){
+       if (rtl8192_pci_initdescring(priv) != 0){
                printk("Endopoints initialization failed");
                return -1;
        }
 
-       //rtl8192_rx_enable(dev);
-       //rtl8192_adapter_start(dev);
        return 0;
 }
 
@@ -2644,15 +2441,14 @@ static short rtl8192_init(struct net_device *dev)
  *  not to do all the hw config as its name says
  * This part need to modified according to the rate set we filtered
  */
-static void rtl8192_hwconfig(struct net_device* dev)
+static void rtl8192_hwconfig(struct r8192_priv *priv)
 {
        u32 regRATR = 0, regRRSR = 0;
        u8 regBwOpMode = 0, regTmp = 0;
-       struct r8192_priv *priv = ieee80211_priv(dev);
 
 // Set RRSR, RATR, and BW_OPMODE registers
        //
-       switch(priv->ieee80211->mode)
+       switch (priv->ieee80211->mode)
        {
        case WIRELESS_MODE_B:
                regBwOpMode = BW_OPMODE_20MHZ;
@@ -2717,13 +2513,11 @@ static void rtl8192_hwconfig(struct net_device* dev)
 }
 
 
-static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
+static RT_STATUS rtl8192_adapter_start(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
-//     struct ieee80211_device *ieee = priv->ieee80211;
+       struct net_device *dev = priv->ieee80211->dev;
        u32 ulRegRead;
        RT_STATUS rtStatus = RT_STATUS_SUCCESS;
-       //u8 eRFPath;
        u8 tmpvalue;
        u8 ICVersion,SwitchingRegulatorOutput;
        bool bfirmwareok = true;
@@ -2732,7 +2526,7 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
 
        RT_TRACE(COMP_INIT, "====>%s()\n", __FUNCTION__);
        priv->being_init_adapter = true;
-        rtl8192_pci_resetdescring(dev);
+        rtl8192_pci_resetdescring(priv);
        // 2007/11/02 MH Before initalizing RF. We can not use FW to do RF-R/W.
        priv->Rf_Mode = RF_OP_By_SW_3wire;
 
@@ -2763,7 +2557,6 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
                RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __FUNCTION__,   priv->pFirmware->firmware_status);
 
        write_nic_dword(priv, CPU_GEN, ulRegRead);
-       //mdelay(100);
 
        //3//
        //3 //Fix the issue of E-cut high temperature issue
@@ -2788,7 +2581,7 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
        //3// Initialize BB before MAC
        //3//
        RT_TRACE(COMP_INIT, "BB Config Start!\n");
-       rtStatus = rtl8192_BBConfig(dev);
+       rtStatus = rtl8192_BBConfig(priv);
        if(rtStatus != RT_STATUS_SUCCESS)
        {
                RT_TRACE(COMP_ERR, "BB Config failed\n");
@@ -2802,7 +2595,6 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
        //      because setting of System_Reset bit reset MAC to default transmission mode.
                //Loopback mode or not
        priv->LoopbackMode = RTL819X_NO_LOOPBACK;
-       //priv->LoopbackMode = RTL819X_MAC_LOOPBACK;
        if(priv->ResetProgress == RESET_TYPE_NORESET)
        {
        ulRegRead = read_nic_dword(priv, CPU_GEN);
@@ -2827,7 +2619,7 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
        udelay(500);
        }
        //3Set Hardware(Do nothing now)
-       rtl8192_hwconfig(dev);
+       rtl8192_hwconfig(priv);
        //2=======================================================
        // Common Setting for all of the FPGA platform. (part 1)
        //2=======================================================
@@ -2846,21 +2638,6 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
        write_nic_dword(priv, RCR, priv->ReceiveConfig);
 
        //3 Initialize Number of Reserved Pages in Firmware Queue
-       #ifdef TO_DO_LIST
-       if(priv->bInHctTest)
-       {
-               PlatformEFIOWrite4Byte(Adapter, RQPN1,  NUM_OF_PAGE_IN_FW_QUEUE_BK_DTM << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
-                                       NUM_OF_PAGE_IN_FW_QUEUE_BE_DTM << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
-                                       NUM_OF_PAGE_IN_FW_QUEUE_VI_DTM << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
-                                       NUM_OF_PAGE_IN_FW_QUEUE_VO_DTM <<RSVD_FW_QUEUE_PAGE_VO_SHIFT);
-               PlatformEFIOWrite4Byte(Adapter, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT);
-               PlatformEFIOWrite4Byte(Adapter, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW|
-                                       NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT|
-                                       NUM_OF_PAGE_IN_FW_QUEUE_PUB_DTM<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT);
-       }
-       else
-       #endif
-       {
                write_nic_dword(priv, RQPN1,  NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT |
                                        NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT |
                                        NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT |
@@ -2869,10 +2646,9 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
                write_nic_dword(priv, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW|
                                        NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT|
                                        NUM_OF_PAGE_IN_FW_QUEUE_PUB<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT);
-       }
 
-       rtl8192_tx_enable(dev);
-       rtl8192_rx_enable(dev);
+       rtl8192_tx_enable(priv);
+       rtl8192_rx_enable(priv);
        //3Set Response Rate Setting Register
        // CCK rate is supported by default.
        // CCK rate will be filtered out only when associated AP does not support it.
@@ -2884,7 +2660,6 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
        // TODO: (it value is only for FPGA version). need to be changed!!2006.12.18, by Emily
        write_nic_byte(priv, ACK_TIMEOUT, 0x30);
 
-       //rtl8192_actset_wirelessmode(dev,priv->RegWirelessMode);
        if(priv->ResetProgress == RESET_TYPE_NORESET)
        rtl8192_SetWirelessMode(dev, priv->ieee80211->mode);
        //-----------------------------------------------------------------------------
@@ -2892,7 +2667,7 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
        // 1. Clear all H/W keys.
        // 2. Enable H/W encryption/decryption.
        //-----------------------------------------------------------------------------
-       CamResetAllEntry(dev);
+       CamResetAllEntry(priv);
        {
                u8 SECR_value = 0x0;
                SECR_value |= SCR_TxEncEnable;
@@ -2915,11 +2690,11 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
        //2=======================================================
        // Set PHY related configuration defined in MAC register bank
        //2=======================================================
-       rtl8192_phy_configmac(dev);
+       rtl8192_phy_configmac(priv);
 
        if (priv->card_8192_version > (u8) VERSION_8190_BD) {
-               rtl8192_phy_getTxPower(dev);
-               rtl8192_phy_setTxPower(dev, priv->chan);
+               rtl8192_phy_getTxPower(priv);
+               rtl8192_phy_setTxPower(priv, priv->chan);
        }
 
        //if D or C cut
@@ -2958,7 +2733,7 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
        if(priv->ResetProgress == RESET_TYPE_NORESET)
        {
        RT_TRACE(COMP_INIT, "RF Config Started!\n");
-       rtStatus = rtl8192_phy_RFConfig(dev);
+       rtStatus = rtl8192_phy_RFConfig(priv);
        if(rtStatus != RT_STATUS_SUCCESS)
        {
                RT_TRACE(COMP_ERR, "RF Config failed\n");
@@ -2966,11 +2741,11 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
        }
        RT_TRACE(COMP_INIT, "RF Config Finished!\n");
        }
-       rtl8192_phy_updateInitGain(dev);
+       rtl8192_phy_updateInitGain(priv);
 
        /*---- Set CCK and OFDM Block "ON"----*/
-       rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1);
-       rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1);
+       rtl8192_setBBreg(priv, rFPGA0_RFMOD, bCCKEn, 0x1);
+       rtl8192_setBBreg(priv, rFPGA0_RFMOD, bOFDMEn, 0x1);
 
        //Enable Led
        write_nic_byte(priv, 0x87, 0x0);
@@ -2981,33 +2756,21 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
 #ifdef ENABLE_IPS
 
 {
-       if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS)
+       if(priv->RfOffReason > RF_CHANGE_BY_PS)
        { // H/W or S/W RF OFF before sleep.
-               RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d) ----------\n", __FUNCTION__,priv->ieee80211->RfOffReason);
-               MgntActSet_RF_State(dev, eRfOff, priv->ieee80211->RfOffReason);
+               RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d)\n", __FUNCTION__,priv->RfOffReason);
+               MgntActSet_RF_State(priv, eRfOff, priv->RfOffReason);
        }
-       else if(priv->ieee80211->RfOffReason >= RF_CHANGE_BY_IPS)
+       else if(priv->RfOffReason >= RF_CHANGE_BY_IPS)
        { // H/W or S/W RF OFF before sleep.
-               RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d) ----------\n", __FUNCTION__,priv->ieee80211->RfOffReason);
-               MgntActSet_RF_State(dev, eRfOff, priv->ieee80211->RfOffReason);
+               RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d)\n",  __FUNCTION__, priv->RfOffReason);
+               MgntActSet_RF_State(priv, eRfOff, priv->RfOffReason);
        }
        else
        {
                RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): RF-ON \n",__FUNCTION__);
-               priv->ieee80211->eRFPowerState = eRfOn;
-               priv->ieee80211->RfOffReason = 0;
-               //DrvIFIndicateCurrentPhyStatus(Adapter);
-       // LED control
-       //Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_POWER_ON);
-
-       //
-       // If inactive power mode is enabled, disable rf while in disconnected state.
-       // But we should still tell upper layer we are in rf on state.
-       // 2007.07.16, by shien chang.
-       //
-               //if(!Adapter->bInHctTest)
-       //IPSEnter(Adapter);
-
+               priv->eRFPowerState = eRfOn;
+               priv->RfOffReason = 0;
        }
 }
 #endif
@@ -3019,12 +2782,12 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
 
        if(priv->ResetProgress == RESET_TYPE_NORESET)
        {
-               dm_initialize_txpower_tracking(dev);
+               dm_initialize_txpower_tracking(priv);
 
                if(priv->IC_Cut >= IC_VersionCut_D)
                {
-                       tmpRegA= rtl8192_QueryBBReg(dev,rOFDM0_XATxIQImbalance,bMaskDWord);
-                       tmpRegC= rtl8192_QueryBBReg(dev,rOFDM0_XCTxIQImbalance,bMaskDWord);
+                       tmpRegA = rtl8192_QueryBBReg(priv, rOFDM0_XATxIQImbalance, bMaskDWord);
+                       tmpRegC = rtl8192_QueryBBReg(priv, rOFDM0_XCTxIQImbalance, bMaskDWord);
                        for(i = 0; i<TxBBGainTableLength; i++)
                        {
                                if(tmpRegA == priv->txbbgain_table[i].txbbgain_value)
@@ -3036,7 +2799,7 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
                                }
                        }
 
-               TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2);
+               TempCCk = rtl8192_QueryBBReg(priv, rCCK0_TxFilter1, bMaskByte2);
 
                for(i=0 ; i<CCKTxBBGainTableLength ; i++)
                {
@@ -3057,7 +2820,7 @@ static RT_STATUS rtl8192_adapter_start(struct net_device *dev)
                }
        }
 
-       rtl8192_irq_enable(dev);
+       rtl8192_irq_enable(priv);
        priv->being_init_adapter = false;
        return rtStatus;
 
@@ -3067,12 +2830,10 @@ static void rtl8192_prepare_beacon(unsigned long arg)
 {
        struct r8192_priv *priv = (struct r8192_priv*) arg;
        struct sk_buff *skb;
-       //unsigned long flags;
        cb_desc *tcb_desc;
 
        skb = ieee80211_get_beacon(priv->ieee80211);
        tcb_desc = (cb_desc *)(skb->cb + 8);
-       //spin_lock_irqsave(&priv->tx_lock,flags);
        /* prepare misc info for the beacon xmit */
        tcb_desc->queue_index = BEACON_QUEUE;
        /* IBSS does not support HT yet, use 1M defaultly */
@@ -3083,9 +2844,8 @@ static void rtl8192_prepare_beacon(unsigned long arg)
 
        skb_push(skb, priv->ieee80211->tx_headroom);
        if(skb){
-               rtl8192_tx(priv->ieee80211->dev,skb);
+               rtl8192_tx(privskb);
        }
-       //spin_unlock_irqrestore (&priv->tx_lock, flags);
 }
 
 
@@ -3094,16 +2854,16 @@ static void rtl8192_prepare_beacon(unsigned long arg)
  * rtl8192_beacon_tx_enable(). rtl8192_beacon_tx_disable() might
  * be used to stop beacon transmission
  */
-static void rtl8192_start_beacon(struct net_device *dev)
+static void rtl8192_start_beacon(struct ieee80211_device *ieee80211)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
+       struct r8192_priv *priv = ieee80211_priv(ieee80211->dev);
        struct ieee80211_network *net = &priv->ieee80211->current_network;
        u16 BcnTimeCfg = 0;
         u16 BcnCW = 6;
         u16 BcnIFS = 0xf;
 
        DMESG("Enabling beacon TX");
-       rtl8192_irq_disable(dev);
+       rtl8192_irq_disable(priv);
        //rtl8192_beacon_tx_enable(dev);
 
        /* ATIM window */
@@ -3138,66 +2898,11 @@ static void rtl8192_start_beacon(struct net_device *dev)
 
 
        /* enable the interrupt for ad-hoc process */
-       rtl8192_irq_enable(dev);
-}
-
-static bool HalTxCheckStuck8190Pci(struct net_device *dev)
-{
-       struct r8192_priv *priv = ieee80211_priv(dev);
-       u16 RegTxCounter = read_nic_word(priv, 0x128);
-       bool                            bStuck = FALSE;
-       RT_TRACE(COMP_RESET,"%s():RegTxCounter is %d,TxCounter is %d\n",__FUNCTION__,RegTxCounter,priv->TxCounter);
-       if(priv->TxCounter==RegTxCounter)
-               bStuck = TRUE;
-
-       priv->TxCounter = RegTxCounter;
-
-       return bStuck;
+       rtl8192_irq_enable(priv);
 }
 
-/*
- * Assumption: RT_TX_SPINLOCK is acquired.
- */
-static RESET_TYPE
-TxCheckStuck(struct net_device *dev)
+static bool HalRxCheckStuck8190Pci(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
-       u8                      ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
-       bool                    bCheckFwTxCnt = false;
-
-       //
-       // Decide Stuch threshold according to current power save mode
-       //
-       switch (priv->ieee80211->dot11PowerSaveMode)
-       {
-               // The threshold value  may required to be adjusted .
-               case eActive:           // Active/Continuous access.
-                       ResetThreshold = NIC_SEND_HANG_THRESHOLD_NORMAL;
-                       break;
-               case eMaxPs:            // Max power save mode.
-                       ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
-                       break;
-               case eFastPs:   // Fast power save mode.
-                       ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE;
-                       break;
-       }
-
-       if(bCheckFwTxCnt)
-       {
-               if(HalTxCheckStuck8190Pci(dev))
-               {
-                       RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n");
-                       return RESET_TYPE_SILENT;
-               }
-       }
-
-       return RESET_TYPE_NORESET;
-}
-
-
-static bool HalRxCheckStuck8190Pci(struct net_device *dev)
-{
-       struct r8192_priv *priv = ieee80211_priv(dev);
        u16 RegRxCounter = read_nic_word(priv, 0x130);
        bool                            bStuck = FALSE;
 
@@ -3255,10 +2960,10 @@ static bool HalRxCheckStuck8190Pci(struct net_device *dev)
        return bStuck;
 }
 
-static RESET_TYPE RxCheckStuck(struct net_device *dev)
+static RESET_TYPE RxCheckStuck(struct r8192_priv *priv)
 {
 
-       if(HalRxCheckStuck8190Pci(dev))
+       if(HalRxCheckStuck8190Pci(priv))
        {
                RT_TRACE(COMP_RESET, "RxStuck Condition\n");
                return RESET_TYPE_SILENT;
@@ -3267,311 +2972,39 @@ static RESET_TYPE RxCheckStuck(struct net_device *dev)
        return RESET_TYPE_NORESET;
 }
 
-static RESET_TYPE
-rtl819x_ifcheck_resetornot(struct net_device *dev)
+static RESET_TYPE rtl819x_check_reset(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
-       RESET_TYPE      TxResetType = RESET_TYPE_NORESET;
-       RESET_TYPE      RxResetType = RESET_TYPE_NORESET;
-       RT_RF_POWER_STATE       rfState;
+       RESET_TYPE RxResetType = RESET_TYPE_NORESET;
+       RT_RF_POWER_STATE rfState;
 
-       rfState = priv->ieee80211->eRFPowerState;
-
-       TxResetType = TxCheckStuck(dev);
-
-       if( rfState != eRfOff &&
-               /*ADAPTER_TEST_STATUS_FLAG(Adapter, ADAPTER_STATUS_FW_DOWNLOAD_FAILURE)) &&*/
-               (priv->ieee80211->iw_mode != IW_MODE_ADHOC))
-       {
-               // If driver is in the status of firmware download failure , driver skips RF initialization and RF is
-               // in turned off state. Driver should check whether Rx stuck and do silent reset. And
-               // if driver is in firmware download failure status, driver should initialize RF in the following
-               // silent reset procedure Emily, 2008.01.21
-
-               // Driver should not check RX stuck in IBSS mode because it is required to
-               // set Check BSSID in order to send beacon, however, if check BSSID is
-               // set, STA cannot hear any packet a all. Emily, 2008.04.12
-               RxResetType = RxCheckStuck(dev);
-       }
+       rfState = priv->eRFPowerState;
 
-       RT_TRACE(COMP_RESET,"%s(): TxResetType is %d, RxResetType is %d\n",__FUNCTION__,TxResetType,RxResetType);
-       if(TxResetType==RESET_TYPE_NORMAL || RxResetType==RESET_TYPE_NORMAL)
-               return RESET_TYPE_NORMAL;
-       else if(TxResetType==RESET_TYPE_SILENT || RxResetType==RESET_TYPE_SILENT)
-               return RESET_TYPE_SILENT;
-       else
-               return RESET_TYPE_NORESET;
-
-}
-
-
-static void CamRestoreAllEntry(struct net_device *dev)
-{
-       u8 EntryId = 0;
-       struct r8192_priv *priv = ieee80211_priv(dev);
-       const u8*       MacAddr = priv->ieee80211->current_network.bssid;
-
-       static const u8 CAM_CONST_ADDR[4][6] = {
-               {0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
-               {0x00, 0x00, 0x00, 0x00, 0x00, 0x01},
-               {0x00, 0x00, 0x00, 0x00, 0x00, 0x02},
-               {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}};
-       static const u8 CAM_CONST_BROAD[] =
-               {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
-
-       RT_TRACE(COMP_SEC, "CamRestoreAllEntry: \n");
-
-
-       if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40)||
-           (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104))
-       {
-
-               for(EntryId=0; EntryId<4; EntryId++)
-               {
-                       {
-                               MacAddr = CAM_CONST_ADDR[EntryId];
-                               setKey(dev,
-                                               EntryId ,
-                                               EntryId,
-                                               priv->ieee80211->pairwise_key_type,
-                                               MacAddr,
-                                               0,
-                                               NULL);
-                       }
-               }
-
-       }
-       else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP)
-       {
-
-               {
-                       if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
-                               setKey(dev,
-                                               4,
-                                               0,
-                                               priv->ieee80211->pairwise_key_type,
-                                               (u8*)dev->dev_addr,
-                                               0,
-                                               NULL);
-                       else
-                               setKey(dev,
-                                               4,
-                                               0,
-                                               priv->ieee80211->pairwise_key_type,
-                                               MacAddr,
-                                               0,
-                                               NULL);
-               }
-       }
-       else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP)
-       {
-
-               {
-                       if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
-                               setKey(dev,
-                                               4,
-                                               0,
-                                               priv->ieee80211->pairwise_key_type,
-                                               (u8*)dev->dev_addr,
-                                               0,
-                                               NULL);
-                       else
-                               setKey(dev,
-                                               4,
-                                               0,
-                                               priv->ieee80211->pairwise_key_type,
-                                               MacAddr,
-                                               0,
-                                               NULL);
-               }
-       }
-
-
-
-       if(priv->ieee80211->group_key_type == KEY_TYPE_TKIP)
-       {
-               MacAddr = CAM_CONST_BROAD;
-               for(EntryId=1 ; EntryId<4 ; EntryId++)
-               {
-                       {
-                               setKey(dev,
-                                               EntryId,
-                                               EntryId,
-                                               priv->ieee80211->group_key_type,
-                                               MacAddr,
-                                               0,
-                                               NULL);
-                       }
-               }
-               if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
-                               setKey(dev,
-                                               0,
-                                               0,
-                                               priv->ieee80211->group_key_type,
-                                               CAM_CONST_ADDR[0],
-                                               0,
-                                               NULL);
-       }
-       else if(priv->ieee80211->group_key_type == KEY_TYPE_CCMP)
-       {
-               MacAddr = CAM_CONST_BROAD;
-               for(EntryId=1; EntryId<4 ; EntryId++)
-               {
-                       {
-                               setKey(dev,
-                                               EntryId ,
-                                               EntryId,
-                                               priv->ieee80211->group_key_type,
-                                               MacAddr,
-                                               0,
-                                               NULL);
-                       }
-               }
-
-               if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
-                               setKey(dev,
-                                               0 ,
-                                               0,
-                                               priv->ieee80211->group_key_type,
-                                               CAM_CONST_ADDR[0],
-                                               0,
-                                               NULL);
+       if (rfState != eRfOff && (priv->ieee80211->iw_mode != IW_MODE_ADHOC)) {
+               /*
+                * If driver is in the status of firmware download failure,
+                * driver skips RF initialization and RF is in turned off state.
+                * Driver should check whether Rx stuck and do silent reset. And
+                * if driver is in firmware download failure status, driver
+                * should initialize RF in the following silent reset procedure
+                *
+                * Driver should not check RX stuck in IBSS mode because it is
+                * required to set Check BSSID in order to send beacon, however,
+                * if check BSSID is set, STA cannot hear any packet a all.
+                */
+               RxResetType = RxCheckStuck(priv);
        }
-}
-
-/*
- * This function is used to fix Tx/Rx stop bug temporarily.
- * This function will do "system reset" to NIC when Tx or Rx is stuck.
- * The method checking Tx/Rx stuck of this function is supported by FW,
- * which reports Tx and Rx counter to register 0x128 and 0x130.
- */
-static void rtl819x_ifsilentreset(struct net_device *dev)
-{
-       struct r8192_priv *priv = ieee80211_priv(dev);
-       u8      reset_times = 0;
-       int reset_status = 0;
-       struct ieee80211_device *ieee = priv->ieee80211;
-
-
-       return;
-
-       // 2007.07.20. If we need to check CCK stop, please uncomment this line.
-       //bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter);
-
-       if(priv->ResetProgress==RESET_TYPE_NORESET)
-       {
-RESET_START:
-#ifdef ENABLE_LPS
-                //LZM for PS-Poll AID issue. 090429
-                if(priv->ieee80211->state == IEEE80211_LINKED)
-                    LeisurePSLeave(dev);
-#endif
 
-               RT_TRACE(COMP_RESET,"=========>Reset progress!! \n");
+       RT_TRACE(COMP_RESET, "%s():  RxResetType is %d\n", __FUNCTION__, RxResetType);
 
-               // Set the variable for reset.
-               priv->ResetProgress = RESET_TYPE_SILENT;
-//             rtl8192_close(dev);
-
-               down(&priv->wx_sem);
-               if(priv->up == 0)
-               {
-                       RT_TRACE(COMP_ERR,"%s():the driver is not up! return\n",__FUNCTION__);
-                       up(&priv->wx_sem);
-                       return ;
-               }
-               priv->up = 0;
-               RT_TRACE(COMP_RESET,"%s():======>start to down the driver\n",__FUNCTION__);
-               if(!netif_queue_stopped(dev))
-                       netif_stop_queue(dev);
-
-               dm_backup_dynamic_mechanism_state(dev);
-
-               rtl8192_irq_disable(dev);
-               rtl8192_cancel_deferred_work(priv);
-               deinit_hal_dm(dev);
-               del_timer_sync(&priv->watch_dog_timer);
-               ieee->sync_scan_hurryup = 1;
-               if(ieee->state == IEEE80211_LINKED)
-               {
-                       down(&ieee->wx_sem);
-                       printk("ieee->state is IEEE80211_LINKED\n");
-                       ieee80211_stop_send_beacons(priv->ieee80211);
-                       del_timer_sync(&ieee->associate_timer);
-                        cancel_delayed_work(&ieee->associate_retry_wq);
-                       ieee80211_stop_scan(ieee);
-                       up(&ieee->wx_sem);
-               }
-               else{
-                       printk("ieee->state is NOT LINKED\n");
-                       ieee80211_softmac_stop_protocol(priv->ieee80211,true);
-               }
-               rtl8192_halt_adapter(dev, true);
-               up(&priv->wx_sem);
-               RT_TRACE(COMP_RESET,"%s():<==========down process is finished\n",__FUNCTION__);
-               RT_TRACE(COMP_RESET,"%s():===========>start to up the driver\n",__FUNCTION__);
-               reset_status = _rtl8192_up(dev);
-
-               RT_TRACE(COMP_RESET,"%s():<===========up process is finished\n",__FUNCTION__);
-               if(reset_status == -1)
-               {
-                       if(reset_times < 3)
-                       {
-                               reset_times++;
-                               goto RESET_START;
-                       }
-                       else
-                       {
-                               RT_TRACE(COMP_ERR," ERR!!! %s():  Reset Failed!!\n",__FUNCTION__);
-                       }
-               }
-               ieee->is_silent_reset = 1;
-               EnableHWSecurityConfig8192(dev);
-               if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA)
-               {
-                       ieee->set_chan(ieee->dev, ieee->current_network.channel);
-
-                       queue_work(ieee->wq, &ieee->associate_complete_wq);
-
-               }
-               else if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC)
-               {
-                       ieee->set_chan(ieee->dev, ieee->current_network.channel);
-                       ieee->link_change(ieee->dev);
-
-               //      notify_wx_assoc_event(ieee);
-
-                       ieee80211_start_send_beacons(ieee);
-
-                       if (ieee->data_hard_resume)
-                               ieee->data_hard_resume(ieee->dev);
-                       netif_carrier_on(ieee->dev);
-               }
-
-               CamRestoreAllEntry(dev);
-
-               // Restore the previous setting for all dynamic mechanism
-               dm_restore_dynamic_mechanism_state(dev);
-
-               priv->ResetProgress = RESET_TYPE_NORESET;
-               priv->reset_count++;
-
-               priv->bForcedSilentReset =false;
-               priv->bResetInProgress = false;
-
-               // For test --> force write UFWP.
-               write_nic_byte(priv, UFWP, 1);
-               RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", priv->reset_count);
-       }
+       return RxResetType;
 }
 
 #ifdef ENABLE_IPS
-void InactivePsWorkItemCallback(struct net_device *dev)
+static void InactivePsWorkItemCallback(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
-       PRT_POWER_SAVE_CONTROL  pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
+       PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl;
 
-       RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() ---------> \n");
+       RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() --------->\n");
        //
        // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
        // is really scheduled.
@@ -3586,20 +3019,19 @@ void InactivePsWorkItemCallback(struct net_device *dev)
                        pPSC->eInactivePowerState == eRfOff?"OFF":"ON");
 
 
-       MgntActSet_RF_State(dev, pPSC->eInactivePowerState, RF_CHANGE_BY_IPS);
+       MgntActSet_RF_State(priv, pPSC->eInactivePowerState, RF_CHANGE_BY_IPS);
 
        //
        // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
        //
        pPSC->bSwRfProcessing = FALSE;
-       RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() <--------- \n");
+       RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() <---------\n");
 }
 
 #ifdef ENABLE_LPS
 /* Change current and default preamble mode. */
-bool MgntActSet_802_11_PowerSaveMode(struct net_device *dev,   u8 rtPsMode)
+bool MgntActSet_802_11_PowerSaveMode(struct r8192_priv *priv, u8 rtPsMode)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
 
        // Currently, we do not change power save mode on IBSS mode.
        if(priv->ieee80211->iw_mode == IW_MODE_ADHOC)
@@ -3625,17 +3057,14 @@ bool MgntActSet_802_11_PowerSaveMode(struct net_device *dev,    u8 rtPsMode)
        // Awake immediately
        if(priv->ieee80211->sta_sleep != 0 && rtPsMode == IEEE80211_PS_DISABLED)
        {
-                unsigned long flags;
-
-               //PlatformSetTimer(Adapter, &(pMgntInfo->AwakeTimer), 0);
                // Notify the AP we awke.
-               rtl8192_hw_wakeup(dev);
+               rtl8192_hw_wakeup(priv->ieee80211->dev);
                priv->ieee80211->sta_sleep = 0;
 
-                spin_lock_irqsave(&(priv->ieee80211->mgmt_tx_lock), flags);
+                spin_lock(&priv->ieee80211->mgmt_tx_lock);
                printk("LPS leave: notify AP we are awaked ++++++++++ SendNullFunctionData\n");
                ieee80211_sta_ps_send_null_frame(priv->ieee80211, 0);
-                spin_unlock_irqrestore(&(priv->ieee80211->mgmt_tx_lock), flags);
+                spin_unlock(&priv->ieee80211->mgmt_tx_lock);
        }
 
        return true;
@@ -3645,11 +3074,7 @@ bool MgntActSet_802_11_PowerSaveMode(struct net_device *dev,     u8 rtPsMode)
 void LeisurePSEnter(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
-       PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
-
-       //RT_TRACE(COMP_PS, "LeisurePSEnter()...\n");
-       //RT_TRACE(COMP_PS, "pPSC->bLeisurePs = %d, ieee->ps = %d,pPSC->LpsIdleCount is %d,RT_CHECK_FOR_HANG_PERIOD is %d\n",
-       //      pPSC->bLeisurePs, priv->ieee80211->ps,pPSC->LpsIdleCount,RT_CHECK_FOR_HANG_PERIOD);
+       PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl;
 
        if(!((priv->ieee80211->iw_mode == IW_MODE_INFRA) &&
                (priv->ieee80211->state == IEEE80211_LINKED)) ||
@@ -3665,9 +3090,7 @@ void LeisurePSEnter(struct net_device *dev)
 
                        if(priv->ieee80211->ps == IEEE80211_PS_DISABLED)
                        {
-
-                               //RT_TRACE(COMP_LPS, "LeisurePSEnter(): Enter 802.11 power save mode...\n");
-                               MgntActSet_802_11_PowerSaveMode(dev, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST);
+                               MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST);
 
                        }
                }
@@ -3681,15 +3104,14 @@ void LeisurePSEnter(struct net_device *dev)
 void LeisurePSLeave(struct net_device *dev)
 {
        struct r8192_priv *priv = ieee80211_priv(dev);
-       PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
+       PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl;
 
        if (pPSC->bLeisurePs)
        {
                if(priv->ieee80211->ps != IEEE80211_PS_DISABLED)
                {
                        // move to lps_wakecomplete()
-                       //RT_TRACE(COMP_LPS, "LeisurePSLeave(): Busy Traffic , Leave 802.11 power save..\n");
-                       MgntActSet_802_11_PowerSaveMode(dev, IEEE80211_PS_DISABLED);
+                       MgntActSet_802_11_PowerSaveMode(priv, IEEE80211_PS_DISABLED);
 
                }
        }
@@ -3698,16 +3120,14 @@ void LeisurePSLeave(struct net_device *dev)
 
 
 /* Enter the inactive power save mode. RF will be off */
-void
-IPSEnter(struct net_device *dev)
+void IPSEnter(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
-       PRT_POWER_SAVE_CONTROL          pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
+       PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl;
        RT_RF_POWER_STATE                       rtState;
 
        if (pPSC->bInactivePs)
        {
-               rtState = priv->ieee80211->eRFPowerState;
+               rtState = priv->eRFPowerState;
                //
                // Added by Bruce, 2007-12-25.
                // Do not enter IPS in the following conditions:
@@ -3723,7 +3143,7 @@ IPSEnter(struct net_device *dev)
                        RT_TRACE(COMP_RF,"IPSEnter(): Turn off RF.\n");
                        pPSC->eInactivePowerState = eRfOff;
 //                     queue_work(priv->priv_wq,&(pPSC->InactivePsWorkItem));
-                       InactivePsWorkItemCallback(dev);
+                       InactivePsWorkItemCallback(priv);
                }
        }
 }
@@ -3733,22 +3153,19 @@ IPSEnter(struct net_device *dev)
 //             Leave the inactive power save mode, RF will be on.
 //     2007.08.17, by shien chang.
 //
-void
-IPSLeave(struct net_device *dev)
+void IPSLeave(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
-       PRT_POWER_SAVE_CONTROL  pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
+       PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl;
        RT_RF_POWER_STATE       rtState;
 
        if (pPSC->bInactivePs)
        {
-               rtState = priv->ieee80211->eRFPowerState;
-               if (rtState != eRfOn  && !pPSC->bSwRfProcessing && priv->ieee80211->RfOffReason <= RF_CHANGE_BY_IPS)
+               rtState = priv->eRFPowerState;
+               if (rtState != eRfOn && !pPSC->bSwRfProcessing && priv->RfOffReason <= RF_CHANGE_BY_IPS)
                {
                        RT_TRACE(COMP_POWER, "IPSLeave(): Turn on RF.\n");
                        pPSC->eInactivePowerState = eRfOn;
-//                     queue_work(priv->priv_wq,&(pPSC->InactivePsWorkItem));
-                       InactivePsWorkItemCallback(dev);
+                       InactivePsWorkItemCallback(priv);
                }
        }
 }
@@ -3760,7 +3177,7 @@ void IPSLeave_wq(struct work_struct *work)
 
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        down(&priv->ieee80211->ips_sem);
-       IPSLeave(dev);
+       IPSLeave(priv);
        up(&priv->ieee80211->ips_sem);
 }
 
@@ -3768,11 +3185,11 @@ void ieee80211_ips_leave_wq(struct net_device *dev)
 {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        RT_RF_POWER_STATE       rtState;
-       rtState = priv->ieee80211->eRFPowerState;
+       rtState = priv->eRFPowerState;
 
-       if(priv->ieee80211->PowerSaveControl.bInactivePs){
+       if (priv->PowerSaveControl.bInactivePs){
                if(rtState == eRfOff){
-                       if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_IPS)
+                       if(priv->RfOffReason > RF_CHANGE_BY_IPS)
                        {
                                RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__);
                                return;
@@ -3789,7 +3206,7 @@ void ieee80211_ips_leave(struct net_device *dev)
 {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        down(&priv->ieee80211->ips_sem);
-       IPSLeave(dev);
+       IPSLeave(priv);
        up(&priv->ieee80211->ips_sem);
 }
 #endif
@@ -3820,10 +3237,9 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
 {
        struct delayed_work *dwork = container_of(work,struct delayed_work,work);
        struct r8192_priv *priv = container_of(dwork,struct r8192_priv,watch_dog_wq);
-       struct net_device *dev = priv->ieee80211->dev;
+       struct net_device *dev = priv->ieee80211->dev;
        struct ieee80211_device* ieee = priv->ieee80211;
        RESET_TYPE      ResetType = RESET_TYPE_NORESET;
-       unsigned long flags;
        bool bBusyTraffic = false;
        bool bEnterPS = false;
 
@@ -3836,11 +3252,10 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
 #ifdef ENABLE_IPS
        if(ieee->actscanning == false){
                if((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state == IEEE80211_NOLINK) &&
-                   (ieee->eRFPowerState == eRfOn)&&!ieee->is_set_key &&
+                   (priv->eRFPowerState == eRfOn) && !ieee->is_set_key &&
                    (!ieee->proto_stoppping) && !ieee->wx_set_enc){
-                       if(ieee->PowerSaveControl.ReturnPoint == IPS_CALLBACK_NONE){
-                               IPSEnter(dev);
-                               //ieee80211_stop_scan(priv->ieee80211);
+                       if (priv->PowerSaveControl.ReturnPoint == IPS_CALLBACK_NONE){
+                               IPSEnter(priv);
                        }
                }
        }
@@ -3880,7 +3295,6 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
                else
                {
 #ifdef ENABLE_LPS
-                       //RT_TRACE(COMP_LPS,"====>no link LPS leave\n");
                        LeisurePSLeave(dev);
 #endif
                }
@@ -3893,8 +3307,6 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
 
 
        //added by amy for AP roaming
-       if (1)
-       {
                if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA)
                {
                        u32     TotalRxBcnNum = 0;
@@ -3903,7 +3315,7 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
                        rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum);
                        if((TotalRxBcnNum+TotalRxDataNum) == 0)
                        {
-                               if( ieee->eRFPowerState == eRfOff)
+                               if (priv->eRFPowerState == eRfOff)
                                        RT_TRACE(COMP_ERR,"========>%s()\n",__FUNCTION__);
                                printk("===>%s(): AP is power off,connect another one\n",__FUNCTION__);
                                //              Dot11d_Reset(dev);
@@ -3919,16 +3331,13 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
              ieee->LinkDetectInfo.NumRecvBcnInPeriod=0;
               ieee->LinkDetectInfo.NumRecvDataInPeriod=0;
 
-       }
        //check if reset the driver
-       spin_lock_irqsave(&priv->tx_lock,flags);
        if (priv->watchdog_check_reset_cnt++ >= 3 && !ieee->is_roaming && 
            priv->watchdog_last_time != 1)
        {
-               ResetType = rtl819x_ifcheck_resetornot(dev);
+               ResetType = rtl819x_check_reset(priv);
                priv->watchdog_check_reset_cnt = 3;
        }
-       spin_unlock_irqrestore(&priv->tx_lock,flags);
        if(!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL)
        {
                priv->ResetProgress = RESET_TYPE_NORMAL;
@@ -3940,7 +3349,6 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
        if( ((priv->force_reset) || (!priv->bDisableNormalResetCheck && ResetType==RESET_TYPE_SILENT))) // This is control by OID set in Pomelo
        {
                priv->watchdog_last_time = 1;
-               rtl819x_ifsilentreset(dev);
        }
        else
                priv->watchdog_last_time = 0;
@@ -3954,23 +3362,23 @@ static void rtl819x_watchdog_wqcallback(struct work_struct *work)
 
 void watch_dog_timer_callback(unsigned long data)
 {
-       struct r8192_priv *priv = ieee80211_priv((struct net_device *) data);
+       struct r8192_priv *priv = (struct r8192_priv *) data;
        queue_delayed_work(priv->priv_wq,&priv->watch_dog_wq,0);
        mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME));
 
 }
 
-static int _rtl8192_up(struct net_device *dev)
+static int _rtl8192_up(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
-       //int i;
        RT_STATUS init_status = RT_STATUS_SUCCESS;
+       struct net_device *dev = priv->ieee80211->dev;
+
        priv->up=1;
        priv->ieee80211->ieee_up=1;
        priv->bdisable_nic = false;  //YJ,add,091111
-       RT_TRACE(COMP_INIT, "Bringing up iface");
+       RT_TRACE(COMP_INIT, "Bringing up iface\n");
 
-       init_status = rtl8192_adapter_start(dev);
+       init_status = rtl8192_adapter_start(priv);
        if(init_status != RT_STATUS_SUCCESS)
        {
                RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__);
@@ -3978,13 +3386,13 @@ static int _rtl8192_up(struct net_device *dev)
        }
        RT_TRACE(COMP_INIT, "start adapter finished\n");
 
-       if(priv->ieee80211->eRFPowerState!=eRfOn)
-               MgntActSet_RF_State(dev, eRfOn, priv->ieee80211->RfOffReason);
+       if (priv->eRFPowerState != eRfOn)
+               MgntActSet_RF_State(priv, eRfOn, priv->RfOffReason);
 
        if(priv->ieee80211->state != IEEE80211_LINKED)
        ieee80211_softmac_start_protocol(priv->ieee80211);
        ieee80211_reset_queue(priv->ieee80211);
-       watch_dog_timer_callback((unsigned long) dev);
+       watch_dog_timer_callback((unsigned long) priv);
        if(!netif_queue_stopped(dev))
                netif_start_queue(dev);
        else
@@ -4013,7 +3421,7 @@ int rtl8192_up(struct net_device *dev)
 
        if (priv->up == 1) return -1;
 
-       return _rtl8192_up(dev);
+       return _rtl8192_up(priv);
 }
 
 
@@ -4051,14 +3459,14 @@ int rtl8192_down(struct net_device *dev)
        if (!netif_queue_stopped(dev))
                netif_stop_queue(dev);
 
-       rtl8192_irq_disable(dev);
+       rtl8192_irq_disable(priv);
        rtl8192_cancel_deferred_work(priv);
        deinit_hal_dm(dev);
        del_timer_sync(&priv->watch_dog_timer);
 
        ieee80211_softmac_stop_protocol(priv->ieee80211,true);
 
-       rtl8192_halt_adapter(dev,false);
+       rtl8192_halt_adapter(priv, false);
        memset(&priv->ieee80211->current_network, 0 , offsetof(struct ieee80211_network, list));
 
        RT_TRACE(COMP_DOWN, "<==========%s()\n", __FUNCTION__);
@@ -4067,28 +3475,25 @@ int rtl8192_down(struct net_device *dev)
 }
 
 
-void rtl8192_commit(struct net_device *dev)
+void rtl8192_commit(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = ieee80211_priv(dev);
-
        if (priv->up == 0) return ;
 
 
        ieee80211_softmac_stop_protocol(priv->ieee80211,true);
 
-       rtl8192_irq_disable(dev);
-       rtl8192_halt_adapter(dev,true);
-       _rtl8192_up(dev);
+       rtl8192_irq_disable(priv);
+       rtl8192_halt_adapter(priv, true);
+       _rtl8192_up(priv);
 }
 
 static void rtl8192_restart(struct work_struct *work)
 {
         struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq);
-        struct net_device *dev = priv->ieee80211->dev;
 
        down(&priv->wx_sem);
 
-       rtl8192_commit(dev);
+       rtl8192_commit(priv);
 
        up(&priv->wx_sem);
 }
@@ -4116,15 +3521,74 @@ static int r8192_set_mac_adr(struct net_device *dev, void *mac)
        return 0;
 }
 
+static void r8192e_set_hw_key(struct r8192_priv *priv, struct ieee_param *ipw)
+{
+       struct ieee80211_device *ieee = priv->ieee80211;
+       u8 broadcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
+       u32 key[4];
+
+       if (ipw->u.crypt.set_tx) {
+               if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
+                       ieee->pairwise_key_type = KEY_TYPE_CCMP;
+               else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
+                       ieee->pairwise_key_type = KEY_TYPE_TKIP;
+               else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
+                       if (ipw->u.crypt.key_len == 13)
+                               ieee->pairwise_key_type = KEY_TYPE_WEP104;
+                       else if (ipw->u.crypt.key_len == 5)
+                               ieee->pairwise_key_type = KEY_TYPE_WEP40;
+               } else
+                       ieee->pairwise_key_type = KEY_TYPE_NA;
+
+               if (ieee->pairwise_key_type) {
+                       memcpy(key, ipw->u.crypt.key, 16);
+                       EnableHWSecurityConfig8192(priv);
+                       /*
+                        * We fill both index entry and 4th entry for pairwise
+                        * key as in IPW interface, adhoc will only get here,
+                        * so we need index entry for its default key serching!
+                        */
+                       setKey(priv, 4, ipw->u.crypt.idx,
+                              ieee->pairwise_key_type,
+                              (u8*)ieee->ap_mac_addr, 0, key);
+
+                       /* LEAP WEP will never set this. */
+                       if (ieee->auth_mode != 2)
+                               setKey(priv, ipw->u.crypt.idx, ipw->u.crypt.idx,
+                                      ieee->pairwise_key_type,
+                                      (u8*)ieee->ap_mac_addr, 0, key);
+               }
+               if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) &&
+                   ieee->pHTInfo->bCurrentHTSupport) {
+                       write_nic_byte(priv, 0x173, 1); /* fix aes bug */
+               }
+       } else {
+               memcpy(key, ipw->u.crypt.key, 16);
+               if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
+                       ieee->group_key_type= KEY_TYPE_CCMP;
+               else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
+                       ieee->group_key_type = KEY_TYPE_TKIP;
+               else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) {
+                       if (ipw->u.crypt.key_len == 13)
+                               ieee->group_key_type = KEY_TYPE_WEP104;
+                       else if (ipw->u.crypt.key_len == 5)
+                               ieee->group_key_type = KEY_TYPE_WEP40;
+               } else
+                       ieee->group_key_type = KEY_TYPE_NA;
+
+               if (ieee->group_key_type) {
+                       setKey(priv, ipw->u.crypt.idx, ipw->u.crypt.idx,
+                              ieee->group_key_type, broadcast_addr, 0, key);
+               }
+       }
+}
+
 /* based on ipw2200 driver */
 static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
 {
        struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct iwreq *wrq = (struct iwreq *)rq;
        int ret=-1;
-       struct ieee80211_device *ieee = priv->ieee80211;
-       u32 key[4];
-       u8 broadcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
        struct iw_point *p = &wrq->u.data;
        struct ieee_param *ipw = NULL;//(struct ieee_param *)wrq->u.data.pointer;
 
@@ -4148,74 +3612,14 @@ static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
      }
 
        switch (cmd) {
-           case RTL_IOCTL_WPA_SUPPLICANT:
-               //parse here for HW security
-                       if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION)
-                       {
-                               if (ipw->u.crypt.set_tx)
-                               {
-                                       if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
-                                               ieee->pairwise_key_type = KEY_TYPE_CCMP;
-                                       else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
-                                               ieee->pairwise_key_type = KEY_TYPE_TKIP;
-                                       else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
-                                       {
-                                               if (ipw->u.crypt.key_len == 13)
-                                                       ieee->pairwise_key_type = KEY_TYPE_WEP104;
-                                               else if (ipw->u.crypt.key_len == 5)
-                                                       ieee->pairwise_key_type = KEY_TYPE_WEP40;
-                                       }
-                                       else
-                                               ieee->pairwise_key_type = KEY_TYPE_NA;
-
-                                       if (ieee->pairwise_key_type)
-                                       {
-                                               memcpy((u8*)key, ipw->u.crypt.key, 16);
-                                               EnableHWSecurityConfig8192(dev);
-                                       //we fill both index entry and 4th entry for pairwise key as in IPW interface, adhoc will only get here, so we need index entry for its default key serching!
-                                       //added by WB.
-                                               setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
-                                               if (ieee->auth_mode != 2)  //LEAP WEP will never set this.
-                                               setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key);
-                                       }
-                                       if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) && ieee->pHTInfo->bCurrentHTSupport){
-                                                       write_nic_byte(priv, 0x173, 1); //fix aes bug
-                                               }
-
-                               }
-                               else //if (ipw->u.crypt.idx) //group key use idx > 0
-                               {
-                                       memcpy((u8*)key, ipw->u.crypt.key, 16);
-                                       if (strcmp(ipw->u.crypt.alg, "CCMP") == 0)
-                                               ieee->group_key_type= KEY_TYPE_CCMP;
-                                       else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0)
-                                               ieee->group_key_type = KEY_TYPE_TKIP;
-                                       else if (strcmp(ipw->u.crypt.alg, "WEP") == 0)
-                                       {
-                                               if (ipw->u.crypt.key_len == 13)
-                                                       ieee->group_key_type = KEY_TYPE_WEP104;
-                                               else if (ipw->u.crypt.key_len == 5)
-                                                       ieee->group_key_type = KEY_TYPE_WEP40;
-                                       }
-                                       else
-                                               ieee->group_key_type = KEY_TYPE_NA;
-
-                                       if (ieee->group_key_type)
-                                       {
-                                                       setKey( dev,
-                                                               ipw->u.crypt.idx,
-                                                               ipw->u.crypt.idx,               //KeyIndex
-                                                               ieee->group_key_type,   //KeyType
-                                                               broadcast_addr, //MacAddr
-                                                               0,              //DefaultKey
-                                                               key);           //KeyContent
-                                       }
-                               }
-                       }
+       case RTL_IOCTL_WPA_SUPPLICANT:
+               /* parse here for HW security */
+               if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION)
+                       r8192e_set_hw_key(priv, ipw);
                ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data);
                break;
 
-           default:
+       default:
                ret = -EOPNOTSUPP;
                break;
        }
@@ -4281,9 +3685,8 @@ static u8 HwRateToMRate90(bool bIsHT, u8 rate)
 }
 
 /* Record the TSF time stamp when receiving a packet */
-static void UpdateRxPktTimeStamp8190 (struct net_device *dev, struct ieee80211_rx_stats *stats)
+static void UpdateRxPktTimeStamp8190(struct r8192_priv *priv, struct ieee80211_rx_stats *stats)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
 
        if(stats->bIsAMPDU && !stats->bFirstMPDU) {
                stats->mac_time[0] = priv->LastRxDescTSFLow;
@@ -4314,13 +3717,9 @@ static void rtl8192_process_phyinfo(struct r8192_priv * priv, u8* buffer,struct
        bool bcheck = false;
        u8      rfpath;
        u32 nspatial_stream, tmp_val;
-       //u8    i;
        static u32 slide_rssi_index=0, slide_rssi_statistics=0;
        static u32 slide_evm_index=0, slide_evm_statistics=0;
        static u32 last_rssi=0, last_evm=0;
-       //cosa add for rx path selection
-//     static long slide_cck_adc_pwdb_index=0, slide_cck_adc_pwdb_statistics=0;
-//     static char last_cck_adc_pwdb[4]={0,0,0,0};
        //cosa add for beacon rssi smoothing
        static u32 slide_beacon_adc_pwdb_index=0, slide_beacon_adc_pwdb_statistics=0;
        static u32 last_beacon_adc_pwdb=0;
@@ -4332,8 +3731,7 @@ static void rtl8192_process_phyinfo(struct r8192_priv * priv, u8* buffer,struct
        sc = le16_to_cpu(hdr->seq_ctl);
        frag = WLAN_GET_SEQ_FRAG(sc);
        seq = WLAN_GET_SEQ_SEQ(sc);
-       //cosa add 04292008 to record the sequence number
-       pcurrent_stats->Seq_Num = seq;
+
        //
        // Check whether we should take the previous packet into accounting
        //
@@ -4377,9 +3775,9 @@ static void rtl8192_process_phyinfo(struct r8192_priv * priv, u8* buffer,struct
        {
                for (rfpath = RF90_PATH_A; rfpath < RF90_PATH_C; rfpath++)
                {
-                       if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath))
+                       if (!rtl8192_phy_CheckIsLegalRFPath(priv, rfpath))
                                continue;
-                       RT_TRACE(COMP_DBG,"Jacken -> pPreviousstats->RxMIMOSignalStrength[rfpath]  = %d \n" ,pprevious_stats->RxMIMOSignalStrength[rfpath] );
+                       RT_TRACE(COMP_DBG, "pPreviousstats->RxMIMOSignalStrength[rfpath] = %d\n", pprevious_stats->RxMIMOSignalStrength[rfpath]);
                        //Fixed by Jacken 2008-03-20
                        if(priv->stats.rx_rssi_percentage[rfpath] == 0)
                        {
@@ -4398,7 +3796,7 @@ static void rtl8192_process_phyinfo(struct r8192_priv * priv, u8* buffer,struct
                                        ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) +
                                        (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor);
                        }
-                       RT_TRACE(COMP_DBG,"Jacken -> priv->RxStats.RxRSSIPercentage[rfPath]  = %d \n" ,priv->stats.rx_rssi_percentage[rfpath] );
+                       RT_TRACE(COMP_DBG, "priv->RxStats.RxRSSIPercentage[rfPath] = %d \n" , priv->stats.rx_rssi_percentage[rfpath]);
                }
        }
 
@@ -4629,7 +4027,7 @@ static void rtl8192_query_rxphystatus(
        /*2007.08.30 requested by SD3 Jerry */
        if (priv->phy_check_reg824 == 0)
        {
-               priv->phy_reg824_bit9 = rtl8192_QueryBBReg(priv->ieee80211->dev, rFPGA0_XA_HSSIParameter2, 0x200);
+               priv->phy_reg824_bit9 = rtl8192_QueryBBReg(priv, rFPGA0_XA_HSSIParameter2, 0x200);
                priv->phy_check_reg824 = 1;
        }
 
@@ -4838,19 +4236,17 @@ rtl8192_record_rxdesc_forlateruse(
 {
        ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU;
        ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU;
-       //ptarget_stats->Seq_Num = psrc_stats->Seq_Num;
 }
 
 
 
-static void TranslateRxSignalStuff819xpci(struct net_device *dev,
+static void TranslateRxSignalStuff819xpci(struct r8192_priv *priv,
         struct sk_buff *skb,
         struct ieee80211_rx_stats * pstats,
         prx_desc_819x_pci pdesc,
         prx_fwinfo_819x_pci pdrvinfo)
 {
     // TODO: We must only check packet for current MAC address. Not finish
-    struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
     bool bpacket_match_bssid, bpacket_toself;
     bool bPacketBeacon=false, bToSelfBA=false;
     struct ieee80211_hdr_3addr *hdr;
@@ -4881,7 +4277,7 @@ static void TranslateRxSignalStuff819xpci(struct net_device *dev,
     }
     if(WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK)
     {
-        if((!compare_ether_addr(praddr,dev->dev_addr)))
+        if (!compare_ether_addr(praddr, priv->ieee80211->dev->dev_addr))
             bToSelfBA = true;
     }
 
@@ -4898,20 +4294,20 @@ static void TranslateRxSignalStuff819xpci(struct net_device *dev,
 }
 
 
-static void rtl8192_tx_resume(struct net_device *dev)
+static void rtl8192_tx_resume(struct r8192_priv *priv)
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct ieee80211_device *ieee = priv->ieee80211;
+       struct net_device *dev = priv->ieee80211->dev;
        struct sk_buff *skb;
-       int queue_index;
+       int i;
 
-       for(queue_index = BK_QUEUE; queue_index < TXCMD_QUEUE;queue_index++) {
-               while((!skb_queue_empty(&ieee->skb_waitQ[queue_index]))&&
-                               (priv->ieee80211->check_nic_enough_desc(dev,queue_index) > 0)) {
+       for (i = BK_QUEUE; i < TXCMD_QUEUE; i++) {
+               while ((!skb_queue_empty(&ieee->skb_waitQ[i])) &&
+                      (priv->ieee80211->check_nic_enough_desc(dev, i) > 0)) {
                        /* 1. dequeue the packet from the wait queue */
-                       skb = skb_dequeue(&ieee->skb_waitQ[queue_index]);
+                       skb = skb_dequeue(&ieee->skb_waitQ[i]);
                        /* 2. tx the packet directly */
-                       ieee->softmac_data_hard_start_xmit(skb,dev,0/* rate useless now*/);
+                       ieee->softmac_data_hard_start_xmit(skb, ieee, 0);
                }
        }
 }
@@ -4935,16 +4331,15 @@ static void rtl8192_irq_tx_tasklet(unsigned long arg)
 
        spin_unlock_irqrestore(&priv->irq_th_lock, flags);
 
-       rtl8192_tx_resume(dev);
+       rtl8192_tx_resume(priv);
 }
 
 /* Record the received data rate */
 static void UpdateReceivedRateHistogramStatistics8190(
-       struct net_device *dev,
+       struct r8192_priv *priv,
        struct ieee80211_rx_stats* pstats
        )
 {
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        u32 rcvType=1;   //0: Total, 1:OK, 2:CRC, 3:ICV
        u32 rateIndex;
        u32 preamble_guardinterval;  //1: short preamble/GI, 0: long preamble/GI
@@ -5004,9 +4399,8 @@ static void UpdateReceivedRateHistogramStatistics8190(
        priv->stats.received_rate_histogram[rcvType][rateIndex]++;
 }
 
-static void rtl8192_rx(struct net_device *dev)
+static void rtl8192_rx(struct r8192_priv *priv)
 {
-    struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
     struct ieee80211_hdr_1addr *ieee80211_hdr = NULL;
     bool unicast_packet = false;
     struct ieee80211_rx_stats stats = {
@@ -5063,7 +4457,7 @@ static void rtl8192_rx(struct net_device *dev)
                 /* it is debug only. It should be disabled in released driver.
                  * 2007.1.11 by Emily
                  * */
-                UpdateReceivedRateHistogramStatistics8190(dev, &stats);
+                UpdateReceivedRateHistogramStatistics8190(priv, &stats);
 
                 stats.bIsAMPDU = (pDrvInfo->PartAggr==1);
                 stats.bFirstMPDU = (pDrvInfo->PartAggr==1) && (pDrvInfo->FirstAGGR==1);
@@ -5071,7 +4465,7 @@ static void rtl8192_rx(struct net_device *dev)
                 stats.TimeStampLow = pDrvInfo->TSFL;
                 stats.TimeStampHigh = read_nic_dword(priv, TSFR+4);
 
-                UpdateRxPktTimeStamp8190(dev, &stats);
+                UpdateRxPktTimeStamp8190(priv, &stats);
 
                 //
                 // Get Total offset of MPDU Frame Body
@@ -5079,10 +4473,8 @@ static void rtl8192_rx(struct net_device *dev)
                 if((stats.RxBufShift + stats.RxDrvInfoSize) > 0)
                     stats.bShift = 1;
 
-                stats.RxIs40MHzPacket = pDrvInfo->BW;
-
                 /* ???? */
-                TranslateRxSignalStuff819xpci(dev,skb, &stats, pdesc, pDrvInfo);
+                TranslateRxSignalStuff819xpci(priv, skb, &stats, pdesc, pDrvInfo);
 
                 /* Rx A-MPDU */
                 if(pDrvInfo->FirstAGGR==1 || pDrvInfo->PartAggr == 1)
@@ -5102,11 +4494,6 @@ static void rtl8192_rx(struct net_device *dev)
                     unicast_packet = true;
                 }
 
-                stats.packetlength = stats.Length-4;
-                stats.fraglength = stats.packetlength;
-                stats.fragoffset = 0;
-                stats.ntotalfrag = 1;
-
                 if(!ieee80211_rtl_rx(priv->ieee80211, skb, &stats)){
                     dev_kfree_skb_any(skb);
                 } else {
@@ -5137,7 +4524,7 @@ done:
 static void rtl8192_irq_rx_tasklet(unsigned long arg)
 {
        struct r8192_priv *priv = (struct r8192_priv*) arg;
-       rtl8192_rx(priv->ieee80211->dev);
+       rtl8192_rx(priv);
        /* unmask RDU */
        write_nic_dword(priv, INTA_MASK, read_nic_dword(priv, INTA_MASK) | IMR_RDU);
 }
@@ -5155,19 +4542,13 @@ static const struct net_device_ops rtl8192_netdev_ops = {
 static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
                         const struct pci_device_id *id)
 {
-       unsigned long ioaddr = 0;
        struct net_device *dev = NULL;
        struct r8192_priv *priv= NULL;
        u8 unit = 0;
        int ret = -ENODEV;
-
-#ifdef CONFIG_RTL8192_IO_MAP
-       unsigned long pio_start, pio_len, pio_flags;
-#else
        unsigned long pmem_start, pmem_len, pmem_flags;
-#endif //end #ifdef RTL_IO_MAP
 
-       RT_TRACE(COMP_INIT,"Configuring chip resources");
+       RT_TRACE(COMP_INIT,"Configuring chip resources\n");
 
        if( pci_enable_device (pdev) ){
                RT_TRACE(COMP_ERR,"Failed to enable PCI device");
@@ -5196,55 +4577,30 @@ static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
                priv->ieee80211->bSupportRemoteWakeUp = 0;
        }
 
-#ifdef CONFIG_RTL8192_IO_MAP
-
-       pio_start = (unsigned long)pci_resource_start (pdev, 0);
-       pio_len = (unsigned long)pci_resource_len (pdev, 0);
-       pio_flags = (unsigned long)pci_resource_flags (pdev, 0);
-
-       if (!(pio_flags & IORESOURCE_IO)) {
-               RT_TRACE(COMP_ERR,"region #0 not a PIO resource, aborting");
-               goto fail;
-       }
-
-       //DMESG("IO space @ 0x%08lx", pio_start );
-       if( ! request_region( pio_start, pio_len, RTL819xE_MODULE_NAME ) ){
-               RT_TRACE(COMP_ERR,"request_region failed!");
-               goto fail;
-       }
-
-       ioaddr = pio_start;
-       dev->base_addr = ioaddr; // device I/O address
-
-#else
-
        pmem_start = pci_resource_start(pdev, 1);
        pmem_len = pci_resource_len(pdev, 1);
        pmem_flags = pci_resource_flags (pdev, 1);
 
        if (!(pmem_flags & IORESOURCE_MEM)) {
-               RT_TRACE(COMP_ERR,"region #1 not a MMIO resource, aborting");
+               RT_TRACE(COMP_ERR, "region #1 not a MMIO resource, aborting\n");
                goto fail;
        }
 
        //DMESG("Memory mapped space @ 0x%08lx ", pmem_start);
        if( ! request_mem_region(pmem_start, pmem_len, RTL819xE_MODULE_NAME)) {
-               RT_TRACE(COMP_ERR,"request_mem_region failed!");
+               RT_TRACE(COMP_ERR,"request_mem_region failed!\n");
                goto fail;
        }
 
-
-       ioaddr = (unsigned long)ioremap_nocache( pmem_start, pmem_len);
-       if( ioaddr == (unsigned long)NULL ){
-               RT_TRACE(COMP_ERR,"ioremap failed!");
-              // release_mem_region( pmem_start, pmem_len );
+       priv->mem_start = ioremap_nocache(pmem_start, pmem_len);
+       if (!priv->mem_start) {
+               RT_TRACE(COMP_ERR,"ioremap failed!\n");
                goto fail1;
        }
 
-       dev->mem_start = ioaddr; // shared mem start
-       dev->mem_end = ioaddr + pci_resource_len(pdev, 0); // shared mem end
-
-#endif //end #ifdef RTL_IO_MAP
+       dev->mem_start = (unsigned long) priv->mem_start;
+       dev->mem_end = (unsigned long) (priv->mem_start +
+                                       pci_resource_len(pdev, 0));
 
         /* We disable the RETRY_TIMEOUT register (0x41) to keep
          * PCI Tx retries from interfering with C3 CPU state */
@@ -5271,14 +4627,14 @@ static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
         }
 
        RT_TRACE(COMP_INIT, "Driver probe completed1\n");
-       if(rtl8192_init(dev)!=0){
-               RT_TRACE(COMP_ERR, "Initialization failed");
+       if (rtl8192_init(priv)!=0) {
+               RT_TRACE(COMP_ERR, "Initialization failed\n");
                goto fail;
        }
 
        register_netdev(dev);
        RT_TRACE(COMP_INIT, "dev name=======> %s\n",dev->name);
-       rtl8192_proc_init_one(dev);
+       rtl8192_proc_init_one(priv);
 
 
        RT_TRACE(COMP_INIT, "Driver probe completed\n");
@@ -5286,20 +4642,11 @@ static int __devinit rtl8192_pci_probe(struct pci_dev *pdev,
 
 fail1:
 
-#ifdef CONFIG_RTL8180_IO_MAP
-
-       if( dev->base_addr != 0 ){
-
-               release_region(dev->base_addr,
-              pci_resource_len(pdev, 0) );
-       }
-#else
-       if( dev->mem_start != (unsigned long)NULL ){
-               iounmap( (void *)dev->mem_start );
+       if (priv->mem_start) {
+               iounmap(priv->mem_start);
                release_mem_region( pci_resource_start(pdev, 1),
                                    pci_resource_len(pdev, 1) );
        }
-#endif //end #ifdef RTL_IO_MAP
 
 fail:
        if(dev){
@@ -5333,13 +4680,9 @@ static void rtl8192_cancel_deferred_work(struct r8192_priv* priv)
        cancel_delayed_work(&priv->watch_dog_wq);
        cancel_delayed_work(&priv->update_beacon_wq);
        cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq);
-       cancel_delayed_work(&priv->ieee80211->hw_sleep_wq);
        cancel_delayed_work(&priv->gpio_change_rf_wq);
        cancel_work_sync(&priv->reset_wq);
        cancel_work_sync(&priv->qos_activate);
-       //cancel_work_sync(&priv->SetBWModeWorkItem);
-       //cancel_work_sync(&priv->SwChnlWorkItem);
-
 }
 
 
@@ -5355,7 +4698,7 @@ static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev)
 
                priv = ieee80211_priv(dev);
 
-               rtl8192_proc_remove_one(dev);
+               rtl8192_proc_remove_one(priv);
 
                rtl8192_down(dev);
                if (priv->pFirmware)
@@ -5366,9 +4709,9 @@ static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev)
                destroy_workqueue(priv->priv_wq);
 
                /* free tx/rx rings */
-               rtl8192_free_rx_ring(dev);
+               rtl8192_free_rx_ring(priv);
                for (i = 0; i < MAX_TX_QUEUE_COUNT; i++)
-                       rtl8192_free_tx_ring(dev, i);
+                       rtl8192_free_tx_ring(priv, i);
 
                if (priv->irq) {
                        printk("Freeing irq %d\n",dev->irq);
@@ -5376,22 +4719,13 @@ static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev)
                        priv->irq=0;
                }
 
-#ifdef CONFIG_RTL8180_IO_MAP
-
-               if( dev->base_addr != 0 ){
-
-                       release_region(dev->base_addr,
-                                      pci_resource_len(pdev, 0) );
-               }
-#else
-               if( dev->mem_start != (unsigned long)NULL ){
-                       iounmap( (void *)dev->mem_start );
+               if (priv->mem_start) {
+                       iounmap(priv->mem_start);
                        release_mem_region( pci_resource_start(pdev, 1),
                                            pci_resource_len(pdev, 1) );
                }
-#endif /*end #ifdef RTL_IO_MAP*/
-               free_ieee80211(dev);
 
+               free_ieee80211(dev);
        }
 
        pci_disable_device(pdev);
@@ -5411,7 +4745,7 @@ static int __init rtl8192_pci_module_init(void)
 
        printk(KERN_INFO "\nLinux kernel driver for RTL8192 based WLAN cards\n");
        printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan\n");
-       RT_TRACE(COMP_INIT, "Initializing module");
+       RT_TRACE(COMP_INIT, "Initializing module\n");
        rtl8192_proc_module_init();
       if(0!=pci_register_driver(&rtl8192_pci_driver))
        {
@@ -5427,7 +4761,7 @@ static void __exit rtl8192_pci_module_exit(void)
 {
        pci_unregister_driver(&rtl8192_pci_driver);
 
-       RT_TRACE(COMP_DOWN, "Exiting");
+       RT_TRACE(COMP_DOWN, "Exiting\n");
        rtl8192_proc_module_remove();
        ieee80211_rtl_exit();
 }
@@ -5442,10 +4776,6 @@ static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
 
        spin_lock_irqsave(&priv->irq_th_lock, flags);
 
-       /* We should return IRQ_NONE, but for now let me keep this */
-       if (priv->irq_enabled == 0)
-               goto out_unlock;
-
        /* ISR: 4bytes */
 
        inta = read_nic_dword(priv, ISR); /* & priv->IntrMask; */
@@ -5469,26 +4799,26 @@ static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
 
        if (inta & IMR_TBDOK) {
                RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
-               rtl8192_tx_isr(dev, BEACON_QUEUE);
+               rtl8192_tx_isr(priv, BEACON_QUEUE);
                priv->stats.txbeaconokint++;
        }
 
        if (inta & IMR_TBDER) {
                RT_TRACE(COMP_INTR, "beacon ok interrupt!\n");
-               rtl8192_tx_isr(dev, BEACON_QUEUE);
+               rtl8192_tx_isr(priv, BEACON_QUEUE);
                priv->stats.txbeaconerr++;
        }
 
        if (inta & IMR_MGNTDOK ) {
                RT_TRACE(COMP_INTR, "Manage ok interrupt!\n");
                priv->stats.txmanageokint++;
-               rtl8192_tx_isr(dev,MGNT_QUEUE);
+               rtl8192_tx_isr(priv, MGNT_QUEUE);
        }
 
        if (inta & IMR_COMDOK)
        {
                priv->stats.txcmdpktokint++;
-               rtl8192_tx_isr(dev, TXCMD_QUEUE);
+               rtl8192_tx_isr(priv, TXCMD_QUEUE);
        }
 
        if (inta & IMR_ROK) {
@@ -5522,27 +4852,27 @@ static irqreturn_t rtl8192_interrupt(int irq, void *netdev)
                RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n");
                priv->stats.txbkokint++;
                priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
-               rtl8192_tx_isr(dev, BK_QUEUE);
+               rtl8192_tx_isr(priv, BK_QUEUE);
        }
 
        if (inta & IMR_BEDOK) {
                RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n");
                priv->stats.txbeokint++;
                priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
-               rtl8192_tx_isr(dev, BE_QUEUE);
+               rtl8192_tx_isr(priv, BE_QUEUE);
        }
 
        if (inta & IMR_VIDOK) {
                RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n");
                priv->stats.txviokint++;
                priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
-               rtl8192_tx_isr(dev, VI_QUEUE);
+               rtl8192_tx_isr(priv, VI_QUEUE);
        }
 
        if (inta & IMR_VODOK) {
                priv->stats.txvookint++;
                priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++;
-               rtl8192_tx_isr(dev, VO_QUEUE);
+               rtl8192_tx_isr(priv, VO_QUEUE);
        }
 
 out_unlock:
@@ -5551,10 +4881,9 @@ out_unlock:
        return ret;
 }
 
-void EnableHWSecurityConfig8192(struct net_device *dev)
+void EnableHWSecurityConfig8192(struct r8192_priv *priv)
 {
         u8 SECR_value = 0x0;
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        struct ieee80211_device* ieee = priv->ieee80211;
 
        SECR_value = SCR_TxEncEnable | SCR_RxDecEnable;
@@ -5589,25 +4918,20 @@ void EnableHWSecurityConfig8192(struct net_device *dev)
 }
 #define TOTAL_CAM_ENTRY 32
 //#define CAM_CONTENT_COUNT 8
-void setKey(   struct net_device *dev,
-               u8 EntryNo,
-               u8 KeyIndex,
-               u16 KeyType,
-               const u8 *MacAddr,
-               u8 DefaultKey,
-               u32 *KeyContent )
+void setKey(struct r8192_priv *priv, u8 EntryNo, u8 KeyIndex, u16 KeyType,
+           const u8 *MacAddr, u8 DefaultKey, u32 *KeyContent)
 {
        u32 TargetCommand = 0;
        u32 TargetContent = 0;
        u16 usConfig = 0;
        u8 i;
 #ifdef ENABLE_IPS
-       struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
        RT_RF_POWER_STATE       rtState;
-       rtState = priv->ieee80211->eRFPowerState;
-       if(priv->ieee80211->PowerSaveControl.bInactivePs){
+
+       rtState = priv->eRFPowerState;
+       if (priv->PowerSaveControl.bInactivePs){
                if(rtState == eRfOff){
-                       if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_IPS)
+                       if(priv->RfOffReason > RF_CHANGE_BY_IPS)
                        {
                                RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__);
                                //up(&priv->wx_sem);
@@ -5615,7 +4939,7 @@ void setKey(      struct net_device *dev,
                        }
                        else{
                                down(&priv->ieee80211->ips_sem);
-                               IPSLeave(dev);
+                               IPSLeave(priv);
                                up(&priv->ieee80211->ips_sem);
                        }
                }
@@ -5625,7 +4949,7 @@ void setKey(      struct net_device *dev,
        if (EntryNo >= TOTAL_CAM_ENTRY)
                RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n");
 
-       RT_TRACE(COMP_SEC, "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", dev,EntryNo, KeyIndex, KeyType, MacAddr);
+       RT_TRACE(COMP_SEC, "====>to setKey(), priv:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", priv, EntryNo, KeyIndex, KeyType, MacAddr);
 
        if (DefaultKey)
                usConfig |= BIT15 | (KeyType<<2);
@@ -5665,11 +4989,10 @@ void setKey(    struct net_device *dev,
        RT_TRACE(COMP_SEC,"=========>after set key, usconfig:%x\n", usConfig);
 }
 
-bool NicIFEnableNIC(struct net_device* dev)
+bool NicIFEnableNIC(struct r8192_priv *priv)
 {
        RT_STATUS init_status = RT_STATUS_SUCCESS;
-       struct r8192_priv* priv = ieee80211_priv(dev);
-       PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl));
+       PRT_POWER_SAVE_CONTROL pPSC = &priv->PowerSaveControl;
 
        //YJ,add,091109
        if (priv->up == 0){
@@ -5682,7 +5005,7 @@ bool NicIFEnableNIC(struct net_device* dev)
 
        // <2> Enable Adapter
        //priv->bfirst_init = true;
-       init_status = rtl8192_adapter_start(dev);
+       init_status = rtl8192_adapter_start(priv);
        if (init_status != RT_STATUS_SUCCESS) {
                RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__);
                priv->bdisable_nic = false;  //YJ,add,091111
@@ -5692,16 +5015,15 @@ bool NicIFEnableNIC(struct net_device* dev)
        //priv->bfirst_init = false;
 
        // <3> Enable Interrupt
-       rtl8192_irq_enable(dev);
+       rtl8192_irq_enable(priv);
        priv->bdisable_nic = false;
 
        return (init_status == RT_STATUS_SUCCESS);
 }
 
-bool NicIFDisableNIC(struct net_device* dev)
+bool NicIFDisableNIC(struct r8192_priv *priv)
 {
        bool    status = true;
-       struct r8192_priv* priv = ieee80211_priv(dev);
        u8 tmp_state = 0;
        // <1> Disable Interrupt
 
@@ -5712,11 +5034,11 @@ bool NicIFDisableNIC(struct net_device* dev)
 
        priv->ieee80211->state = tmp_state;
        rtl8192_cancel_deferred_work(priv);
-       rtl8192_irq_disable(dev);
+       rtl8192_irq_disable(priv);
        // <2> Stop all timer
 
        // <3> Disable Adapter
-       rtl8192_halt_adapter(dev, false);
+       rtl8192_halt_adapter(priv, false);
 //     priv->bdisable_nic = true;
 
        return status;
This page took 0.070346 seconds and 5 git commands to generate.