Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved. |
| 3 | * Linux device driver for RTL8190P / RTL8192E |
| 4 | * |
| 5 | * Based on the r8180 driver, which is: |
| 6 | * Copyright 2004-2005 Andrea Merello <andreamrl@tiscali.it>, et al. |
| 7 | * This program is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of version 2 of the GNU General Public License as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | * more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 19 | * |
| 20 | * The full GNU General Public License is included in this distribution in the |
| 21 | * file called LICENSE. |
| 22 | * |
| 23 | * Contact Information: |
| 24 | * Jerry chuang <wlanfae@realtek.com> |
| 25 | */ |
| 26 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 27 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 28 | #undef RX_DONT_PASS_UL |
| 29 | #undef DEBUG_EPROM |
| 30 | #undef DEBUG_RX_VERBOSE |
| 31 | #undef DUMMY_RX |
| 32 | #undef DEBUG_ZERO_RX |
| 33 | #undef DEBUG_RX_SKB |
| 34 | #undef DEBUG_TX_FRAG |
| 35 | #undef DEBUG_RX_FRAG |
| 36 | #undef DEBUG_TX_FILLDESC |
| 37 | #undef DEBUG_TX |
| 38 | #undef DEBUG_IRQ |
| 39 | #undef DEBUG_RX |
| 40 | #undef DEBUG_RXALLOC |
| 41 | #undef DEBUG_REGISTERS |
| 42 | #undef DEBUG_RING |
| 43 | #undef DEBUG_IRQ_TASKLET |
| 44 | #undef DEBUG_TX_ALLOC |
| 45 | #undef DEBUG_TX_DESC |
| 46 | |
| 47 | //#define CONFIG_RTL8192_IO_MAP |
Jeff Mahoney | 3d14b51 | 2009-10-08 17:30:40 -0400 | [diff] [blame] | 48 | #include <linux/vmalloc.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 49 | #include <linux/slab.h> |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 50 | #include <asm/uaccess.h> |
| 51 | #include "r8192E_hw.h" |
| 52 | #include "r8192E.h" |
| 53 | #include "r8190_rtl8256.h" /* RTL8225 Radio frontend */ |
| 54 | #include "r8180_93cx6.h" /* Card EEPROM */ |
| 55 | #include "r8192E_wx.h" |
| 56 | #include "r819xE_phy.h" //added by WB 4.30.2008 |
| 57 | #include "r819xE_phyreg.h" |
| 58 | #include "r819xE_cmdpkt.h" |
| 59 | #include "r8192E_dm.h" |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 60 | |
Yong Wang | bebdf80 | 2010-04-23 16:26:42 +0800 | [diff] [blame] | 61 | #ifdef CONFIG_PM |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 62 | #include "r8192_pm.h" |
| 63 | #endif |
| 64 | |
| 65 | #ifdef ENABLE_DOT11D |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 66 | #include "ieee80211/dot11d.h" |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 67 | #endif |
| 68 | |
| 69 | //set here to open your trace code. //WB |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 70 | u32 rt_global_debug_component = |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 71 | // COMP_INIT | |
| 72 | // COMP_EPROM | |
| 73 | // COMP_PHY | |
| 74 | // COMP_RF | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 75 | // COMP_FIRMWARE | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 76 | // COMP_TRACE | |
| 77 | // COMP_DOWN | |
| 78 | // COMP_SWBW | |
| 79 | // COMP_SEC | |
| 80 | // COMP_QOS | |
| 81 | // COMP_RATE | |
| 82 | // COMP_RECV | |
| 83 | // COMP_SEND | |
| 84 | // COMP_POWER | |
| 85 | // COMP_EVENTS | |
| 86 | // COMP_RESET | |
| 87 | // COMP_CMDPKT | |
| 88 | // COMP_POWER_TRACKING | |
| 89 | // COMP_INTR | |
| 90 | COMP_ERR ; //always open err flags on |
Mike McCormack | cf3d3d3 | 2010-07-26 22:58:26 +0900 | [diff] [blame] | 91 | |
Mike McCormack | 881a975 | 2010-07-26 22:58:03 +0900 | [diff] [blame] | 92 | static const struct pci_device_id rtl8192_pci_id_tbl[] __devinitdata = { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 93 | #ifdef RTL8190P |
| 94 | /* Realtek */ |
| 95 | /* Dlink */ |
| 96 | { PCI_DEVICE(0x10ec, 0x8190) }, |
| 97 | /* Corega */ |
| 98 | { PCI_DEVICE(0x07aa, 0x0045) }, |
| 99 | { PCI_DEVICE(0x07aa, 0x0046) }, |
| 100 | #else |
| 101 | /* Realtek */ |
| 102 | { PCI_DEVICE(0x10ec, 0x8192) }, |
| 103 | |
| 104 | /* Corega */ |
| 105 | { PCI_DEVICE(0x07aa, 0x0044) }, |
| 106 | { PCI_DEVICE(0x07aa, 0x0047) }, |
| 107 | #endif |
| 108 | {} |
| 109 | }; |
| 110 | |
Rusty Russell | dca4130 | 2010-08-11 23:04:21 -0600 | [diff] [blame] | 111 | static char ifname[IFNAMSIZ] = "wlan%d"; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 112 | static int hwwep = 1; //default use hw. set 0 to use software security |
| 113 | static int channels = 0x3fff; |
| 114 | |
| 115 | MODULE_LICENSE("GPL"); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 116 | MODULE_VERSION("V 1.1"); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 117 | MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl); |
| 118 | //MODULE_AUTHOR("Andrea Merello <andreamrl@tiscali.it>"); |
| 119 | MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards"); |
| 120 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 121 | |
Rusty Russell | dca4130 | 2010-08-11 23:04:21 -0600 | [diff] [blame] | 122 | module_param_string(ifname, ifname, sizeof(ifname), S_IRUGO|S_IWUSR); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 123 | module_param(hwwep,int, S_IRUGO|S_IWUSR); |
| 124 | module_param(channels,int, S_IRUGO|S_IWUSR); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 125 | |
| 126 | MODULE_PARM_DESC(ifname," Net interface name, wlan%d=default"); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 127 | MODULE_PARM_DESC(hwwep," Try to use hardware WEP support. Still broken and not available on all cards"); |
| 128 | MODULE_PARM_DESC(channels," Channel bitmask for specific locales. NYI"); |
| 129 | |
| 130 | static int __devinit rtl8192_pci_probe(struct pci_dev *pdev, |
| 131 | const struct pci_device_id *id); |
| 132 | static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev); |
| 133 | |
| 134 | static struct pci_driver rtl8192_pci_driver = { |
| 135 | .name = RTL819xE_MODULE_NAME, /* Driver name */ |
| 136 | .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */ |
| 137 | .probe = rtl8192_pci_probe, /* probe fn */ |
| 138 | .remove = __devexit_p(rtl8192_pci_disconnect), /* remove fn */ |
Yong Wang | bebdf80 | 2010-04-23 16:26:42 +0800 | [diff] [blame] | 139 | #ifdef CONFIG_PM |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 140 | .suspend = rtl8192E_suspend, /* PM suspend fn */ |
| 141 | .resume = rtl8192E_resume, /* PM resume fn */ |
| 142 | #else |
| 143 | .suspend = NULL, /* PM suspend fn */ |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 144 | .resume = NULL, /* PM resume fn */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 145 | #endif |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Mike McCormack | 559fba5 | 2010-07-26 22:57:52 +0900 | [diff] [blame] | 148 | static void rtl8192_start_beacon(struct net_device *dev); |
| 149 | static void rtl8192_stop_beacon(struct net_device *dev); |
| 150 | static void rtl819x_watchdog_wqcallback(struct work_struct *work); |
| 151 | static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv); |
| 152 | static void rtl8192_irq_tx_tasklet(struct r8192_priv *priv); |
| 153 | static void rtl8192_prepare_beacon(struct r8192_priv *priv); |
| 154 | static irqreturn_t rtl8192_interrupt(int irq, void *netdev); |
| 155 | static void rtl8192_try_wake_queue(struct net_device *dev, int pri); |
Mike McCormack | 881a975 | 2010-07-26 22:58:03 +0900 | [diff] [blame] | 156 | static void rtl819xE_tx_cmd(struct net_device *dev, struct sk_buff *skb); |
Mike McCormack | 5b3b1a7 | 2010-08-10 23:44:36 +0900 | [diff] [blame] | 157 | static void rtl8192_update_ratr_table(struct net_device* dev); |
| 158 | static void rtl8192_restart(struct work_struct *work); |
| 159 | static void watch_dog_timer_callback(unsigned long data); |
| 160 | static int _rtl8192_up(struct net_device *dev); |
| 161 | static void rtl8192_cancel_deferred_work(struct r8192_priv* priv); |
Mike McCormack | 559fba5 | 2010-07-26 22:57:52 +0900 | [diff] [blame] | 162 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 163 | #ifdef ENABLE_DOT11D |
| 164 | |
| 165 | typedef struct _CHANNEL_LIST |
| 166 | { |
| 167 | u8 Channel[32]; |
| 168 | u8 Len; |
| 169 | }CHANNEL_LIST, *PCHANNEL_LIST; |
| 170 | |
Mike McCormack | ab2161a | 2010-07-26 22:57:24 +0900 | [diff] [blame] | 171 | static const CHANNEL_LIST ChannelPlan[] = { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 172 | {{1,2,3,4,5,6,7,8,9,10,11,36,40,44,48,52,56,60,64,149,153,157,161,165},24}, //FCC |
| 173 | {{1,2,3,4,5,6,7,8,9,10,11},11}, //IC |
| 174 | {{1,2,3,4,5,6,7,8,9,10,11,12,13,36,40,44,48,52,56,60,64},21}, //ETSI |
| 175 | {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Spain. Change to ETSI. |
| 176 | {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //France. Change to ETSI. |
| 177 | {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22}, //MKK //MKK |
| 178 | {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22},//MKK1 |
| 179 | {{1,2,3,4,5,6,7,8,9,10,11,12,13},13}, //Israel. |
| 180 | {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64},22}, // For 11a , TELEC |
| 181 | {{1,2,3,4,5,6,7,8,9,10,11,12,13,14,36,40,44,48,52,56,60,64}, 22}, //MIC |
| 182 | {{1,2,3,4,5,6,7,8,9,10,11,12,13,14},14} //For Global Domain. 1-11:active scan, 12-14 passive scan. //+YJ, 080626 |
| 183 | }; |
| 184 | |
| 185 | static void rtl819x_set_channel_map(u8 channel_plan, struct r8192_priv* priv) |
| 186 | { |
| 187 | int i, max_chan=-1, min_chan=-1; |
| 188 | struct ieee80211_device* ieee = priv->ieee80211; |
| 189 | switch (channel_plan) |
| 190 | { |
| 191 | case COUNTRY_CODE_FCC: |
| 192 | case COUNTRY_CODE_IC: |
| 193 | case COUNTRY_CODE_ETSI: |
| 194 | case COUNTRY_CODE_SPAIN: |
| 195 | case COUNTRY_CODE_FRANCE: |
| 196 | case COUNTRY_CODE_MKK: |
| 197 | case COUNTRY_CODE_MKK1: |
| 198 | case COUNTRY_CODE_ISRAEL: |
| 199 | case COUNTRY_CODE_TELEC: |
| 200 | case COUNTRY_CODE_MIC: |
| 201 | { |
| 202 | Dot11d_Init(ieee); |
| 203 | ieee->bGlobalDomain = false; |
| 204 | //acturally 8225 & 8256 rf chip only support B,G,24N mode |
| 205 | if ((priv->rf_chip == RF_8225) || (priv->rf_chip == RF_8256)) |
| 206 | { |
| 207 | min_chan = 1; |
| 208 | max_chan = 14; |
| 209 | } |
| 210 | else |
| 211 | { |
| 212 | RT_TRACE(COMP_ERR, "unknown rf chip, can't set channel map in function:%s()\n", __FUNCTION__); |
| 213 | } |
| 214 | if (ChannelPlan[channel_plan].Len != 0){ |
| 215 | // Clear old channel map |
| 216 | memset(GET_DOT11D_INFO(ieee)->channel_map, 0, sizeof(GET_DOT11D_INFO(ieee)->channel_map)); |
| 217 | // Set new channel map |
| 218 | for (i=0;i<ChannelPlan[channel_plan].Len;i++) |
| 219 | { |
| 220 | if (ChannelPlan[channel_plan].Channel[i] < min_chan || ChannelPlan[channel_plan].Channel[i] > max_chan) |
| 221 | break; |
| 222 | GET_DOT11D_INFO(ieee)->channel_map[ChannelPlan[channel_plan].Channel[i]] = 1; |
| 223 | } |
| 224 | } |
| 225 | break; |
| 226 | } |
| 227 | case COUNTRY_CODE_GLOBAL_DOMAIN: |
| 228 | { |
| 229 | GET_DOT11D_INFO(ieee)->bEnabled = 0; //this flag enabled to follow 11d country IE setting, otherwise, it shall follow global domain setting |
| 230 | Dot11d_Reset(ieee); |
| 231 | ieee->bGlobalDomain = true; |
| 232 | break; |
| 233 | } |
| 234 | default: |
| 235 | break; |
| 236 | } |
| 237 | } |
| 238 | #endif |
| 239 | |
| 240 | |
| 241 | #define eqMacAddr(a,b) ( ((a)[0]==(b)[0] && (a)[1]==(b)[1] && (a)[2]==(b)[2] && (a)[3]==(b)[3] && (a)[4]==(b)[4] && (a)[5]==(b)[5]) ? 1:0 ) |
| 242 | /* 2007/07/25 MH Defien temp tx fw info. */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 243 | static TX_FWINFO_T Tmp_TxFwInfo; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 244 | |
| 245 | |
| 246 | #define rx_hal_is_cck_rate(_pdrvinfo)\ |
| 247 | (_pdrvinfo->RxRate == DESC90_RATE1M ||\ |
| 248 | _pdrvinfo->RxRate == DESC90_RATE2M ||\ |
| 249 | _pdrvinfo->RxRate == DESC90_RATE5_5M ||\ |
| 250 | _pdrvinfo->RxRate == DESC90_RATE11M) &&\ |
| 251 | !_pdrvinfo->RxHT\ |
| 252 | |
| 253 | |
| 254 | void CamResetAllEntry(struct net_device *dev) |
| 255 | { |
Mike McCormack | c325d98 | 2010-09-20 23:12:29 +0900 | [diff] [blame] | 256 | write_nic_dword(dev, RWCAM, BIT31|BIT30); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | |
| 260 | void write_cam(struct net_device *dev, u8 addr, u32 data) |
| 261 | { |
| 262 | write_nic_dword(dev, WCAMI, data); |
| 263 | write_nic_dword(dev, RWCAM, BIT31|BIT16|(addr&0xff) ); |
| 264 | } |
| 265 | u32 read_cam(struct net_device *dev, u8 addr) |
| 266 | { |
| 267 | write_nic_dword(dev, RWCAM, 0x80000000|(addr&0xff) ); |
| 268 | return read_nic_dword(dev, 0xa8); |
| 269 | } |
| 270 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 271 | #ifdef CONFIG_RTL8180_IO_MAP |
| 272 | |
| 273 | u8 read_nic_byte(struct net_device *dev, int x) |
| 274 | { |
| 275 | return 0xff&inb(dev->base_addr +x); |
| 276 | } |
| 277 | |
| 278 | u32 read_nic_dword(struct net_device *dev, int x) |
| 279 | { |
| 280 | return inl(dev->base_addr +x); |
| 281 | } |
| 282 | |
| 283 | u16 read_nic_word(struct net_device *dev, int x) |
| 284 | { |
| 285 | return inw(dev->base_addr +x); |
| 286 | } |
| 287 | |
| 288 | void write_nic_byte(struct net_device *dev, int x,u8 y) |
| 289 | { |
| 290 | outb(y&0xff,dev->base_addr +x); |
| 291 | } |
| 292 | |
| 293 | void write_nic_word(struct net_device *dev, int x,u16 y) |
| 294 | { |
| 295 | outw(y,dev->base_addr +x); |
| 296 | } |
| 297 | |
| 298 | void write_nic_dword(struct net_device *dev, int x,u32 y) |
| 299 | { |
| 300 | outl(y,dev->base_addr +x); |
| 301 | } |
| 302 | |
| 303 | #else /* RTL_IO_MAP */ |
| 304 | |
| 305 | u8 read_nic_byte(struct net_device *dev, int x) |
| 306 | { |
| 307 | return 0xff&readb((u8*)dev->mem_start +x); |
| 308 | } |
| 309 | |
| 310 | u32 read_nic_dword(struct net_device *dev, int x) |
| 311 | { |
| 312 | return readl((u8*)dev->mem_start +x); |
| 313 | } |
| 314 | |
| 315 | u16 read_nic_word(struct net_device *dev, int x) |
| 316 | { |
| 317 | return readw((u8*)dev->mem_start +x); |
| 318 | } |
| 319 | |
| 320 | void write_nic_byte(struct net_device *dev, int x,u8 y) |
| 321 | { |
| 322 | writeb(y,(u8*)dev->mem_start +x); |
| 323 | udelay(20); |
| 324 | } |
| 325 | |
| 326 | void write_nic_dword(struct net_device *dev, int x,u32 y) |
| 327 | { |
| 328 | writel(y,(u8*)dev->mem_start +x); |
| 329 | udelay(20); |
| 330 | } |
| 331 | |
| 332 | void write_nic_word(struct net_device *dev, int x,u16 y) |
| 333 | { |
| 334 | writew(y,(u8*)dev->mem_start +x); |
| 335 | udelay(20); |
| 336 | } |
| 337 | |
| 338 | #endif /* RTL_IO_MAP */ |
| 339 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 340 | u8 rtl8192e_ap_sec_type(struct ieee80211_device *ieee) |
| 341 | { |
Mike McCormack | 4a53336 | 2010-07-26 22:57:35 +0900 | [diff] [blame] | 342 | static const u8 ccmp_ie[4] = {0x00,0x50,0xf2,0x04}; |
| 343 | static const u8 ccmp_rsn_ie[4] = {0x00, 0x0f, 0xac, 0x04}; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 344 | int wpa_ie_len= ieee->wpa_ie_len; |
| 345 | struct ieee80211_crypt_data* crypt; |
| 346 | int encrypt; |
| 347 | |
| 348 | crypt = ieee->crypt[ieee->tx_keyidx]; |
| 349 | |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 350 | encrypt = (ieee->current_network.capability & WLAN_CAPABILITY_PRIVACY) || |
| 351 | (ieee->host_encrypt && crypt && crypt->ops && |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 352 | (0 == strcmp(crypt->ops->name,"WEP"))); |
| 353 | |
| 354 | /* simply judge */ |
| 355 | if(encrypt && (wpa_ie_len == 0)) { |
| 356 | // wep encryption, no N mode setting */ |
| 357 | return SEC_ALG_WEP; |
| 358 | } else if((wpa_ie_len != 0)) { |
| 359 | // parse pairwise key type */ |
| 360 | if (((ieee->wpa_ie[0] == 0xdd) && (!memcmp(&(ieee->wpa_ie[14]),ccmp_ie,4))) || |
| 361 | ((ieee->wpa_ie[0] == 0x30) && (!memcmp(&ieee->wpa_ie[10],ccmp_rsn_ie, 4)))) |
| 362 | return SEC_ALG_CCMP; |
| 363 | else |
| 364 | return SEC_ALG_TKIP; |
| 365 | } else { |
| 366 | return SEC_ALG_NONE; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | void |
| 371 | rtl8192e_SetHwReg(struct net_device *dev,u8 variable,u8* val) |
| 372 | { |
| 373 | struct r8192_priv* priv = ieee80211_priv(dev); |
| 374 | |
| 375 | switch(variable) |
| 376 | { |
| 377 | |
| 378 | case HW_VAR_BSSID: |
| 379 | write_nic_dword(dev, BSSIDR, ((u32*)(val))[0]); |
| 380 | write_nic_word(dev, BSSIDR+2, ((u16*)(val+2))[0]); |
| 381 | break; |
| 382 | |
| 383 | case HW_VAR_MEDIA_STATUS: |
| 384 | { |
| 385 | RT_OP_MODE OpMode = *((RT_OP_MODE *)(val)); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 386 | u8 btMsr = read_nic_byte(dev, MSR); |
| 387 | |
| 388 | btMsr &= 0xfc; |
| 389 | |
| 390 | switch(OpMode) |
| 391 | { |
| 392 | case RT_OP_MODE_INFRASTRUCTURE: |
| 393 | btMsr |= MSR_INFRA; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 394 | break; |
| 395 | |
| 396 | case RT_OP_MODE_IBSS: |
| 397 | btMsr |= MSR_ADHOC; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 398 | break; |
| 399 | |
| 400 | case RT_OP_MODE_AP: |
| 401 | btMsr |= MSR_AP; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 402 | break; |
| 403 | |
| 404 | default: |
| 405 | btMsr |= MSR_NOLINK; |
| 406 | break; |
| 407 | } |
| 408 | |
| 409 | write_nic_byte(dev, MSR, btMsr); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 410 | } |
| 411 | break; |
| 412 | |
| 413 | case HW_VAR_CECHK_BSSID: |
| 414 | { |
| 415 | u32 RegRCR, Type; |
| 416 | |
| 417 | Type = ((u8*)(val))[0]; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 418 | RegRCR = read_nic_dword(dev,RCR); |
| 419 | priv->ReceiveConfig = RegRCR; |
| 420 | |
| 421 | if (Type == true) |
| 422 | RegRCR |= (RCR_CBSSID); |
| 423 | else if (Type == false) |
| 424 | RegRCR &= (~RCR_CBSSID); |
| 425 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 426 | write_nic_dword(dev, RCR,RegRCR); |
| 427 | priv->ReceiveConfig = RegRCR; |
| 428 | |
| 429 | } |
| 430 | break; |
| 431 | |
| 432 | case HW_VAR_SLOT_TIME: |
| 433 | { |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 434 | priv->slot_time = val[0]; |
| 435 | write_nic_byte(dev, SLOT_TIME, val[0]); |
| 436 | |
| 437 | } |
| 438 | break; |
| 439 | |
| 440 | case HW_VAR_ACK_PREAMBLE: |
| 441 | { |
| 442 | u32 regTmp = 0; |
| 443 | priv->short_preamble = (bool)(*(u8*)val ); |
| 444 | regTmp = priv->basic_rate; |
| 445 | if (priv->short_preamble) |
| 446 | regTmp |= BRSR_AckShortPmb; |
| 447 | write_nic_dword(dev, RRSR, regTmp); |
| 448 | } |
| 449 | break; |
| 450 | |
| 451 | case HW_VAR_CPU_RST: |
| 452 | write_nic_dword(dev, CPU_GEN, ((u32*)(val))[0]); |
| 453 | break; |
| 454 | |
| 455 | default: |
| 456 | break; |
| 457 | } |
| 458 | |
| 459 | } |
| 460 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 461 | static struct proc_dir_entry *rtl8192_proc = NULL; |
| 462 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 463 | static int proc_get_stats_ap(char *page, char **start, |
| 464 | off_t offset, int count, |
| 465 | int *eof, void *data) |
| 466 | { |
| 467 | struct net_device *dev = data; |
| 468 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 469 | struct ieee80211_device *ieee = priv->ieee80211; |
| 470 | struct ieee80211_network *target; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 471 | int len = 0; |
| 472 | |
| 473 | list_for_each_entry(target, &ieee->network_list, list) { |
| 474 | |
| 475 | len += snprintf(page + len, count - len, |
| 476 | "%s ", target->ssid); |
| 477 | |
| 478 | if(target->wpa_ie_len>0 || target->rsn_ie_len>0){ |
| 479 | len += snprintf(page + len, count - len, |
| 480 | "WPA\n"); |
| 481 | } |
| 482 | else{ |
| 483 | len += snprintf(page + len, count - len, |
| 484 | "non_WPA\n"); |
| 485 | } |
| 486 | |
| 487 | } |
| 488 | |
| 489 | *eof = 1; |
| 490 | return len; |
| 491 | } |
| 492 | |
| 493 | static int proc_get_registers(char *page, char **start, |
| 494 | off_t offset, int count, |
| 495 | int *eof, void *data) |
| 496 | { |
| 497 | struct net_device *dev = data; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 498 | int len = 0; |
| 499 | int i,n; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 500 | int max=0xff; |
| 501 | |
| 502 | /* This dump the current register page */ |
| 503 | len += snprintf(page + len, count - len, |
| 504 | "\n####################page 0##################\n "); |
| 505 | |
| 506 | for(n=0;n<=max;) |
| 507 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 508 | len += snprintf(page + len, count - len, |
| 509 | "\nD: %2x > ",n); |
| 510 | |
| 511 | for(i=0;i<16 && n<=max;i++,n++) |
| 512 | len += snprintf(page + len, count - len, |
| 513 | "%2x ",read_nic_byte(dev,n)); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 514 | } |
| 515 | len += snprintf(page + len, count - len,"\n"); |
| 516 | len += snprintf(page + len, count - len, |
| 517 | "\n####################page 1##################\n "); |
| 518 | for(n=0;n<=max;) |
| 519 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 520 | len += snprintf(page + len, count - len, |
| 521 | "\nD: %2x > ",n); |
| 522 | |
| 523 | for(i=0;i<16 && n<=max;i++,n++) |
| 524 | len += snprintf(page + len, count - len, |
| 525 | "%2x ",read_nic_byte(dev,0x100|n)); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | len += snprintf(page + len, count - len, |
| 529 | "\n####################page 3##################\n "); |
| 530 | for(n=0;n<=max;) |
| 531 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 532 | len += snprintf(page + len, count - len, |
| 533 | "\nD: %2x > ",n); |
| 534 | |
| 535 | for(i=0;i<16 && n<=max;i++,n++) |
| 536 | len += snprintf(page + len, count - len, |
| 537 | "%2x ",read_nic_byte(dev,0x300|n)); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 540 | *eof = 1; |
| 541 | return len; |
| 542 | |
| 543 | } |
| 544 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 545 | static int proc_get_stats_tx(char *page, char **start, |
| 546 | off_t offset, int count, |
| 547 | int *eof, void *data) |
| 548 | { |
| 549 | struct net_device *dev = data; |
| 550 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 551 | |
| 552 | int len = 0; |
| 553 | |
| 554 | len += snprintf(page + len, count - len, |
| 555 | "TX VI priority ok int: %lu\n" |
| 556 | // "TX VI priority error int: %lu\n" |
| 557 | "TX VO priority ok int: %lu\n" |
| 558 | // "TX VO priority error int: %lu\n" |
| 559 | "TX BE priority ok int: %lu\n" |
| 560 | // "TX BE priority error int: %lu\n" |
| 561 | "TX BK priority ok int: %lu\n" |
| 562 | // "TX BK priority error int: %lu\n" |
| 563 | "TX MANAGE priority ok int: %lu\n" |
| 564 | // "TX MANAGE priority error int: %lu\n" |
| 565 | "TX BEACON priority ok int: %lu\n" |
| 566 | "TX BEACON priority error int: %lu\n" |
| 567 | "TX CMDPKT priority ok int: %lu\n" |
| 568 | // "TX high priority ok int: %lu\n" |
| 569 | // "TX high priority failed error int: %lu\n" |
| 570 | // "TX queue resume: %lu\n" |
| 571 | "TX queue stopped?: %d\n" |
| 572 | "TX fifo overflow: %lu\n" |
| 573 | // "TX beacon: %lu\n" |
| 574 | // "TX VI queue: %d\n" |
| 575 | // "TX VO queue: %d\n" |
| 576 | // "TX BE queue: %d\n" |
| 577 | // "TX BK queue: %d\n" |
| 578 | // "TX HW queue: %d\n" |
| 579 | // "TX VI dropped: %lu\n" |
| 580 | // "TX VO dropped: %lu\n" |
| 581 | // "TX BE dropped: %lu\n" |
| 582 | // "TX BK dropped: %lu\n" |
| 583 | "TX total data packets %lu\n" |
| 584 | "TX total data bytes :%lu\n", |
| 585 | // "TX beacon aborted: %lu\n", |
| 586 | priv->stats.txviokint, |
| 587 | // priv->stats.txvierr, |
| 588 | priv->stats.txvookint, |
| 589 | // priv->stats.txvoerr, |
| 590 | priv->stats.txbeokint, |
| 591 | // priv->stats.txbeerr, |
| 592 | priv->stats.txbkokint, |
| 593 | // priv->stats.txbkerr, |
| 594 | priv->stats.txmanageokint, |
| 595 | // priv->stats.txmanageerr, |
| 596 | priv->stats.txbeaconokint, |
| 597 | priv->stats.txbeaconerr, |
| 598 | priv->stats.txcmdpktokint, |
| 599 | // priv->stats.txhpokint, |
| 600 | // priv->stats.txhperr, |
| 601 | // priv->stats.txresumed, |
| 602 | netif_queue_stopped(dev), |
| 603 | priv->stats.txoverflow, |
| 604 | // priv->stats.txbeacon, |
| 605 | // atomic_read(&(priv->tx_pending[VI_QUEUE])), |
| 606 | // atomic_read(&(priv->tx_pending[VO_QUEUE])), |
| 607 | // atomic_read(&(priv->tx_pending[BE_QUEUE])), |
| 608 | // atomic_read(&(priv->tx_pending[BK_QUEUE])), |
| 609 | // read_nic_byte(dev, TXFIFOCOUNT), |
| 610 | // priv->stats.txvidrop, |
| 611 | // priv->stats.txvodrop, |
| 612 | priv->ieee80211->stats.tx_packets, |
| 613 | priv->ieee80211->stats.tx_bytes |
| 614 | |
| 615 | |
| 616 | // priv->stats.txbedrop, |
| 617 | // priv->stats.txbkdrop |
| 618 | // priv->stats.txdatapkt |
| 619 | // priv->stats.txbeaconerr |
| 620 | ); |
| 621 | |
| 622 | *eof = 1; |
| 623 | return len; |
| 624 | } |
| 625 | |
| 626 | |
| 627 | |
| 628 | static int proc_get_stats_rx(char *page, char **start, |
| 629 | off_t offset, int count, |
| 630 | int *eof, void *data) |
| 631 | { |
| 632 | struct net_device *dev = data; |
| 633 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 634 | |
| 635 | int len = 0; |
| 636 | |
| 637 | len += snprintf(page + len, count - len, |
| 638 | "RX packets: %lu\n" |
| 639 | "RX desc err: %lu\n" |
| 640 | "RX rx overflow error: %lu\n" |
| 641 | "RX invalid urb error: %lu\n", |
| 642 | priv->stats.rxint, |
| 643 | priv->stats.rxrdu, |
| 644 | priv->stats.rxoverflow, |
| 645 | priv->stats.rxurberr); |
| 646 | |
| 647 | *eof = 1; |
| 648 | return len; |
| 649 | } |
| 650 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 651 | static void rtl8192_proc_module_init(void) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 652 | { |
| 653 | RT_TRACE(COMP_INIT, "Initializing proc filesystem"); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 654 | rtl8192_proc=create_proc_entry(RTL819xE_MODULE_NAME, S_IFDIR, init_net.proc_net); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 658 | static void rtl8192_proc_module_remove(void) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 659 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 660 | remove_proc_entry(RTL819xE_MODULE_NAME, init_net.proc_net); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 664 | static void rtl8192_proc_remove_one(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 665 | { |
| 666 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 667 | |
| 668 | printk("dev name=======> %s\n",dev->name); |
| 669 | |
| 670 | if (priv->dir_dev) { |
| 671 | // remove_proc_entry("stats-hw", priv->dir_dev); |
| 672 | remove_proc_entry("stats-tx", priv->dir_dev); |
| 673 | remove_proc_entry("stats-rx", priv->dir_dev); |
| 674 | // remove_proc_entry("stats-ieee", priv->dir_dev); |
| 675 | remove_proc_entry("stats-ap", priv->dir_dev); |
| 676 | remove_proc_entry("registers", priv->dir_dev); |
| 677 | // remove_proc_entry("cck-registers",priv->dir_dev); |
| 678 | // remove_proc_entry("ofdm-registers",priv->dir_dev); |
| 679 | //remove_proc_entry(dev->name, rtl8192_proc); |
| 680 | remove_proc_entry("wlan0", rtl8192_proc); |
| 681 | priv->dir_dev = NULL; |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 686 | static void rtl8192_proc_init_one(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 687 | { |
| 688 | struct proc_dir_entry *e; |
| 689 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 690 | priv->dir_dev = create_proc_entry(dev->name, |
| 691 | S_IFDIR | S_IRUGO | S_IXUGO, |
| 692 | rtl8192_proc); |
| 693 | if (!priv->dir_dev) { |
| 694 | RT_TRACE(COMP_ERR, "Unable to initialize /proc/net/rtl8192/%s\n", |
| 695 | dev->name); |
| 696 | return; |
| 697 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 698 | e = create_proc_read_entry("stats-rx", S_IFREG | S_IRUGO, |
| 699 | priv->dir_dev, proc_get_stats_rx, dev); |
| 700 | |
| 701 | if (!e) { |
| 702 | RT_TRACE(COMP_ERR,"Unable to initialize " |
| 703 | "/proc/net/rtl8192/%s/stats-rx\n", |
| 704 | dev->name); |
| 705 | } |
| 706 | |
| 707 | |
| 708 | e = create_proc_read_entry("stats-tx", S_IFREG | S_IRUGO, |
| 709 | priv->dir_dev, proc_get_stats_tx, dev); |
| 710 | |
| 711 | if (!e) { |
| 712 | RT_TRACE(COMP_ERR, "Unable to initialize " |
| 713 | "/proc/net/rtl8192/%s/stats-tx\n", |
| 714 | dev->name); |
| 715 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 716 | |
| 717 | e = create_proc_read_entry("stats-ap", S_IFREG | S_IRUGO, |
| 718 | priv->dir_dev, proc_get_stats_ap, dev); |
| 719 | |
| 720 | if (!e) { |
| 721 | RT_TRACE(COMP_ERR, "Unable to initialize " |
| 722 | "/proc/net/rtl8192/%s/stats-ap\n", |
| 723 | dev->name); |
| 724 | } |
| 725 | |
| 726 | e = create_proc_read_entry("registers", S_IFREG | S_IRUGO, |
| 727 | priv->dir_dev, proc_get_registers, dev); |
| 728 | if (!e) { |
| 729 | RT_TRACE(COMP_ERR, "Unable to initialize " |
| 730 | "/proc/net/rtl8192/%s/registers\n", |
| 731 | dev->name); |
| 732 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 733 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 734 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 735 | short check_nic_enough_desc(struct net_device *dev, int prio) |
| 736 | { |
| 737 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 738 | struct rtl8192_tx_ring *ring = &priv->tx_ring[prio]; |
| 739 | |
| 740 | /* for now we reserve two free descriptor as a safety boundary |
| 741 | * between the tail and the head |
| 742 | */ |
Mike McCormack | 285f660 | 2010-08-10 23:44:03 +0900 | [diff] [blame] | 743 | return (ring->entries - skb_queue_len(&ring->queue) >= 2); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 746 | static void tx_timeout(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 747 | { |
| 748 | struct r8192_priv *priv = ieee80211_priv(dev); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 749 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 750 | schedule_work(&priv->reset_wq); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 751 | printk("TXTIMEOUT"); |
| 752 | } |
| 753 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 754 | static void rtl8192_irq_enable(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 755 | { |
| 756 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 757 | priv->irq_enabled = 1; |
| 758 | write_nic_dword(dev,INTA_MASK, priv->irq_mask); |
| 759 | } |
| 760 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 761 | void rtl8192_irq_disable(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 762 | { |
| 763 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 764 | |
| 765 | write_nic_dword(dev,INTA_MASK,0); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 766 | priv->irq_enabled = 0; |
| 767 | } |
| 768 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 769 | void rtl8192_update_msr(struct net_device *dev) |
| 770 | { |
| 771 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 772 | u8 msr; |
| 773 | |
| 774 | msr = read_nic_byte(dev, MSR); |
| 775 | msr &= ~ MSR_LINK_MASK; |
| 776 | |
| 777 | /* do not change in link_state != WLAN_LINK_ASSOCIATED. |
| 778 | * msr must be updated if the state is ASSOCIATING. |
| 779 | * this is intentional and make sense for ad-hoc and |
| 780 | * master (see the create BSS/IBSS func) |
| 781 | */ |
| 782 | if (priv->ieee80211->state == IEEE80211_LINKED){ |
| 783 | |
| 784 | if (priv->ieee80211->iw_mode == IW_MODE_INFRA) |
| 785 | msr |= (MSR_LINK_MANAGED<<MSR_LINK_SHIFT); |
| 786 | else if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) |
| 787 | msr |= (MSR_LINK_ADHOC<<MSR_LINK_SHIFT); |
| 788 | else if (priv->ieee80211->iw_mode == IW_MODE_MASTER) |
| 789 | msr |= (MSR_LINK_MASTER<<MSR_LINK_SHIFT); |
| 790 | |
| 791 | }else |
| 792 | msr |= (MSR_LINK_NONE<<MSR_LINK_SHIFT); |
| 793 | |
| 794 | write_nic_byte(dev, MSR, msr); |
| 795 | } |
| 796 | |
| 797 | void rtl8192_set_chan(struct net_device *dev,short ch) |
| 798 | { |
Mike McCormack | 61d0e67 | 2010-09-20 23:12:09 +0900 | [diff] [blame] | 799 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 800 | |
Mike McCormack | 61d0e67 | 2010-09-20 23:12:09 +0900 | [diff] [blame] | 801 | priv->chan = ch; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 802 | |
Mike McCormack | 61d0e67 | 2010-09-20 23:12:09 +0900 | [diff] [blame] | 803 | /* need to implement rf set channel here WB */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 804 | |
Mike McCormack | 61d0e67 | 2010-09-20 23:12:09 +0900 | [diff] [blame] | 805 | if (priv->rf_set_chan) |
| 806 | priv->rf_set_chan(dev, priv->chan); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 807 | } |
| 808 | |
| 809 | void rtl8192_rx_enable(struct net_device *dev) |
| 810 | { |
Mike McCormack | 7aed48d | 2010-09-20 23:12:18 +0900 | [diff] [blame] | 811 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 812 | |
| 813 | write_nic_dword(dev, RDQDA,priv->rx_ring_dma); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | /* the TX_DESC_BASE setting is according to the following queue index |
| 817 | * BK_QUEUE ===> 0 |
| 818 | * BE_QUEUE ===> 1 |
| 819 | * VI_QUEUE ===> 2 |
| 820 | * VO_QUEUE ===> 3 |
| 821 | * HCCA_QUEUE ===> 4 |
| 822 | * TXCMD_QUEUE ===> 5 |
| 823 | * MGNT_QUEUE ===> 6 |
| 824 | * HIGH_QUEUE ===> 7 |
| 825 | * BEACON_QUEUE ===> 8 |
| 826 | * */ |
Mike McCormack | 881a975 | 2010-07-26 22:58:03 +0900 | [diff] [blame] | 827 | static const u32 TX_DESC_BASE[] = {BKQDA, BEQDA, VIQDA, VOQDA, HCCAQDA, CQDA, MQDA, HQDA, BQDA}; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 828 | void rtl8192_tx_enable(struct net_device *dev) |
| 829 | { |
Mike McCormack | 7aed48d | 2010-09-20 23:12:18 +0900 | [diff] [blame] | 830 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 831 | u32 i; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 832 | |
Mike McCormack | 7aed48d | 2010-09-20 23:12:18 +0900 | [diff] [blame] | 833 | for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) |
| 834 | write_nic_dword(dev, TX_DESC_BASE[i], priv->tx_ring[i].dma); |
| 835 | |
| 836 | ieee80211_reset_queue(priv->ieee80211); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 839 | |
| 840 | static void rtl8192_free_rx_ring(struct net_device *dev) |
| 841 | { |
Mike McCormack | 7aed48d | 2010-09-20 23:12:18 +0900 | [diff] [blame] | 842 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 843 | int i; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 844 | |
Mike McCormack | 7aed48d | 2010-09-20 23:12:18 +0900 | [diff] [blame] | 845 | for (i = 0; i < priv->rxringcount; i++) { |
| 846 | struct sk_buff *skb = priv->rx_buf[i]; |
| 847 | if (!skb) |
| 848 | continue; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 849 | |
Mike McCormack | 7aed48d | 2010-09-20 23:12:18 +0900 | [diff] [blame] | 850 | pci_unmap_single(priv->pdev, |
| 851 | *((dma_addr_t *)skb->cb), |
| 852 | priv->rxbuffersize, PCI_DMA_FROMDEVICE); |
| 853 | kfree_skb(skb); |
| 854 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 855 | |
Mike McCormack | 7aed48d | 2010-09-20 23:12:18 +0900 | [diff] [blame] | 856 | pci_free_consistent(priv->pdev, sizeof(*priv->rx_ring) * priv->rxringcount, |
| 857 | priv->rx_ring, priv->rx_ring_dma); |
| 858 | priv->rx_ring = NULL; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | static void rtl8192_free_tx_ring(struct net_device *dev, unsigned int prio) |
| 862 | { |
Mike McCormack | 7aed48d | 2010-09-20 23:12:18 +0900 | [diff] [blame] | 863 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 864 | struct rtl8192_tx_ring *ring = &priv->tx_ring[prio]; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 865 | |
Mike McCormack | 7aed48d | 2010-09-20 23:12:18 +0900 | [diff] [blame] | 866 | while (skb_queue_len(&ring->queue)) { |
| 867 | tx_desc_819x_pci *entry = &ring->desc[ring->idx]; |
| 868 | struct sk_buff *skb = __skb_dequeue(&ring->queue); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 869 | |
Mike McCormack | 7aed48d | 2010-09-20 23:12:18 +0900 | [diff] [blame] | 870 | pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr), |
| 871 | skb->len, PCI_DMA_TODEVICE); |
| 872 | kfree_skb(skb); |
| 873 | ring->idx = (ring->idx + 1) % ring->entries; |
| 874 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 875 | |
Mike McCormack | 7aed48d | 2010-09-20 23:12:18 +0900 | [diff] [blame] | 876 | pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries, |
| 877 | ring->desc, ring->dma); |
| 878 | ring->desc = NULL; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Mike McCormack | 16d74da | 2010-09-20 23:11:14 +0900 | [diff] [blame] | 881 | void PHY_SetRtl8192eRfOff(struct net_device* dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 882 | { |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 883 | //disable RF-Chip A/B |
| 884 | rtl8192_setBBreg(dev, rFPGA0_XA_RFInterfaceOE, BIT4, 0x0); |
| 885 | //analog to digital off, for power save |
| 886 | rtl8192_setBBreg(dev, rFPGA0_AnalogParameter4, 0x300, 0x0); |
| 887 | //digital to analog off, for power save |
| 888 | rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x18, 0x0); |
| 889 | //rx antenna off |
| 890 | rtl8192_setBBreg(dev, rOFDM0_TRxPathEnable, 0xf, 0x0); |
| 891 | //rx antenna off |
| 892 | rtl8192_setBBreg(dev, rOFDM1_TRxPathEnable, 0xf, 0x0); |
| 893 | //analog to digital part2 off, for power save |
| 894 | rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x60, 0x0); |
| 895 | rtl8192_setBBreg(dev, rFPGA0_AnalogParameter1, 0x4, 0x0); |
| 896 | // Analog parameter!!Change bias and Lbus control. |
| 897 | write_nic_byte(dev, ANAPAR_FOR_8192PciE, 0x07); |
| 898 | |
| 899 | } |
| 900 | |
| 901 | void rtl8192_halt_adapter(struct net_device *dev, bool reset) |
| 902 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 903 | struct r8192_priv *priv = ieee80211_priv(dev); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 904 | int i; |
| 905 | u8 OpMode; |
| 906 | u8 u1bTmp; |
| 907 | u32 ulRegRead; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 908 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 909 | OpMode = RT_OP_MODE_NO_LINK; |
| 910 | priv->ieee80211->SetHwRegHandler(dev, HW_VAR_MEDIA_STATUS, &OpMode); |
| 911 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 912 | if(!priv->ieee80211->bSupportRemoteWakeUp) |
| 913 | { |
| 914 | u1bTmp = 0x0; // disable tx/rx. In 8185 we write 0x10 (Reset bit), but here we make reference to WMAC and wirte 0x0. 2006.11.21 Emily |
| 915 | //priv->ieee80211->SetHwRegHandler(dev, HW_VAR_COMMAND, &u1bTmp ); // Using HW_VAR_COMMAND instead of writing CMDR directly. Rewrited by Annie, 2006-04-07. |
| 916 | write_nic_byte(dev, CMDR, u1bTmp); |
| 917 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 918 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 919 | mdelay(20); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 920 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 921 | if(!reset) |
| 922 | { |
| 923 | //PlatformStallExecution(150000); |
| 924 | mdelay(150); |
| 925 | |
| 926 | #ifdef RTL8192E |
| 927 | priv->bHwRfOffAction = 2; |
| 928 | #endif |
| 929 | |
| 930 | // |
| 931 | // Call MgntActSet_RF_State instead to prevent RF config race condition. |
| 932 | // By Bruce, 2008-01-17. |
| 933 | // |
| 934 | if(!priv->ieee80211->bSupportRemoteWakeUp) |
| 935 | { |
| 936 | //MgntActSet_RF_State(Adapter, eRfOff, RF_CHANGE_BY_INIT); |
| 937 | //MgntActSet_RF_State(Adapter, eRfOff, Adapter->MgntInfo.RfOffReason); |
| 938 | //if(Adapter->HardwareType == HARDWARE_TYPE_RTL8190P) |
| 939 | |
| 940 | PHY_SetRtl8192eRfOff(dev); |
| 941 | |
| 942 | // 2006.11.30. System reset bit |
| 943 | //priv->ieee80211->GetHwRegHandler(dev, HW_VAR_CPU_RST, (u32*)(&ulRegRead) ); |
| 944 | ulRegRead = read_nic_dword(dev,CPU_GEN); |
| 945 | ulRegRead|=CPU_GEN_SYSTEM_RESET; |
| 946 | //priv->ieee80211->SetHwRegHandler(dev, HW_VAR_CPU_RST, &ulRegRead); |
| 947 | write_nic_dword(dev,CPU_GEN, ulRegRead); |
| 948 | } |
| 949 | else |
| 950 | { |
| 951 | //2008.06.03 for WOL |
| 952 | write_nic_dword(dev, WFCRC0, 0xffffffff); |
| 953 | write_nic_dword(dev, WFCRC1, 0xffffffff); |
| 954 | write_nic_dword(dev, WFCRC2, 0xffffffff); |
| 955 | |
| 956 | //Write PMR register |
| 957 | write_nic_byte(dev, PMR, 0x5); |
| 958 | //Disable tx, enanble rx |
| 959 | write_nic_byte(dev, MacBlkCtrl, 0xa); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | for(i = 0; i < MAX_QUEUE_SIZE; i++) { |
| 964 | skb_queue_purge(&priv->ieee80211->skb_waitQ [i]); |
| 965 | } |
| 966 | for(i = 0; i < MAX_QUEUE_SIZE; i++) { |
| 967 | skb_queue_purge(&priv->ieee80211->skb_aggQ [i]); |
| 968 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 969 | |
| 970 | skb_queue_purge(&priv->skb_queue); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Mike McCormack | 881a975 | 2010-07-26 22:58:03 +0900 | [diff] [blame] | 973 | static const u16 rtl_rate[] = {10,20,55,110,60,90,120,180,240,360,480,540}; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 974 | inline u16 rtl8192_rate2rate(short rate) |
| 975 | { |
| 976 | if (rate >11) return 0; |
| 977 | return rtl_rate[rate]; |
| 978 | } |
| 979 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 980 | static void rtl8192_data_hard_stop(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 981 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 982 | } |
| 983 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 984 | static void rtl8192_data_hard_resume(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 985 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 986 | } |
| 987 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 988 | /* |
| 989 | * this function TX data frames when the ieee80211 stack requires this. |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 990 | * It checks also if we need to stop the ieee tx queue, eventually do it |
| 991 | */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 992 | static void rtl8192_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, int rate) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 993 | { |
| 994 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 995 | int ret; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 996 | cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); |
| 997 | u8 queue_index = tcb_desc->queue_index; |
Mike McCormack | dcf663f | 2010-09-20 23:11:40 +0900 | [diff] [blame] | 998 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 999 | /* shall not be referred by command packet */ |
| 1000 | assert(queue_index != TXCMD_QUEUE); |
| 1001 | |
Mike McCormack | dcf663f | 2010-09-20 23:11:40 +0900 | [diff] [blame] | 1002 | if (priv->bHwRadioOff || (!priv->up)) |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 1003 | { |
| 1004 | kfree_skb(skb); |
| 1005 | return; |
| 1006 | } |
| 1007 | |
Mike McCormack | dcf663f | 2010-09-20 23:11:40 +0900 | [diff] [blame] | 1008 | memcpy(skb->cb, &dev, sizeof(dev)); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1009 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1010 | skb_push(skb, priv->ieee80211->tx_headroom); |
| 1011 | ret = rtl8192_tx(dev, skb); |
Mike McCormack | dcf663f | 2010-09-20 23:11:40 +0900 | [diff] [blame] | 1012 | if (ret != 0) { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1013 | kfree_skb(skb); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1014 | } |
| 1015 | |
Mike McCormack | dcf663f | 2010-09-20 23:11:40 +0900 | [diff] [blame] | 1016 | if (queue_index != MGNT_QUEUE) { |
| 1017 | priv->ieee80211->stats.tx_bytes += (skb->len - priv->ieee80211->tx_headroom); |
| 1018 | priv->ieee80211->stats.tx_packets++; |
| 1019 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1020 | } |
| 1021 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 1022 | /* |
| 1023 | * This is a rough attempt to TX a frame |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1024 | * This is called by the ieee 80211 stack to TX management frames. |
| 1025 | * If the ring is full packet are dropped (for data frame the queue |
| 1026 | * is stopped before this can happen). |
| 1027 | */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1028 | static int rtl8192_hard_start_xmit(struct sk_buff *skb,struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1029 | { |
| 1030 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1031 | int ret; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1032 | cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); |
| 1033 | u8 queue_index = tcb_desc->queue_index; |
| 1034 | |
Mike McCormack | 162f535 | 2010-09-20 23:12:50 +0900 | [diff] [blame] | 1035 | if (queue_index != TXCMD_QUEUE) { |
| 1036 | if (priv->bHwRadioOff || (!priv->up)) |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 1037 | { |
Mike McCormack | 162f535 | 2010-09-20 23:12:50 +0900 | [diff] [blame] | 1038 | kfree_skb(skb); |
| 1039 | return 0; |
| 1040 | } |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 1041 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1042 | |
Mike McCormack | 162f535 | 2010-09-20 23:12:50 +0900 | [diff] [blame] | 1043 | memcpy(skb->cb, &dev, sizeof(dev)); |
| 1044 | if (queue_index == TXCMD_QUEUE) { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1045 | rtl819xE_tx_cmd(dev, skb); |
| 1046 | ret = 0; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1047 | return ret; |
| 1048 | } else { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1049 | tcb_desc->RATRIndex = 7; |
| 1050 | tcb_desc->bTxDisableRateFallBack = 1; |
| 1051 | tcb_desc->bTxUseDriverAssingedRate = 1; |
| 1052 | tcb_desc->bTxEnableFwCalcDur = 1; |
| 1053 | skb_push(skb, priv->ieee80211->tx_headroom); |
| 1054 | ret = rtl8192_tx(dev, skb); |
Mike McCormack | 162f535 | 2010-09-20 23:12:50 +0900 | [diff] [blame] | 1055 | if (ret != 0) { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1056 | kfree_skb(skb); |
Mike McCormack | 162f535 | 2010-09-20 23:12:50 +0900 | [diff] [blame] | 1057 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1058 | } |
| 1059 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1060 | return ret; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1064 | static void rtl8192_tx_isr(struct net_device *dev, int prio) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1065 | { |
| 1066 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 1067 | |
| 1068 | struct rtl8192_tx_ring *ring = &priv->tx_ring[prio]; |
| 1069 | |
| 1070 | while (skb_queue_len(&ring->queue)) { |
| 1071 | tx_desc_819x_pci *entry = &ring->desc[ring->idx]; |
| 1072 | struct sk_buff *skb; |
| 1073 | |
André Goddard Rosa | bbc9a99 | 2009-11-14 13:09:06 -0200 | [diff] [blame] | 1074 | /* beacon packet will only use the first descriptor defaultly, |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1075 | * and the OWN may not be cleared by the hardware |
| 1076 | * */ |
| 1077 | if(prio != BEACON_QUEUE) { |
| 1078 | if(entry->OWN) |
| 1079 | return; |
| 1080 | ring->idx = (ring->idx + 1) % ring->entries; |
| 1081 | } |
| 1082 | |
| 1083 | skb = __skb_dequeue(&ring->queue); |
| 1084 | pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr), |
| 1085 | skb->len, PCI_DMA_TODEVICE); |
| 1086 | |
| 1087 | kfree_skb(skb); |
| 1088 | } |
| 1089 | if (prio == MGNT_QUEUE){ |
| 1090 | if (priv->ieee80211->ack_tx_to_ieee){ |
| 1091 | if (rtl8192_is_tx_queue_empty(dev)){ |
| 1092 | priv->ieee80211->ack_tx_to_ieee = 0; |
| 1093 | ieee80211_ps_tx_ack(priv->ieee80211, 1); |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | |
| 1098 | if(prio != BEACON_QUEUE) { |
| 1099 | /* try to deal with the pending packets */ |
| 1100 | tasklet_schedule(&priv->irq_tx_tasklet); |
| 1101 | } |
| 1102 | |
| 1103 | } |
| 1104 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1105 | static void rtl8192_stop_beacon(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1106 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1109 | static void rtl8192_config_rate(struct net_device* dev, u16* rate_config) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1110 | { |
| 1111 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1112 | struct ieee80211_network *net; |
| 1113 | u8 i=0, basic_rate = 0; |
| 1114 | net = & priv->ieee80211->current_network; |
| 1115 | |
| 1116 | for (i=0; i<net->rates_len; i++) |
| 1117 | { |
| 1118 | basic_rate = net->rates[i]&0x7f; |
| 1119 | switch(basic_rate) |
| 1120 | { |
| 1121 | case MGN_1M: *rate_config |= RRSR_1M; break; |
| 1122 | case MGN_2M: *rate_config |= RRSR_2M; break; |
| 1123 | case MGN_5_5M: *rate_config |= RRSR_5_5M; break; |
| 1124 | case MGN_11M: *rate_config |= RRSR_11M; break; |
| 1125 | case MGN_6M: *rate_config |= RRSR_6M; break; |
| 1126 | case MGN_9M: *rate_config |= RRSR_9M; break; |
| 1127 | case MGN_12M: *rate_config |= RRSR_12M; break; |
| 1128 | case MGN_18M: *rate_config |= RRSR_18M; break; |
| 1129 | case MGN_24M: *rate_config |= RRSR_24M; break; |
| 1130 | case MGN_36M: *rate_config |= RRSR_36M; break; |
| 1131 | case MGN_48M: *rate_config |= RRSR_48M; break; |
| 1132 | case MGN_54M: *rate_config |= RRSR_54M; break; |
| 1133 | } |
| 1134 | } |
| 1135 | for (i=0; i<net->rates_ex_len; i++) |
| 1136 | { |
| 1137 | basic_rate = net->rates_ex[i]&0x7f; |
| 1138 | switch(basic_rate) |
| 1139 | { |
| 1140 | case MGN_1M: *rate_config |= RRSR_1M; break; |
| 1141 | case MGN_2M: *rate_config |= RRSR_2M; break; |
| 1142 | case MGN_5_5M: *rate_config |= RRSR_5_5M; break; |
| 1143 | case MGN_11M: *rate_config |= RRSR_11M; break; |
| 1144 | case MGN_6M: *rate_config |= RRSR_6M; break; |
| 1145 | case MGN_9M: *rate_config |= RRSR_9M; break; |
| 1146 | case MGN_12M: *rate_config |= RRSR_12M; break; |
| 1147 | case MGN_18M: *rate_config |= RRSR_18M; break; |
| 1148 | case MGN_24M: *rate_config |= RRSR_24M; break; |
| 1149 | case MGN_36M: *rate_config |= RRSR_36M; break; |
| 1150 | case MGN_48M: *rate_config |= RRSR_48M; break; |
| 1151 | case MGN_54M: *rate_config |= RRSR_54M; break; |
| 1152 | } |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | |
| 1157 | #define SHORT_SLOT_TIME 9 |
| 1158 | #define NON_SHORT_SLOT_TIME 20 |
| 1159 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1160 | static void rtl8192_update_cap(struct net_device* dev, u16 cap) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1161 | { |
| 1162 | u32 tmp = 0; |
| 1163 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1164 | struct ieee80211_network *net = &priv->ieee80211->current_network; |
| 1165 | priv->short_preamble = cap & WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 1166 | tmp = priv->basic_rate; |
| 1167 | if (priv->short_preamble) |
| 1168 | tmp |= BRSR_AckShortPmb; |
| 1169 | write_nic_dword(dev, RRSR, tmp); |
| 1170 | |
| 1171 | if (net->mode & (IEEE_G|IEEE_N_24G)) |
| 1172 | { |
| 1173 | u8 slot_time = 0; |
| 1174 | if ((cap & WLAN_CAPABILITY_SHORT_SLOT)&&(!priv->ieee80211->pHTInfo->bCurrentRT2RTLongSlotTime)) |
| 1175 | {//short slot time |
| 1176 | slot_time = SHORT_SLOT_TIME; |
| 1177 | } |
| 1178 | else //long slot time |
| 1179 | slot_time = NON_SHORT_SLOT_TIME; |
| 1180 | priv->slot_time = slot_time; |
| 1181 | write_nic_byte(dev, SLOT_TIME, slot_time); |
| 1182 | } |
| 1183 | |
| 1184 | } |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1185 | |
| 1186 | static void rtl8192_net_update(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1187 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1188 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1189 | struct ieee80211_network *net; |
| 1190 | u16 BcnTimeCfg = 0, BcnCW = 6, BcnIFS = 0xf; |
| 1191 | u16 rate_config = 0; |
| 1192 | net = &priv->ieee80211->current_network; |
Mike McCormack | eb40aea | 2010-09-24 18:38:23 +0900 | [diff] [blame] | 1193 | |
| 1194 | /* update Basic rate: RR, BRSR */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1195 | rtl8192_config_rate(dev, &rate_config); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1196 | |
Mike McCormack | eb40aea | 2010-09-24 18:38:23 +0900 | [diff] [blame] | 1197 | /* |
| 1198 | * Select RRSR (in Legacy-OFDM and CCK) |
| 1199 | * For 8190, we select only 24M, 12M, 6M, 11M, 5.5M, |
| 1200 | * 2M, and 1M from the Basic rate. |
| 1201 | * We do not use other rates. |
| 1202 | */ |
| 1203 | priv->basic_rate = rate_config &= 0x15f; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1204 | |
Mike McCormack | eb40aea | 2010-09-24 18:38:23 +0900 | [diff] [blame] | 1205 | /* BSSID */ |
| 1206 | write_nic_dword(dev, BSSIDR, ((u32 *)net->bssid)[0]); |
| 1207 | write_nic_word(dev, BSSIDR+4, ((u16 *)net->bssid)[2]); |
| 1208 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1209 | if (priv->ieee80211->iw_mode == IW_MODE_ADHOC) |
| 1210 | { |
| 1211 | write_nic_word(dev, ATIMWND, 2); |
| 1212 | write_nic_word(dev, BCN_DMATIME, 256); |
| 1213 | write_nic_word(dev, BCN_INTERVAL, net->beacon_interval); |
Mike McCormack | eb40aea | 2010-09-24 18:38:23 +0900 | [diff] [blame] | 1214 | /* |
| 1215 | * BIT15 of BCN_DRV_EARLY_INT will indicate |
| 1216 | * whether software beacon or hw beacon is applied. |
| 1217 | */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1218 | write_nic_word(dev, BCN_DRV_EARLY_INT, 10); |
| 1219 | write_nic_byte(dev, BCN_ERR_THRESH, 100); |
| 1220 | |
| 1221 | BcnTimeCfg |= (BcnCW<<BCN_TCFG_CW_SHIFT); |
Mike McCormack | eb40aea | 2010-09-24 18:38:23 +0900 | [diff] [blame] | 1222 | /* TODO: BcnIFS may required to be changed on ASIC */ |
| 1223 | BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1224 | write_nic_word(dev, BCN_TCFG, BcnTimeCfg); |
| 1225 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1226 | } |
| 1227 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1228 | void rtl819xE_tx_cmd(struct net_device *dev, struct sk_buff *skb) |
| 1229 | { |
| 1230 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1231 | struct rtl8192_tx_ring *ring; |
| 1232 | tx_desc_819x_pci *entry; |
| 1233 | unsigned int idx; |
| 1234 | dma_addr_t mapping; |
| 1235 | cb_desc *tcb_desc; |
| 1236 | unsigned long flags; |
| 1237 | |
| 1238 | ring = &priv->tx_ring[TXCMD_QUEUE]; |
| 1239 | mapping = pci_map_single(priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE); |
| 1240 | |
| 1241 | spin_lock_irqsave(&priv->irq_th_lock,flags); |
| 1242 | idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries; |
| 1243 | entry = &ring->desc[idx]; |
| 1244 | |
| 1245 | tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); |
| 1246 | memset(entry,0,12); |
| 1247 | entry->LINIP = tcb_desc->bLastIniPkt; |
| 1248 | entry->FirstSeg = 1;//first segment |
| 1249 | entry->LastSeg = 1; //last segment |
| 1250 | if(tcb_desc->bCmdOrInit == DESC_PACKET_TYPE_INIT) { |
| 1251 | entry->CmdInit = DESC_PACKET_TYPE_INIT; |
| 1252 | } else { |
| 1253 | entry->CmdInit = DESC_PACKET_TYPE_NORMAL; |
| 1254 | entry->Offset = sizeof(TX_FWINFO_8190PCI) + 8; |
| 1255 | entry->PktSize = (u16)(tcb_desc->pkt_size + entry->Offset); |
| 1256 | entry->QueueSelect = QSLT_CMD; |
| 1257 | entry->TxFWInfoSize = 0x08; |
| 1258 | entry->RATid = (u8)DESC_PACKET_TYPE_INIT; |
| 1259 | } |
| 1260 | entry->TxBufferSize = skb->len; |
| 1261 | entry->TxBuffAddr = cpu_to_le32(mapping); |
| 1262 | entry->OWN = 1; |
| 1263 | |
| 1264 | #ifdef JOHN_DUMP_TXDESC |
| 1265 | { int i; |
| 1266 | tx_desc_819x_pci *entry1 = &ring->desc[0]; |
| 1267 | unsigned int *ptr= (unsigned int *)entry1; |
| 1268 | printk("<Tx descriptor>:\n"); |
| 1269 | for (i = 0; i < 8; i++) |
| 1270 | printk("%8x ", ptr[i]); |
| 1271 | printk("\n"); |
| 1272 | } |
| 1273 | #endif |
| 1274 | __skb_queue_tail(&ring->queue, skb); |
| 1275 | spin_unlock_irqrestore(&priv->irq_th_lock,flags); |
| 1276 | |
| 1277 | write_nic_byte(dev, TPPoll, TPPoll_CQ); |
| 1278 | |
| 1279 | return; |
| 1280 | } |
| 1281 | |
| 1282 | /* |
| 1283 | * Mapping Software/Hardware descriptor queue id to "Queue Select Field" |
| 1284 | * in TxFwInfo data structure |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 1285 | */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1286 | static u8 MapHwQueueToFirmwareQueue(u8 QueueID) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1287 | { |
Mike McCormack | f72b6a5 | 2010-09-24 18:38:41 +0900 | [diff] [blame] | 1288 | u8 QueueSelect = 0; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1289 | |
Mike McCormack | f72b6a5 | 2010-09-24 18:38:41 +0900 | [diff] [blame] | 1290 | switch (QueueID) { |
| 1291 | case BE_QUEUE: |
| 1292 | QueueSelect = QSLT_BE; |
| 1293 | break; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1294 | |
Mike McCormack | f72b6a5 | 2010-09-24 18:38:41 +0900 | [diff] [blame] | 1295 | case BK_QUEUE: |
| 1296 | QueueSelect = QSLT_BK; |
| 1297 | break; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1298 | |
Mike McCormack | f72b6a5 | 2010-09-24 18:38:41 +0900 | [diff] [blame] | 1299 | case VO_QUEUE: |
| 1300 | QueueSelect = QSLT_VO; |
| 1301 | break; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1302 | |
Mike McCormack | f72b6a5 | 2010-09-24 18:38:41 +0900 | [diff] [blame] | 1303 | case VI_QUEUE: |
| 1304 | QueueSelect = QSLT_VI; |
| 1305 | break; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1306 | |
Mike McCormack | f72b6a5 | 2010-09-24 18:38:41 +0900 | [diff] [blame] | 1307 | case MGNT_QUEUE: |
| 1308 | QueueSelect = QSLT_MGNT; |
| 1309 | break; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1310 | |
Mike McCormack | f72b6a5 | 2010-09-24 18:38:41 +0900 | [diff] [blame] | 1311 | case BEACON_QUEUE: |
| 1312 | QueueSelect = QSLT_BEACON; |
| 1313 | break; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1314 | |
Mike McCormack | f72b6a5 | 2010-09-24 18:38:41 +0900 | [diff] [blame] | 1315 | case TXCMD_QUEUE: |
| 1316 | QueueSelect = QSLT_CMD; |
| 1317 | break; |
| 1318 | |
| 1319 | case HIGH_QUEUE: |
| 1320 | default: |
| 1321 | RT_TRACE(COMP_ERR, "Impossible Queue Selection: %d\n", QueueID); |
| 1322 | break; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1323 | } |
| 1324 | return QueueSelect; |
| 1325 | } |
| 1326 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1327 | static u8 MRateToHwRate8190Pci(u8 rate) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1328 | { |
| 1329 | u8 ret = DESC90_RATE1M; |
| 1330 | |
| 1331 | switch(rate) { |
| 1332 | case MGN_1M: ret = DESC90_RATE1M; break; |
| 1333 | case MGN_2M: ret = DESC90_RATE2M; break; |
| 1334 | case MGN_5_5M: ret = DESC90_RATE5_5M; break; |
| 1335 | case MGN_11M: ret = DESC90_RATE11M; break; |
| 1336 | case MGN_6M: ret = DESC90_RATE6M; break; |
| 1337 | case MGN_9M: ret = DESC90_RATE9M; break; |
| 1338 | case MGN_12M: ret = DESC90_RATE12M; break; |
| 1339 | case MGN_18M: ret = DESC90_RATE18M; break; |
| 1340 | case MGN_24M: ret = DESC90_RATE24M; break; |
| 1341 | case MGN_36M: ret = DESC90_RATE36M; break; |
| 1342 | case MGN_48M: ret = DESC90_RATE48M; break; |
| 1343 | case MGN_54M: ret = DESC90_RATE54M; break; |
| 1344 | |
| 1345 | // HT rate since here |
| 1346 | case MGN_MCS0: ret = DESC90_RATEMCS0; break; |
| 1347 | case MGN_MCS1: ret = DESC90_RATEMCS1; break; |
| 1348 | case MGN_MCS2: ret = DESC90_RATEMCS2; break; |
| 1349 | case MGN_MCS3: ret = DESC90_RATEMCS3; break; |
| 1350 | case MGN_MCS4: ret = DESC90_RATEMCS4; break; |
| 1351 | case MGN_MCS5: ret = DESC90_RATEMCS5; break; |
| 1352 | case MGN_MCS6: ret = DESC90_RATEMCS6; break; |
| 1353 | case MGN_MCS7: ret = DESC90_RATEMCS7; break; |
| 1354 | case MGN_MCS8: ret = DESC90_RATEMCS8; break; |
| 1355 | case MGN_MCS9: ret = DESC90_RATEMCS9; break; |
| 1356 | case MGN_MCS10: ret = DESC90_RATEMCS10; break; |
| 1357 | case MGN_MCS11: ret = DESC90_RATEMCS11; break; |
| 1358 | case MGN_MCS12: ret = DESC90_RATEMCS12; break; |
| 1359 | case MGN_MCS13: ret = DESC90_RATEMCS13; break; |
| 1360 | case MGN_MCS14: ret = DESC90_RATEMCS14; break; |
| 1361 | case MGN_MCS15: ret = DESC90_RATEMCS15; break; |
| 1362 | case (0x80|0x20): ret = DESC90_RATEMCS32; break; |
| 1363 | |
| 1364 | default: break; |
| 1365 | } |
| 1366 | return ret; |
| 1367 | } |
| 1368 | |
| 1369 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1370 | static u8 QueryIsShort(u8 TxHT, u8 TxRate, cb_desc *tcb_desc) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1371 | { |
| 1372 | u8 tmp_Short; |
| 1373 | |
| 1374 | tmp_Short = (TxHT==1)?((tcb_desc->bUseShortGI)?1:0):((tcb_desc->bUseShortPreamble)?1:0); |
| 1375 | |
| 1376 | if(TxHT==1 && TxRate != DESC90_RATEMCS15) |
| 1377 | tmp_Short = 0; |
| 1378 | |
| 1379 | return tmp_Short; |
| 1380 | } |
| 1381 | |
| 1382 | /* |
| 1383 | * The tx procedure is just as following, |
| 1384 | * skb->cb will contain all the following information, |
| 1385 | * priority, morefrag, rate, &dev. |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 1386 | */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1387 | short rtl8192_tx(struct net_device *dev, struct sk_buff* skb) |
| 1388 | { |
| 1389 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1390 | struct rtl8192_tx_ring *ring; |
| 1391 | unsigned long flags; |
| 1392 | cb_desc *tcb_desc = (cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); |
| 1393 | tx_desc_819x_pci *pdesc = NULL; |
| 1394 | TX_FWINFO_8190PCI *pTxFwInfo = NULL; |
| 1395 | dma_addr_t mapping; |
| 1396 | bool multi_addr=false,broad_addr=false,uni_addr=false; |
| 1397 | u8* pda_addr = NULL; |
| 1398 | int idx; |
| 1399 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 1400 | if(priv->bdisable_nic){ |
| 1401 | RT_TRACE(COMP_ERR,"%s: ERR!! Nic is disabled! Can't tx packet len=%d qidx=%d!!!\n", __FUNCTION__, skb->len, tcb_desc->queue_index); |
| 1402 | return skb->len; |
| 1403 | } |
| 1404 | |
| 1405 | #ifdef ENABLE_LPS |
| 1406 | priv->ieee80211->bAwakePktSent = true; |
| 1407 | #endif |
| 1408 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1409 | mapping = pci_map_single(priv->pdev, skb->data, skb->len, PCI_DMA_TODEVICE); |
| 1410 | /* collect the tx packets statitcs */ |
| 1411 | pda_addr = ((u8*)skb->data) + sizeof(TX_FWINFO_8190PCI); |
| 1412 | if(is_multicast_ether_addr(pda_addr)) |
| 1413 | multi_addr = true; |
| 1414 | else if(is_broadcast_ether_addr(pda_addr)) |
| 1415 | broad_addr = true; |
| 1416 | else |
| 1417 | uni_addr = true; |
| 1418 | |
| 1419 | if(uni_addr) |
| 1420 | priv->stats.txbytesunicast += (u8)(skb->len) - sizeof(TX_FWINFO_8190PCI); |
| 1421 | else if(multi_addr) |
| 1422 | priv->stats.txbytesmulticast +=(u8)(skb->len) - sizeof(TX_FWINFO_8190PCI); |
| 1423 | else |
| 1424 | priv->stats.txbytesbroadcast += (u8)(skb->len) - sizeof(TX_FWINFO_8190PCI); |
| 1425 | |
| 1426 | /* fill tx firmware */ |
| 1427 | pTxFwInfo = (PTX_FWINFO_8190PCI)skb->data; |
| 1428 | memset(pTxFwInfo,0,sizeof(TX_FWINFO_8190PCI)); |
| 1429 | pTxFwInfo->TxHT = (tcb_desc->data_rate&0x80)?1:0; |
| 1430 | pTxFwInfo->TxRate = MRateToHwRate8190Pci((u8)tcb_desc->data_rate); |
| 1431 | pTxFwInfo->EnableCPUDur = tcb_desc->bTxEnableFwCalcDur; |
| 1432 | pTxFwInfo->Short = QueryIsShort(pTxFwInfo->TxHT, pTxFwInfo->TxRate, tcb_desc); |
| 1433 | |
| 1434 | /* Aggregation related */ |
| 1435 | if(tcb_desc->bAMPDUEnable) { |
| 1436 | pTxFwInfo->AllowAggregation = 1; |
| 1437 | pTxFwInfo->RxMF = tcb_desc->ampdu_factor; |
| 1438 | pTxFwInfo->RxAMD = tcb_desc->ampdu_density; |
| 1439 | } else { |
| 1440 | pTxFwInfo->AllowAggregation = 0; |
| 1441 | pTxFwInfo->RxMF = 0; |
| 1442 | pTxFwInfo->RxAMD = 0; |
| 1443 | } |
| 1444 | |
| 1445 | // |
| 1446 | // Protection mode related |
| 1447 | // |
| 1448 | pTxFwInfo->RtsEnable = (tcb_desc->bRTSEnable)?1:0; |
| 1449 | pTxFwInfo->CtsEnable = (tcb_desc->bCTSEnable)?1:0; |
| 1450 | pTxFwInfo->RtsSTBC = (tcb_desc->bRTSSTBC)?1:0; |
| 1451 | pTxFwInfo->RtsHT= (tcb_desc->rts_rate&0x80)?1:0; |
| 1452 | pTxFwInfo->RtsRate = MRateToHwRate8190Pci((u8)tcb_desc->rts_rate); |
| 1453 | pTxFwInfo->RtsBandwidth = 0; |
| 1454 | pTxFwInfo->RtsSubcarrier = tcb_desc->RTSSC; |
| 1455 | pTxFwInfo->RtsShort = (pTxFwInfo->RtsHT==0)?(tcb_desc->bRTSUseShortPreamble?1:0):(tcb_desc->bRTSUseShortGI?1:0); |
| 1456 | // |
| 1457 | // Set Bandwidth and sub-channel settings. |
| 1458 | // |
| 1459 | if(priv->CurrentChannelBW == HT_CHANNEL_WIDTH_20_40) |
| 1460 | { |
| 1461 | if(tcb_desc->bPacketBW) |
| 1462 | { |
| 1463 | pTxFwInfo->TxBandwidth = 1; |
| 1464 | #ifdef RTL8190P |
| 1465 | pTxFwInfo->TxSubCarrier = 3; |
| 1466 | #else |
| 1467 | pTxFwInfo->TxSubCarrier = 0; //By SD3's Jerry suggestion, use duplicated mode, cosa 04012008 |
| 1468 | #endif |
| 1469 | } |
| 1470 | else |
| 1471 | { |
| 1472 | pTxFwInfo->TxBandwidth = 0; |
| 1473 | pTxFwInfo->TxSubCarrier = priv->nCur40MhzPrimeSC; |
| 1474 | } |
| 1475 | } else { |
| 1476 | pTxFwInfo->TxBandwidth = 0; |
| 1477 | pTxFwInfo->TxSubCarrier = 0; |
| 1478 | } |
| 1479 | |
| 1480 | if (0) |
| 1481 | { |
| 1482 | /* 2007/07/25 MH Copy current TX FW info.*/ |
| 1483 | memcpy((void*)(&Tmp_TxFwInfo), (void*)(pTxFwInfo), sizeof(TX_FWINFO_8190PCI)); |
| 1484 | printk("&&&&&&&&&&&&&&&&&&&&&&====>print out fwinf\n"); |
| 1485 | printk("===>enable fwcacl:%d\n", Tmp_TxFwInfo.EnableCPUDur); |
| 1486 | printk("===>RTS STBC:%d\n", Tmp_TxFwInfo.RtsSTBC); |
| 1487 | printk("===>RTS Subcarrier:%d\n", Tmp_TxFwInfo.RtsSubcarrier); |
| 1488 | printk("===>Allow Aggregation:%d\n", Tmp_TxFwInfo.AllowAggregation); |
| 1489 | printk("===>TX HT bit:%d\n", Tmp_TxFwInfo.TxHT); |
| 1490 | printk("===>Tx rate:%d\n", Tmp_TxFwInfo.TxRate); |
| 1491 | printk("===>Received AMPDU Density:%d\n", Tmp_TxFwInfo.RxAMD); |
| 1492 | printk("===>Received MPDU Factor:%d\n", Tmp_TxFwInfo.RxMF); |
| 1493 | printk("===>TxBandwidth:%d\n", Tmp_TxFwInfo.TxBandwidth); |
| 1494 | printk("===>TxSubCarrier:%d\n", Tmp_TxFwInfo.TxSubCarrier); |
| 1495 | |
| 1496 | printk("<=====**********************out of print\n"); |
| 1497 | |
| 1498 | } |
| 1499 | spin_lock_irqsave(&priv->irq_th_lock,flags); |
| 1500 | ring = &priv->tx_ring[tcb_desc->queue_index]; |
| 1501 | if (tcb_desc->queue_index != BEACON_QUEUE) { |
| 1502 | idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries; |
| 1503 | } else { |
| 1504 | idx = 0; |
| 1505 | } |
| 1506 | |
| 1507 | pdesc = &ring->desc[idx]; |
| 1508 | if((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) { |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 1509 | RT_TRACE(COMP_ERR,"No more TX desc@%d, ring->idx = %d,idx = %d,%x", |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1510 | tcb_desc->queue_index,ring->idx, idx,skb->len); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 1511 | spin_unlock_irqrestore(&priv->irq_th_lock,flags); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1512 | return skb->len; |
| 1513 | } |
| 1514 | |
| 1515 | /* fill tx descriptor */ |
| 1516 | memset((u8*)pdesc,0,12); |
| 1517 | /*DWORD 0*/ |
| 1518 | pdesc->LINIP = 0; |
| 1519 | pdesc->CmdInit = 1; |
| 1520 | pdesc->Offset = sizeof(TX_FWINFO_8190PCI) + 8; //We must add 8!! Emily |
| 1521 | pdesc->PktSize = (u16)skb->len-sizeof(TX_FWINFO_8190PCI); |
| 1522 | |
| 1523 | /*DWORD 1*/ |
| 1524 | pdesc->SecCAMID= 0; |
| 1525 | pdesc->RATid = tcb_desc->RATRIndex; |
| 1526 | |
| 1527 | |
| 1528 | pdesc->NoEnc = 1; |
| 1529 | pdesc->SecType = 0x0; |
| 1530 | if (tcb_desc->bHwSec) { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1531 | switch (priv->ieee80211->pairwise_key_type) { |
| 1532 | case KEY_TYPE_WEP40: |
| 1533 | case KEY_TYPE_WEP104: |
| 1534 | pdesc->SecType = 0x1; |
| 1535 | pdesc->NoEnc = 0; |
| 1536 | break; |
| 1537 | case KEY_TYPE_TKIP: |
| 1538 | pdesc->SecType = 0x2; |
| 1539 | pdesc->NoEnc = 0; |
| 1540 | break; |
| 1541 | case KEY_TYPE_CCMP: |
| 1542 | pdesc->SecType = 0x3; |
| 1543 | pdesc->NoEnc = 0; |
| 1544 | break; |
| 1545 | case KEY_TYPE_NA: |
| 1546 | pdesc->SecType = 0x0; |
| 1547 | pdesc->NoEnc = 1; |
| 1548 | break; |
| 1549 | } |
| 1550 | } |
| 1551 | |
| 1552 | // |
| 1553 | // Set Packet ID |
| 1554 | // |
| 1555 | pdesc->PktId = 0x0; |
| 1556 | |
| 1557 | pdesc->QueueSelect = MapHwQueueToFirmwareQueue(tcb_desc->queue_index); |
| 1558 | pdesc->TxFWInfoSize = sizeof(TX_FWINFO_8190PCI); |
| 1559 | |
| 1560 | pdesc->DISFB = tcb_desc->bTxDisableRateFallBack; |
| 1561 | pdesc->USERATE = tcb_desc->bTxUseDriverAssingedRate; |
| 1562 | |
| 1563 | pdesc->FirstSeg =1; |
| 1564 | pdesc->LastSeg = 1; |
| 1565 | pdesc->TxBufferSize = skb->len; |
| 1566 | |
| 1567 | pdesc->TxBuffAddr = cpu_to_le32(mapping); |
| 1568 | __skb_queue_tail(&ring->queue, skb); |
| 1569 | pdesc->OWN = 1; |
| 1570 | spin_unlock_irqrestore(&priv->irq_th_lock,flags); |
| 1571 | dev->trans_start = jiffies; |
| 1572 | write_nic_word(dev,TPPoll,0x01<<tcb_desc->queue_index); |
| 1573 | return 0; |
| 1574 | } |
| 1575 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1576 | static short rtl8192_alloc_rx_desc_ring(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1577 | { |
| 1578 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1579 | rx_desc_819x_pci *entry = NULL; |
| 1580 | int i; |
| 1581 | |
| 1582 | priv->rx_ring = pci_alloc_consistent(priv->pdev, |
| 1583 | sizeof(*priv->rx_ring) * priv->rxringcount, &priv->rx_ring_dma); |
| 1584 | |
| 1585 | if (!priv->rx_ring || (unsigned long)priv->rx_ring & 0xFF) { |
| 1586 | RT_TRACE(COMP_ERR,"Cannot allocate RX ring\n"); |
| 1587 | return -ENOMEM; |
| 1588 | } |
| 1589 | |
| 1590 | memset(priv->rx_ring, 0, sizeof(*priv->rx_ring) * priv->rxringcount); |
| 1591 | priv->rx_idx = 0; |
| 1592 | |
| 1593 | for (i = 0; i < priv->rxringcount; i++) { |
| 1594 | struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize); |
| 1595 | dma_addr_t *mapping; |
| 1596 | entry = &priv->rx_ring[i]; |
| 1597 | if (!skb) |
| 1598 | return 0; |
| 1599 | priv->rx_buf[i] = skb; |
| 1600 | mapping = (dma_addr_t *)skb->cb; |
Jeff Mahoney | 1c7ec2e | 2010-01-11 10:54:27 -0500 | [diff] [blame] | 1601 | *mapping = pci_map_single(priv->pdev, skb_tail_pointer(skb), |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1602 | priv->rxbuffersize, PCI_DMA_FROMDEVICE); |
| 1603 | |
| 1604 | entry->BufferAddress = cpu_to_le32(*mapping); |
| 1605 | |
| 1606 | entry->Length = priv->rxbuffersize; |
| 1607 | entry->OWN = 1; |
| 1608 | } |
| 1609 | |
| 1610 | entry->EOR = 1; |
| 1611 | return 0; |
| 1612 | } |
| 1613 | |
| 1614 | static int rtl8192_alloc_tx_desc_ring(struct net_device *dev, |
| 1615 | unsigned int prio, unsigned int entries) |
| 1616 | { |
| 1617 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 1618 | tx_desc_819x_pci *ring; |
| 1619 | dma_addr_t dma; |
| 1620 | int i; |
| 1621 | |
| 1622 | ring = pci_alloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma); |
| 1623 | if (!ring || (unsigned long)ring & 0xFF) { |
| 1624 | RT_TRACE(COMP_ERR, "Cannot allocate TX ring (prio = %d)\n", prio); |
| 1625 | return -ENOMEM; |
| 1626 | } |
| 1627 | |
| 1628 | memset(ring, 0, sizeof(*ring)*entries); |
| 1629 | priv->tx_ring[prio].desc = ring; |
| 1630 | priv->tx_ring[prio].dma = dma; |
| 1631 | priv->tx_ring[prio].idx = 0; |
| 1632 | priv->tx_ring[prio].entries = entries; |
| 1633 | skb_queue_head_init(&priv->tx_ring[prio].queue); |
| 1634 | |
| 1635 | for (i = 0; i < entries; i++) |
| 1636 | ring[i].NextDescAddress = |
| 1637 | cpu_to_le32((u32)dma + ((i + 1) % entries) * sizeof(*ring)); |
| 1638 | |
| 1639 | return 0; |
| 1640 | } |
| 1641 | |
| 1642 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1643 | static short rtl8192_pci_initdescring(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1644 | { |
| 1645 | u32 ret; |
| 1646 | int i; |
| 1647 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1648 | |
| 1649 | ret = rtl8192_alloc_rx_desc_ring(dev); |
| 1650 | if (ret) { |
| 1651 | return ret; |
| 1652 | } |
| 1653 | |
| 1654 | |
| 1655 | /* general process for other queue */ |
| 1656 | for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) { |
Joe Perches | d6d42df | 2010-03-24 22:17:02 -0700 | [diff] [blame] | 1657 | ret = rtl8192_alloc_tx_desc_ring(dev, i, priv->txringcount); |
| 1658 | if (ret) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1659 | goto err_free_rings; |
| 1660 | } |
| 1661 | |
| 1662 | #if 0 |
| 1663 | /* specific process for hardware beacon process */ |
Joe Perches | d6d42df | 2010-03-24 22:17:02 -0700 | [diff] [blame] | 1664 | ret = rtl8192_alloc_tx_desc_ring(dev, MAX_TX_QUEUE_COUNT - 1, 2); |
| 1665 | if (ret) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1666 | goto err_free_rings; |
| 1667 | #endif |
| 1668 | |
| 1669 | return 0; |
| 1670 | |
| 1671 | err_free_rings: |
| 1672 | rtl8192_free_rx_ring(dev); |
| 1673 | for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) |
| 1674 | if (priv->tx_ring[i].desc) |
| 1675 | rtl8192_free_tx_ring(dev, i); |
| 1676 | return 1; |
| 1677 | } |
| 1678 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1679 | static void rtl8192_pci_resetdescring(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1680 | { |
| 1681 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1682 | int i; |
| 1683 | |
| 1684 | /* force the rx_idx to the first one */ |
| 1685 | if(priv->rx_ring) { |
| 1686 | rx_desc_819x_pci *entry = NULL; |
| 1687 | for (i = 0; i < priv->rxringcount; i++) { |
| 1688 | entry = &priv->rx_ring[i]; |
| 1689 | entry->OWN = 1; |
| 1690 | } |
| 1691 | priv->rx_idx = 0; |
| 1692 | } |
| 1693 | |
| 1694 | /* after reset, release previous pending packet, and force the |
| 1695 | * tx idx to the first one */ |
| 1696 | for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) { |
| 1697 | if (priv->tx_ring[i].desc) { |
| 1698 | struct rtl8192_tx_ring *ring = &priv->tx_ring[i]; |
| 1699 | |
| 1700 | while (skb_queue_len(&ring->queue)) { |
| 1701 | tx_desc_819x_pci *entry = &ring->desc[ring->idx]; |
| 1702 | struct sk_buff *skb = __skb_dequeue(&ring->queue); |
| 1703 | |
| 1704 | pci_unmap_single(priv->pdev, le32_to_cpu(entry->TxBuffAddr), |
| 1705 | skb->len, PCI_DMA_TODEVICE); |
| 1706 | kfree_skb(skb); |
| 1707 | ring->idx = (ring->idx + 1) % ring->entries; |
| 1708 | } |
| 1709 | ring->idx = 0; |
| 1710 | } |
| 1711 | } |
| 1712 | } |
| 1713 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1714 | static void rtl8192_link_change(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1715 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1716 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1717 | struct ieee80211_device* ieee = priv->ieee80211; |
| 1718 | //write_nic_word(dev, BCN_INTR_ITV, net->beacon_interval); |
| 1719 | if (ieee->state == IEEE80211_LINKED) |
| 1720 | { |
| 1721 | rtl8192_net_update(dev); |
| 1722 | rtl8192_update_ratr_table(dev); |
| 1723 | #if 1 |
| 1724 | //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 |
| 1725 | if ((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) |
| 1726 | EnableHWSecurityConfig8192(dev); |
| 1727 | #endif |
| 1728 | } |
| 1729 | else |
| 1730 | { |
| 1731 | write_nic_byte(dev, 0x173, 0); |
| 1732 | } |
| 1733 | /*update timing params*/ |
| 1734 | //rtl8192_set_chan(dev, priv->chan); |
| 1735 | //MSR |
| 1736 | rtl8192_update_msr(dev); |
| 1737 | |
| 1738 | // 2007/10/16 MH MAC Will update TSF according to all received beacon, so we have |
| 1739 | // // To set CBSSID bit when link with any AP or STA. |
| 1740 | if (ieee->iw_mode == IW_MODE_INFRA || ieee->iw_mode == IW_MODE_ADHOC) |
| 1741 | { |
| 1742 | u32 reg = 0; |
| 1743 | reg = read_nic_dword(dev, RCR); |
| 1744 | if (priv->ieee80211->state == IEEE80211_LINKED) |
| 1745 | priv->ReceiveConfig = reg |= RCR_CBSSID; |
| 1746 | else |
| 1747 | priv->ReceiveConfig = reg &= ~RCR_CBSSID; |
| 1748 | write_nic_dword(dev, RCR, reg); |
| 1749 | } |
| 1750 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1751 | |
| 1752 | |
Mike McCormack | 5b3b1a7 | 2010-08-10 23:44:36 +0900 | [diff] [blame] | 1753 | static const struct ieee80211_qos_parameters def_qos_parameters = { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1754 | {3,3,3,3},/* cw_min */ |
| 1755 | {7,7,7,7},/* cw_max */ |
| 1756 | {2,2,2,2},/* aifs */ |
| 1757 | {0,0,0,0},/* flags */ |
| 1758 | {0,0,0,0} /* tx_op_limit */ |
| 1759 | }; |
| 1760 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1761 | static void rtl8192_update_beacon(struct work_struct * work) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1762 | { |
| 1763 | struct r8192_priv *priv = container_of(work, struct r8192_priv, update_beacon_wq.work); |
| 1764 | struct net_device *dev = priv->ieee80211->dev; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1765 | struct ieee80211_device* ieee = priv->ieee80211; |
| 1766 | struct ieee80211_network* net = &ieee->current_network; |
| 1767 | |
| 1768 | if (ieee->pHTInfo->bCurrentHTSupport) |
| 1769 | HTUpdateSelfAndPeerSetting(ieee, net); |
| 1770 | ieee->pHTInfo->bCurrentRT2RTLongSlotTime = net->bssht.bdRT2RTLongSlotTime; |
| 1771 | rtl8192_update_cap(dev, net->capability); |
| 1772 | } |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 1773 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1774 | /* |
| 1775 | * background support to run QoS activate functionality |
| 1776 | */ |
Mike McCormack | 881a975 | 2010-07-26 22:58:03 +0900 | [diff] [blame] | 1777 | static const int WDCAPARA_ADD[] = {EDCAPARA_BE,EDCAPARA_BK,EDCAPARA_VI,EDCAPARA_VO}; |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1778 | static void rtl8192_qos_activate(struct work_struct * work) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1779 | { |
| 1780 | struct r8192_priv *priv = container_of(work, struct r8192_priv, qos_activate); |
| 1781 | struct net_device *dev = priv->ieee80211->dev; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1782 | struct ieee80211_qos_parameters *qos_parameters = &priv->ieee80211->current_network.qos_data.parameters; |
| 1783 | u8 mode = priv->ieee80211->current_network.mode; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1784 | u8 u1bAIFS; |
| 1785 | u32 u4bAcParam; |
| 1786 | int i; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1787 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1788 | mutex_lock(&priv->mutex); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1789 | if(priv->ieee80211->state != IEEE80211_LINKED) |
| 1790 | goto success; |
| 1791 | RT_TRACE(COMP_QOS,"qos active process with associate response received\n"); |
| 1792 | /* It better set slot time at first */ |
| 1793 | /* For we just support b/g mode at present, let the slot time at 9/20 selection */ |
| 1794 | /* update the ac parameter to related registers */ |
| 1795 | for(i = 0; i < QOS_QUEUE_NUM; i++) { |
| 1796 | //Mode G/A: slotTimeTimer = 9; Mode B: 20 |
| 1797 | u1bAIFS = qos_parameters->aifs[i] * ((mode&(IEEE_G|IEEE_N_24G)) ?9:20) + aSifsTime; |
| 1798 | u4bAcParam = ((((u32)(qos_parameters->tx_op_limit[i]))<< AC_PARAM_TXOP_LIMIT_OFFSET)| |
| 1799 | (((u32)(qos_parameters->cw_max[i]))<< AC_PARAM_ECW_MAX_OFFSET)| |
| 1800 | (((u32)(qos_parameters->cw_min[i]))<< AC_PARAM_ECW_MIN_OFFSET)| |
| 1801 | ((u32)u1bAIFS << AC_PARAM_AIFS_OFFSET)); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 1802 | //printk("===>u4bAcParam:%x, ", u4bAcParam); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1803 | write_nic_dword(dev, WDCAPARA_ADD[i], u4bAcParam); |
| 1804 | //write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4332); |
| 1805 | } |
| 1806 | |
| 1807 | success: |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1808 | mutex_unlock(&priv->mutex); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1809 | } |
| 1810 | |
| 1811 | static int rtl8192_qos_handle_probe_response(struct r8192_priv *priv, |
| 1812 | int active_network, |
| 1813 | struct ieee80211_network *network) |
| 1814 | { |
| 1815 | int ret = 0; |
| 1816 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 1817 | |
| 1818 | if(priv->ieee80211->state !=IEEE80211_LINKED) |
| 1819 | return ret; |
| 1820 | |
| 1821 | if ((priv->ieee80211->iw_mode != IW_MODE_INFRA)) |
| 1822 | return ret; |
| 1823 | |
| 1824 | if (network->flags & NETWORK_HAS_QOS_MASK) { |
| 1825 | if (active_network && |
| 1826 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) |
| 1827 | network->qos_data.active = network->qos_data.supported; |
| 1828 | |
| 1829 | if ((network->qos_data.active == 1) && (active_network == 1) && |
| 1830 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && |
| 1831 | (network->qos_data.old_param_count != |
| 1832 | network->qos_data.param_count)) { |
| 1833 | network->qos_data.old_param_count = |
| 1834 | network->qos_data.param_count; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1835 | queue_work(priv->priv_wq, &priv->qos_activate); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1836 | RT_TRACE (COMP_QOS, "QoS parameters change call " |
| 1837 | "qos_activate\n"); |
| 1838 | } |
| 1839 | } else { |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 1840 | memcpy(&priv->ieee80211->current_network.qos_data.parameters, |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1841 | &def_qos_parameters, size); |
| 1842 | |
| 1843 | if ((network->qos_data.active == 1) && (active_network == 1)) { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1844 | queue_work(priv->priv_wq, &priv->qos_activate); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1845 | RT_TRACE(COMP_QOS, "QoS was disabled call qos_activate \n"); |
| 1846 | } |
| 1847 | network->qos_data.active = 0; |
| 1848 | network->qos_data.supported = 0; |
| 1849 | } |
| 1850 | |
| 1851 | return 0; |
| 1852 | } |
| 1853 | |
| 1854 | /* handle manage frame frame beacon and probe response */ |
| 1855 | static int rtl8192_handle_beacon(struct net_device * dev, |
| 1856 | struct ieee80211_beacon * beacon, |
| 1857 | struct ieee80211_network * network) |
| 1858 | { |
| 1859 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1860 | |
| 1861 | rtl8192_qos_handle_probe_response(priv,1,network); |
| 1862 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1863 | queue_delayed_work(priv->priv_wq, &priv->update_beacon_wq, 0); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1864 | return 0; |
| 1865 | |
| 1866 | } |
| 1867 | |
| 1868 | /* |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 1869 | * handling the beaconing responses. if we get different QoS setting |
| 1870 | * off the network from the associated setting, adjust the QoS setting |
| 1871 | */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1872 | static int rtl8192_qos_association_resp(struct r8192_priv *priv, |
| 1873 | struct ieee80211_network *network) |
| 1874 | { |
| 1875 | int ret = 0; |
| 1876 | unsigned long flags; |
| 1877 | u32 size = sizeof(struct ieee80211_qos_parameters); |
| 1878 | int set_qos_param = 0; |
| 1879 | |
| 1880 | if ((priv == NULL) || (network == NULL)) |
| 1881 | return ret; |
| 1882 | |
| 1883 | if(priv->ieee80211->state !=IEEE80211_LINKED) |
| 1884 | return ret; |
| 1885 | |
| 1886 | if ((priv->ieee80211->iw_mode != IW_MODE_INFRA)) |
| 1887 | return ret; |
| 1888 | |
| 1889 | spin_lock_irqsave(&priv->ieee80211->lock, flags); |
| 1890 | if(network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 1891 | memcpy(&priv->ieee80211->current_network.qos_data.parameters, |
| 1892 | &network->qos_data.parameters, |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1893 | sizeof(struct ieee80211_qos_parameters)); |
| 1894 | priv->ieee80211->current_network.qos_data.active = 1; |
| 1895 | #if 0 |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 1896 | if((priv->ieee80211->current_network.qos_data.param_count != |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1897 | network->qos_data.param_count)) |
| 1898 | #endif |
| 1899 | { |
| 1900 | set_qos_param = 1; |
| 1901 | /* update qos parameter for current network */ |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 1902 | priv->ieee80211->current_network.qos_data.old_param_count = |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1903 | priv->ieee80211->current_network.qos_data.param_count; |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 1904 | priv->ieee80211->current_network.qos_data.param_count = |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1905 | network->qos_data.param_count; |
| 1906 | } |
| 1907 | } else { |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 1908 | memcpy(&priv->ieee80211->current_network.qos_data.parameters, |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1909 | &def_qos_parameters, size); |
| 1910 | priv->ieee80211->current_network.qos_data.active = 0; |
| 1911 | priv->ieee80211->current_network.qos_data.supported = 0; |
| 1912 | set_qos_param = 1; |
| 1913 | } |
| 1914 | |
| 1915 | spin_unlock_irqrestore(&priv->ieee80211->lock, flags); |
| 1916 | |
| 1917 | RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n",__FUNCTION__,network->flags ,priv->ieee80211->current_network.qos_data.active); |
| 1918 | if (set_qos_param == 1) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1919 | queue_work(priv->priv_wq, &priv->qos_activate); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1920 | |
| 1921 | return ret; |
| 1922 | } |
| 1923 | |
| 1924 | |
| 1925 | static int rtl8192_handle_assoc_response(struct net_device *dev, |
| 1926 | struct ieee80211_assoc_response_frame *resp, |
| 1927 | struct ieee80211_network *network) |
| 1928 | { |
| 1929 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1930 | rtl8192_qos_association_resp(priv, network); |
| 1931 | return 0; |
| 1932 | } |
| 1933 | |
| 1934 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 1935 | /* updateRATRTabel for MCS only. Basic rate is not implemented. */ |
Mike McCormack | 5b3b1a7 | 2010-08-10 23:44:36 +0900 | [diff] [blame] | 1936 | static void rtl8192_update_ratr_table(struct net_device* dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1937 | { |
| 1938 | struct r8192_priv* priv = ieee80211_priv(dev); |
| 1939 | struct ieee80211_device* ieee = priv->ieee80211; |
| 1940 | u8* pMcsRate = ieee->dot11HTOperationalRateSet; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1941 | u32 ratr_value = 0; |
| 1942 | u8 rate_index = 0; |
| 1943 | |
| 1944 | rtl8192_config_rate(dev, (u16*)(&ratr_value)); |
| 1945 | ratr_value |= (*(u16*)(pMcsRate)) << 12; |
Mike McCormack | 16d74da | 2010-09-20 23:11:14 +0900 | [diff] [blame] | 1946 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1947 | switch (ieee->mode) |
| 1948 | { |
| 1949 | case IEEE_A: |
| 1950 | ratr_value &= 0x00000FF0; |
| 1951 | break; |
| 1952 | case IEEE_B: |
| 1953 | ratr_value &= 0x0000000F; |
| 1954 | break; |
| 1955 | case IEEE_G: |
| 1956 | ratr_value &= 0x00000FF7; |
| 1957 | break; |
| 1958 | case IEEE_N_24G: |
| 1959 | case IEEE_N_5G: |
| 1960 | if (ieee->pHTInfo->PeerMimoPs == 0) //MIMO_PS_STATIC |
| 1961 | ratr_value &= 0x0007F007; |
| 1962 | else{ |
| 1963 | if (priv->rf_type == RF_1T2R) |
| 1964 | ratr_value &= 0x000FF007; |
| 1965 | else |
| 1966 | ratr_value &= 0x0F81F007; |
| 1967 | } |
| 1968 | break; |
| 1969 | default: |
| 1970 | break; |
| 1971 | } |
| 1972 | ratr_value &= 0x0FFFFFFF; |
| 1973 | if(ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI40MHz){ |
| 1974 | ratr_value |= 0x80000000; |
| 1975 | }else if(!ieee->pHTInfo->bCurTxBW40MHz && ieee->pHTInfo->bCurShortGI20MHz){ |
| 1976 | ratr_value |= 0x80000000; |
| 1977 | } |
| 1978 | write_nic_dword(dev, RATR0+rate_index*4, ratr_value); |
| 1979 | write_nic_byte(dev, UFWP, 1); |
| 1980 | } |
| 1981 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1982 | static bool GetNmodeSupportBySecCfg8190Pci(struct net_device*dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1983 | { |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 1984 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 1985 | struct ieee80211_device *ieee = priv->ieee80211; |
Mike McCormack | f8acdc3 | 2010-09-24 18:38:51 +0900 | [diff] [blame^] | 1986 | |
Mike McCormack | 285f660 | 2010-08-10 23:44:03 +0900 | [diff] [blame] | 1987 | return !(ieee->rtllib_ap_sec_type && |
Mike McCormack | f8acdc3 | 2010-09-24 18:38:51 +0900 | [diff] [blame^] | 1988 | (ieee->rtllib_ap_sec_type(ieee)&(SEC_ALG_WEP|SEC_ALG_TKIP))); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1989 | } |
| 1990 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 1991 | static void rtl8192_refresh_supportrate(struct r8192_priv* priv) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 1992 | { |
| 1993 | struct ieee80211_device* ieee = priv->ieee80211; |
| 1994 | //we donot consider set support rate for ABG mode, only HT MCS rate is set here. |
| 1995 | if (ieee->mode == WIRELESS_MODE_N_24G || ieee->mode == WIRELESS_MODE_N_5G) |
| 1996 | { |
| 1997 | memcpy(ieee->Regdot11HTOperationalRateSet, ieee->RegHTSuppRateSet, 16); |
| 1998 | //RT_DEBUG_DATA(COMP_INIT, ieee->RegHTSuppRateSet, 16); |
| 1999 | //RT_DEBUG_DATA(COMP_INIT, ieee->Regdot11HTOperationalRateSet, 16); |
| 2000 | } |
| 2001 | else |
| 2002 | memset(ieee->Regdot11HTOperationalRateSet, 0, 16); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 2005 | static u8 rtl8192_getSupportedWireleeMode(struct net_device*dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2006 | { |
| 2007 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2008 | u8 ret = 0; |
| 2009 | switch(priv->rf_chip) |
| 2010 | { |
| 2011 | case RF_8225: |
| 2012 | case RF_8256: |
| 2013 | case RF_PSEUDO_11N: |
| 2014 | ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G|WIRELESS_MODE_B); |
| 2015 | break; |
| 2016 | case RF_8258: |
| 2017 | ret = (WIRELESS_MODE_A|WIRELESS_MODE_N_5G); |
| 2018 | break; |
| 2019 | default: |
| 2020 | ret = WIRELESS_MODE_B; |
| 2021 | break; |
| 2022 | } |
| 2023 | return ret; |
| 2024 | } |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 2025 | |
| 2026 | static void rtl8192_SetWirelessMode(struct net_device* dev, u8 wireless_mode) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2027 | { |
| 2028 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2029 | u8 bSupportMode = rtl8192_getSupportedWireleeMode(dev); |
| 2030 | |
| 2031 | #if 1 |
| 2032 | if ((wireless_mode == WIRELESS_MODE_AUTO) || ((wireless_mode&bSupportMode)==0)) |
| 2033 | { |
| 2034 | if(bSupportMode & WIRELESS_MODE_N_24G) |
| 2035 | { |
| 2036 | wireless_mode = WIRELESS_MODE_N_24G; |
| 2037 | } |
| 2038 | else if(bSupportMode & WIRELESS_MODE_N_5G) |
| 2039 | { |
| 2040 | wireless_mode = WIRELESS_MODE_N_5G; |
| 2041 | } |
| 2042 | else if((bSupportMode & WIRELESS_MODE_A)) |
| 2043 | { |
| 2044 | wireless_mode = WIRELESS_MODE_A; |
| 2045 | } |
| 2046 | else if((bSupportMode & WIRELESS_MODE_G)) |
| 2047 | { |
| 2048 | wireless_mode = WIRELESS_MODE_G; |
| 2049 | } |
| 2050 | else if((bSupportMode & WIRELESS_MODE_B)) |
| 2051 | { |
| 2052 | wireless_mode = WIRELESS_MODE_B; |
| 2053 | } |
| 2054 | else{ |
| 2055 | RT_TRACE(COMP_ERR, "%s(), No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n", __FUNCTION__,bSupportMode); |
| 2056 | wireless_mode = WIRELESS_MODE_B; |
| 2057 | } |
| 2058 | } |
Adam Buchbinder | 39cfb97 | 2009-12-18 15:43:51 -0500 | [diff] [blame] | 2059 | #ifdef TO_DO_LIST //// TODO: this function doesn't work well at this time, we should wait for FPGA |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2060 | ActUpdateChannelAccessSetting( pAdapter, pHalData->CurrentWirelessMode, &pAdapter->MgntInfo.Info8185.ChannelAccessSetting ); |
| 2061 | #endif |
| 2062 | priv->ieee80211->mode = wireless_mode; |
| 2063 | |
| 2064 | if ((wireless_mode == WIRELESS_MODE_N_24G) || (wireless_mode == WIRELESS_MODE_N_5G)) |
| 2065 | priv->ieee80211->pHTInfo->bEnableHT = 1; |
| 2066 | else |
| 2067 | priv->ieee80211->pHTInfo->bEnableHT = 0; |
| 2068 | RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode); |
| 2069 | rtl8192_refresh_supportrate(priv); |
| 2070 | #endif |
| 2071 | |
| 2072 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2073 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 2074 | static bool GetHalfNmodeSupportByAPs819xPci(struct net_device* dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2075 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2076 | struct r8192_priv* priv = ieee80211_priv(dev); |
| 2077 | struct ieee80211_device* ieee = priv->ieee80211; |
| 2078 | |
Mike McCormack | 285f660 | 2010-08-10 23:44:03 +0900 | [diff] [blame] | 2079 | return ieee->bHalfWirelessN24GMode; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | short rtl8192_is_tx_queue_empty(struct net_device *dev) |
| 2083 | { |
| 2084 | int i=0; |
| 2085 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2086 | for (i=0; i<=MGNT_QUEUE; i++) |
| 2087 | { |
| 2088 | if ((i== TXCMD_QUEUE) || (i == HCCA_QUEUE) ) |
| 2089 | continue; |
| 2090 | if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0){ |
| 2091 | printk("===>tx queue is not empty:%d, %d\n", i, skb_queue_len(&(&priv->tx_ring[i])->queue)); |
| 2092 | return 0; |
| 2093 | } |
| 2094 | } |
| 2095 | return 1; |
| 2096 | } |
Mike McCormack | 16d74da | 2010-09-20 23:11:14 +0900 | [diff] [blame] | 2097 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 2098 | static void rtl8192_hw_sleep_down(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2099 | { |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2100 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2101 | unsigned long flags = 0; |
| 2102 | |
| 2103 | spin_lock_irqsave(&priv->rf_ps_lock,flags); |
| 2104 | if (priv->RFChangeInProgress) { |
| 2105 | spin_unlock_irqrestore(&priv->rf_ps_lock,flags); |
| 2106 | RT_TRACE(COMP_RF, "rtl8192_hw_sleep_down(): RF Change in progress! \n"); |
| 2107 | printk("rtl8192_hw_sleep_down(): RF Change in progress!\n"); |
| 2108 | return; |
| 2109 | } |
| 2110 | spin_unlock_irqrestore(&priv->rf_ps_lock,flags); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2111 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2112 | MgntActSet_RF_State(dev, eRfSleep, RF_CHANGE_BY_PS); |
| 2113 | } |
Mike McCormack | 16d74da | 2010-09-20 23:11:14 +0900 | [diff] [blame] | 2114 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 2115 | static void rtl8192_hw_sleep_wq (struct work_struct *work) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2116 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2117 | struct delayed_work *dwork = container_of(work,struct delayed_work,work); |
| 2118 | struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_sleep_wq); |
| 2119 | struct net_device *dev = ieee->dev; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2120 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2121 | rtl8192_hw_sleep_down(dev); |
| 2122 | } |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2123 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 2124 | static void rtl8192_hw_wakeup(struct net_device* dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2125 | { |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2126 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2127 | unsigned long flags = 0; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2128 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2129 | spin_lock_irqsave(&priv->rf_ps_lock,flags); |
| 2130 | if (priv->RFChangeInProgress) { |
| 2131 | spin_unlock_irqrestore(&priv->rf_ps_lock,flags); |
| 2132 | RT_TRACE(COMP_RF, "rtl8192_hw_wakeup(): RF Change in progress! \n"); |
| 2133 | printk("rtl8192_hw_wakeup(): RF Change in progress! schedule wake up task again\n"); |
| 2134 | 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 |
| 2135 | return; |
| 2136 | } |
| 2137 | spin_unlock_irqrestore(&priv->rf_ps_lock,flags); |
| 2138 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2139 | MgntActSet_RF_State(dev, eRfOn, RF_CHANGE_BY_PS); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2140 | } |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2141 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2142 | void rtl8192_hw_wakeup_wq (struct work_struct *work) |
| 2143 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2144 | struct delayed_work *dwork = container_of(work,struct delayed_work,work); |
| 2145 | struct ieee80211_device *ieee = container_of(dwork,struct ieee80211_device,hw_wakeup_wq); |
| 2146 | struct net_device *dev = ieee->dev; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2147 | rtl8192_hw_wakeup(dev); |
| 2148 | |
| 2149 | } |
| 2150 | |
| 2151 | #define MIN_SLEEP_TIME 50 |
| 2152 | #define MAX_SLEEP_TIME 10000 |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 2153 | static void rtl8192_hw_to_sleep(struct net_device *dev, u32 th, u32 tl) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2154 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2155 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2156 | |
| 2157 | u32 rb = jiffies; |
| 2158 | unsigned long flags; |
| 2159 | |
| 2160 | spin_lock_irqsave(&priv->ps_lock,flags); |
| 2161 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2162 | // Writing HW register with 0 equals to disable |
| 2163 | // the timer, that is not really what we want |
| 2164 | // |
| 2165 | tl -= MSECS(8+16+7); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2166 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2167 | // If the interval in witch we are requested to sleep is too |
| 2168 | // short then give up and remain awake |
| 2169 | // when we sleep after send null frame, the timer will be too short to sleep. |
| 2170 | // |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2171 | if(((tl>=rb)&& (tl-rb) <= MSECS(MIN_SLEEP_TIME)) |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2172 | ||((rb>tl)&& (rb-tl) < MSECS(MIN_SLEEP_TIME))) { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2173 | spin_unlock_irqrestore(&priv->ps_lock,flags); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2174 | printk("too short to sleep::%x, %x, %lx\n",tl, rb, MSECS(MIN_SLEEP_TIME)); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2175 | return; |
| 2176 | } |
| 2177 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2178 | if(((tl > rb) && ((tl-rb) > MSECS(MAX_SLEEP_TIME)))|| |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2179 | ((tl < rb) && (tl>MSECS(69)) && ((rb-tl) > MSECS(MAX_SLEEP_TIME)))|| |
| 2180 | ((tl<rb)&&(tl<MSECS(69))&&((tl+0xffffffff-rb)>MSECS(MAX_SLEEP_TIME)))) { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2181 | printk("========>too long to sleep:%x, %x, %lx\n", tl, rb, MSECS(MAX_SLEEP_TIME)); |
| 2182 | spin_unlock_irqrestore(&priv->ps_lock,flags); |
| 2183 | return; |
| 2184 | } |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2185 | { |
| 2186 | u32 tmp = (tl>rb)?(tl-rb):(rb-tl); |
| 2187 | queue_delayed_work(priv->ieee80211->wq, |
| 2188 | &priv->ieee80211->hw_wakeup_wq,tmp); |
| 2189 | //PowerSave not supported when kernel version less 2.6.20 |
| 2190 | } |
| 2191 | queue_delayed_work(priv->ieee80211->wq, |
| 2192 | (void *)&priv->ieee80211->hw_sleep_wq,0); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2193 | spin_unlock_irqrestore(&priv->ps_lock,flags); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2194 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2195 | } |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 2196 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2197 | static void rtl8192_init_priv_variable(struct net_device* dev) |
| 2198 | { |
| 2199 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2200 | u8 i; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2201 | PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl)); |
| 2202 | |
| 2203 | // Default Halt the NIC if RF is OFF. |
| 2204 | pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_HALT_NIC; |
| 2205 | pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_CLK_REQ; |
| 2206 | pPSC->RegRfPsLevel |= RT_RF_OFF_LEVL_ASPM; |
| 2207 | pPSC->RegRfPsLevel |= RT_RF_LPS_LEVEL_ASPM; |
| 2208 | pPSC->bLeisurePs = true; |
| 2209 | pPSC->RegMaxLPSAwakeIntvl = 5; |
| 2210 | priv->bHwRadioOff = false; |
| 2211 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2212 | priv->being_init_adapter = false; |
| 2213 | priv->txbuffsize = 1600;//1024; |
| 2214 | priv->txfwbuffersize = 4096; |
| 2215 | priv->txringcount = 64;//32; |
| 2216 | //priv->txbeaconcount = priv->txringcount; |
| 2217 | priv->txbeaconcount = 2; |
| 2218 | priv->rxbuffersize = 9100;//2048;//1024; |
| 2219 | priv->rxringcount = MAX_RX_COUNT;//64; |
| 2220 | priv->irq_enabled=0; |
| 2221 | priv->card_8192 = NIC_8192E; |
| 2222 | priv->rx_skb_complete = 1; |
| 2223 | priv->chan = 1; //set to channel 1 |
| 2224 | priv->RegWirelessMode = WIRELESS_MODE_AUTO; |
| 2225 | priv->RegChannelPlan = 0xf; |
| 2226 | priv->nrxAMPDU_size = 0; |
| 2227 | priv->nrxAMPDU_aggr_num = 0; |
| 2228 | priv->last_rxdesc_tsf_high = 0; |
| 2229 | priv->last_rxdesc_tsf_low = 0; |
| 2230 | priv->ieee80211->mode = WIRELESS_MODE_AUTO; //SET AUTO |
| 2231 | priv->ieee80211->iw_mode = IW_MODE_INFRA; |
| 2232 | priv->ieee80211->ieee_up=0; |
| 2233 | priv->retry_rts = DEFAULT_RETRY_RTS; |
| 2234 | priv->retry_data = DEFAULT_RETRY_DATA; |
| 2235 | priv->ieee80211->rts = DEFAULT_RTS_THRESHOLD; |
| 2236 | priv->ieee80211->rate = 110; //11 mbps |
| 2237 | priv->ieee80211->short_slot = 1; |
| 2238 | priv->promisc = (dev->flags & IFF_PROMISC) ? 1:0; |
| 2239 | priv->bcck_in_ch14 = false; |
| 2240 | priv->bfsync_processing = false; |
| 2241 | priv->CCKPresentAttentuation = 0; |
| 2242 | priv->rfa_txpowertrackingindex = 0; |
| 2243 | priv->rfc_txpowertrackingindex = 0; |
| 2244 | priv->CckPwEnl = 6; |
| 2245 | priv->ScanDelay = 50;//for Scan TODO |
| 2246 | //added by amy for silent reset |
| 2247 | priv->ResetProgress = RESET_TYPE_NORESET; |
| 2248 | priv->bForcedSilentReset = 0; |
| 2249 | priv->bDisableNormalResetCheck = false; |
| 2250 | priv->force_reset = false; |
| 2251 | //added by amy for power save |
| 2252 | priv->RegRfOff = 0; |
| 2253 | priv->ieee80211->RfOffReason = 0; |
| 2254 | priv->RFChangeInProgress = false; |
| 2255 | priv->bHwRfOffAction = 0; |
| 2256 | priv->SetRFPowerStateInProgress = false; |
| 2257 | priv->ieee80211->PowerSaveControl.bInactivePs = true; |
| 2258 | priv->ieee80211->PowerSaveControl.bIPSModeBackup = false; |
| 2259 | //just for debug |
| 2260 | priv->txpower_checkcnt = 0; |
| 2261 | priv->thermal_readback_index =0; |
| 2262 | priv->txpower_tracking_callback_cnt = 0; |
| 2263 | priv->ccktxpower_adjustcnt_ch14 = 0; |
| 2264 | priv->ccktxpower_adjustcnt_not_ch14 = 0; |
| 2265 | |
| 2266 | priv->ieee80211->current_network.beacon_interval = DEFAULT_BEACONINTERVAL; |
| 2267 | priv->ieee80211->iw_mode = IW_MODE_INFRA; |
| 2268 | priv->ieee80211->softmac_features = IEEE_SOFTMAC_SCAN | |
| 2269 | IEEE_SOFTMAC_ASSOCIATE | IEEE_SOFTMAC_PROBERQ | |
| 2270 | IEEE_SOFTMAC_PROBERS | IEEE_SOFTMAC_TX_QUEUE;/* | |
| 2271 | IEEE_SOFTMAC_BEACONS;*///added by amy 080604 //| //IEEE_SOFTMAC_SINGLE_QUEUE; |
| 2272 | |
| 2273 | priv->ieee80211->active_scan = 1; |
| 2274 | priv->ieee80211->modulation = IEEE80211_CCK_MODULATION | IEEE80211_OFDM_MODULATION; |
| 2275 | priv->ieee80211->host_encrypt = 1; |
| 2276 | priv->ieee80211->host_decrypt = 1; |
| 2277 | //priv->ieee80211->start_send_beacons = NULL;//rtl819xusb_beacon_tx;//-by amy 080604 |
| 2278 | //priv->ieee80211->stop_send_beacons = NULL;//rtl8192_beacon_stop;//-by amy 080604 |
| 2279 | priv->ieee80211->start_send_beacons = rtl8192_start_beacon;//+by david 081107 |
| 2280 | priv->ieee80211->stop_send_beacons = rtl8192_stop_beacon;//+by david 081107 |
| 2281 | priv->ieee80211->softmac_hard_start_xmit = rtl8192_hard_start_xmit; |
| 2282 | priv->ieee80211->set_chan = rtl8192_set_chan; |
| 2283 | priv->ieee80211->link_change = rtl8192_link_change; |
| 2284 | priv->ieee80211->softmac_data_hard_start_xmit = rtl8192_hard_data_xmit; |
| 2285 | priv->ieee80211->data_hard_stop = rtl8192_data_hard_stop; |
| 2286 | priv->ieee80211->data_hard_resume = rtl8192_data_hard_resume; |
| 2287 | priv->ieee80211->init_wmmparam_flag = 0; |
| 2288 | priv->ieee80211->fts = DEFAULT_FRAG_THRESHOLD; |
| 2289 | priv->ieee80211->check_nic_enough_desc = check_nic_enough_desc; |
| 2290 | priv->ieee80211->tx_headroom = sizeof(TX_FWINFO_8190PCI); |
| 2291 | priv->ieee80211->qos_support = 1; |
| 2292 | priv->ieee80211->dot11PowerSaveMode = 0; |
| 2293 | //added by WB |
| 2294 | // priv->ieee80211->SwChnlByTimerHandler = rtl8192_phy_SwChnl; |
| 2295 | priv->ieee80211->SetBWModeHandler = rtl8192_SetBWMode; |
| 2296 | priv->ieee80211->handle_assoc_response = rtl8192_handle_assoc_response; |
| 2297 | priv->ieee80211->handle_beacon = rtl8192_handle_beacon; |
| 2298 | |
| 2299 | priv->ieee80211->sta_wake_up = rtl8192_hw_wakeup; |
| 2300 | // priv->ieee80211->ps_request_tx_ack = rtl8192_rq_tx_ack; |
| 2301 | priv->ieee80211->enter_sleep_state = rtl8192_hw_to_sleep; |
| 2302 | priv->ieee80211->ps_is_queue_empty = rtl8192_is_tx_queue_empty; |
| 2303 | //added by david |
| 2304 | priv->ieee80211->GetNmodeSupportBySecCfg = GetNmodeSupportBySecCfg8190Pci; |
| 2305 | priv->ieee80211->SetWirelessMode = rtl8192_SetWirelessMode; |
| 2306 | priv->ieee80211->GetHalfNmodeSupportByAPsHandler = GetHalfNmodeSupportByAPs819xPci; |
| 2307 | |
| 2308 | //added by amy |
| 2309 | priv->ieee80211->InitialGainHandler = InitialGain819xPci; |
| 2310 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2311 | #ifdef ENABLE_IPS |
| 2312 | priv->ieee80211->ieee80211_ips_leave_wq = ieee80211_ips_leave_wq; |
| 2313 | priv->ieee80211->ieee80211_ips_leave = ieee80211_ips_leave; |
| 2314 | #endif |
| 2315 | #ifdef ENABLE_LPS |
| 2316 | priv->ieee80211->LeisurePSLeave = LeisurePSLeave; |
Mike McCormack | 16d74da | 2010-09-20 23:11:14 +0900 | [diff] [blame] | 2317 | #endif |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2318 | |
| 2319 | priv->ieee80211->SetHwRegHandler = rtl8192e_SetHwReg; |
| 2320 | priv->ieee80211->rtllib_ap_sec_type = rtl8192e_ap_sec_type; |
| 2321 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2322 | priv->card_type = USB; |
| 2323 | { |
| 2324 | priv->ShortRetryLimit = 0x30; |
| 2325 | priv->LongRetryLimit = 0x30; |
| 2326 | } |
| 2327 | priv->EarlyRxThreshold = 7; |
| 2328 | priv->enable_gpio0 = 0; |
| 2329 | |
| 2330 | priv->TransmitConfig = 0; |
| 2331 | |
| 2332 | priv->ReceiveConfig = RCR_ADD3 | |
| 2333 | RCR_AMF | RCR_ADF | //accept management/data |
| 2334 | RCR_AICV | //accept control frame for SW AP needs PS-poll, 2005.07.07, by rcnjko. |
| 2335 | RCR_AB | RCR_AM | RCR_APM | //accept BC/MC/UC |
| 2336 | RCR_AAP | ((u32)7<<RCR_MXDMA_OFFSET) | |
| 2337 | ((u32)7 << RCR_FIFO_OFFSET) | RCR_ONLYERLPKT; |
| 2338 | |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 2339 | priv->irq_mask = (u32)(IMR_ROK | IMR_VODOK | IMR_VIDOK | IMR_BEDOK | IMR_BKDOK | |
| 2340 | IMR_HCCADOK | IMR_MGNTDOK | IMR_COMDOK | IMR_HIGHDOK | |
| 2341 | IMR_BDOK | IMR_RXCMDOK | IMR_TIMEOUT0 | IMR_RDU | IMR_RXFOVW | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2342 | IMR_TXFOVW | IMR_BcnInt | IMR_TBDOK | IMR_TBDER); |
| 2343 | |
| 2344 | priv->AcmControl = 0; |
| 2345 | priv->pFirmware = (rt_firmware*)vmalloc(sizeof(rt_firmware)); |
| 2346 | if (priv->pFirmware) |
| 2347 | memset(priv->pFirmware, 0, sizeof(rt_firmware)); |
| 2348 | |
| 2349 | /* rx related queue */ |
| 2350 | skb_queue_head_init(&priv->rx_queue); |
| 2351 | skb_queue_head_init(&priv->skb_queue); |
| 2352 | |
| 2353 | /* Tx related queue */ |
| 2354 | for(i = 0; i < MAX_QUEUE_SIZE; i++) { |
| 2355 | skb_queue_head_init(&priv->ieee80211->skb_waitQ [i]); |
| 2356 | } |
| 2357 | for(i = 0; i < MAX_QUEUE_SIZE; i++) { |
| 2358 | skb_queue_head_init(&priv->ieee80211->skb_aggQ [i]); |
| 2359 | } |
| 2360 | priv->rf_set_chan = rtl8192_phy_SwChnl; |
| 2361 | } |
| 2362 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2363 | static void rtl8192_init_priv_lock(struct r8192_priv* priv) |
| 2364 | { |
| 2365 | spin_lock_init(&priv->tx_lock); |
| 2366 | spin_lock_init(&priv->irq_lock);//added by thomas |
| 2367 | spin_lock_init(&priv->irq_th_lock); |
| 2368 | spin_lock_init(&priv->rf_ps_lock); |
| 2369 | spin_lock_init(&priv->ps_lock); |
| 2370 | //spin_lock_init(&priv->rf_lock); |
| 2371 | sema_init(&priv->wx_sem,1); |
| 2372 | sema_init(&priv->rf_sem,1); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2373 | mutex_init(&priv->mutex); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 2376 | /* init tasklet and wait_queue here */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2377 | #define DRV_NAME "wlan0" |
| 2378 | static void rtl8192_init_priv_task(struct net_device* dev) |
| 2379 | { |
| 2380 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2381 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2382 | #ifdef PF_SYNCTHREAD |
| 2383 | priv->priv_wq = create_workqueue(DRV_NAME,0); |
| 2384 | #else |
| 2385 | priv->priv_wq = create_workqueue(DRV_NAME); |
| 2386 | #endif |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2387 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2388 | #ifdef ENABLE_IPS |
| 2389 | INIT_WORK(&priv->ieee80211->ips_leave_wq, (void*)IPSLeave_wq); |
| 2390 | #endif |
| 2391 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2392 | // INIT_WORK(&priv->reset_wq, (void(*)(void*)) rtl8192_restart); |
| 2393 | INIT_WORK(&priv->reset_wq, rtl8192_restart); |
| 2394 | // INIT_DELAYED_WORK(&priv->watch_dog_wq, hal_dm_watchdog); |
| 2395 | INIT_DELAYED_WORK(&priv->watch_dog_wq, rtl819x_watchdog_wqcallback); |
| 2396 | INIT_DELAYED_WORK(&priv->txpower_tracking_wq, dm_txpower_trackingcallback); |
| 2397 | INIT_DELAYED_WORK(&priv->rfpath_check_wq, dm_rf_pathcheck_workitemcallback); |
| 2398 | INIT_DELAYED_WORK(&priv->update_beacon_wq, rtl8192_update_beacon); |
| 2399 | //INIT_WORK(&priv->SwChnlWorkItem, rtl8192_SwChnl_WorkItem); |
| 2400 | //INIT_WORK(&priv->SetBWModeWorkItem, rtl8192_SetBWModeWorkItem); |
| 2401 | INIT_WORK(&priv->qos_activate, rtl8192_qos_activate); |
| 2402 | INIT_DELAYED_WORK(&priv->ieee80211->hw_wakeup_wq,(void*) rtl8192_hw_wakeup_wq); |
| 2403 | INIT_DELAYED_WORK(&priv->ieee80211->hw_sleep_wq,(void*) rtl8192_hw_sleep_wq); |
| 2404 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2405 | tasklet_init(&priv->irq_rx_tasklet, |
| 2406 | (void(*)(unsigned long))rtl8192_irq_rx_tasklet, |
| 2407 | (unsigned long)priv); |
| 2408 | tasklet_init(&priv->irq_tx_tasklet, |
| 2409 | (void(*)(unsigned long))rtl8192_irq_tx_tasklet, |
| 2410 | (unsigned long)priv); |
| 2411 | tasklet_init(&priv->irq_prepare_beacon_tasklet, |
| 2412 | (void(*)(unsigned long))rtl8192_prepare_beacon, |
| 2413 | (unsigned long)priv); |
| 2414 | } |
| 2415 | |
| 2416 | static void rtl8192_get_eeprom_size(struct net_device* dev) |
| 2417 | { |
| 2418 | u16 curCR = 0; |
| 2419 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2420 | RT_TRACE(COMP_INIT, "===========>%s()\n", __FUNCTION__); |
| 2421 | curCR = read_nic_dword(dev, EPROM_CMD); |
| 2422 | RT_TRACE(COMP_INIT, "read from Reg Cmd9346CR(%x):%x\n", EPROM_CMD, curCR); |
| 2423 | //whether need I consider BIT5? |
| 2424 | priv->epromtype = (curCR & EPROM_CMD_9356SEL) ? EPROM_93c56 : EPROM_93c46; |
| 2425 | RT_TRACE(COMP_INIT, "<===========%s(), epromtype:%d\n", __FUNCTION__, priv->epromtype); |
| 2426 | } |
| 2427 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 2428 | /* |
| 2429 | * used to swap endian. as ntohl & htonl are not |
| 2430 | * neccessary to swap endian, so use this instead. |
| 2431 | */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2432 | static inline u16 endian_swap(u16* data) |
| 2433 | { |
| 2434 | u16 tmp = *data; |
| 2435 | *data = (tmp >> 8) | (tmp << 8); |
| 2436 | return *data; |
| 2437 | } |
| 2438 | |
| 2439 | /* |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 2440 | * Adapter->EEPROMAddressSize should be set before this function call. |
| 2441 | * EEPROM address size can be got through GetEEPROMSize8185() |
| 2442 | */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2443 | static void rtl8192_read_eeprom_info(struct net_device* dev) |
| 2444 | { |
| 2445 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2446 | |
| 2447 | u8 tempval; |
| 2448 | #ifdef RTL8192E |
| 2449 | u8 ICVer8192, ICVer8256; |
| 2450 | #endif |
| 2451 | u16 i,usValue, IC_Version; |
| 2452 | u16 EEPROMId; |
| 2453 | #ifdef RTL8190P |
Mike McCormack | 16d74da | 2010-09-20 23:11:14 +0900 | [diff] [blame] | 2454 | u8 offset; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2455 | u8 EepromTxPower[100]; |
| 2456 | #endif |
| 2457 | u8 bMac_Tmp_Addr[6] = {0x00, 0xe0, 0x4c, 0x00, 0x00, 0x01}; |
| 2458 | RT_TRACE(COMP_INIT, "====> rtl8192_read_eeprom_info\n"); |
| 2459 | |
| 2460 | |
| 2461 | // TODO: I don't know if we need to apply EF function to EEPROM read function |
| 2462 | |
| 2463 | //2 Read EEPROM ID to make sure autoload is success |
| 2464 | EEPROMId = eprom_read(dev, 0); |
| 2465 | if( EEPROMId != RTL8190_EEPROM_ID ) |
| 2466 | { |
| 2467 | RT_TRACE(COMP_ERR, "EEPROM ID is invalid:%x, %x\n", EEPROMId, RTL8190_EEPROM_ID); |
| 2468 | priv->AutoloadFailFlag=true; |
| 2469 | } |
| 2470 | else |
| 2471 | { |
| 2472 | priv->AutoloadFailFlag=false; |
| 2473 | } |
| 2474 | |
| 2475 | // |
| 2476 | // Assign Chip Version ID |
| 2477 | // |
| 2478 | // Read IC Version && Channel Plan |
| 2479 | if(!priv->AutoloadFailFlag) |
| 2480 | { |
| 2481 | // VID, PID |
| 2482 | priv->eeprom_vid = eprom_read(dev, (EEPROM_VID >> 1)); |
| 2483 | priv->eeprom_did = eprom_read(dev, (EEPROM_DID >> 1)); |
| 2484 | |
| 2485 | usValue = eprom_read(dev, (u16)(EEPROM_Customer_ID>>1)) >> 8 ; |
| 2486 | priv->eeprom_CustomerID = (u8)( usValue & 0xff); |
| 2487 | usValue = eprom_read(dev, (EEPROM_ICVersion_ChannelPlan>>1)); |
| 2488 | priv->eeprom_ChannelPlan = usValue&0xff; |
| 2489 | IC_Version = ((usValue&0xff00)>>8); |
| 2490 | |
| 2491 | #ifdef RTL8190P |
| 2492 | priv->card_8192_version = (VERSION_8190)(IC_Version); |
| 2493 | #else |
| 2494 | #ifdef RTL8192E |
| 2495 | ICVer8192 = (IC_Version&0xf); //bit0~3; 1:A cut, 2:B cut, 3:C cut... |
| 2496 | ICVer8256 = ((IC_Version&0xf0)>>4);//bit4~6, bit7 reserved for other RF chip; 1:A cut, 2:B cut, 3:C cut... |
| 2497 | RT_TRACE(COMP_INIT, "\nICVer8192 = 0x%x\n", ICVer8192); |
| 2498 | RT_TRACE(COMP_INIT, "\nICVer8256 = 0x%x\n", ICVer8256); |
| 2499 | if(ICVer8192 == 0x2) //B-cut |
| 2500 | { |
| 2501 | if(ICVer8256 == 0x5) //E-cut |
| 2502 | priv->card_8192_version= VERSION_8190_BE; |
| 2503 | } |
| 2504 | #endif |
| 2505 | #endif |
| 2506 | switch(priv->card_8192_version) |
| 2507 | { |
| 2508 | case VERSION_8190_BD: |
| 2509 | case VERSION_8190_BE: |
| 2510 | break; |
| 2511 | default: |
| 2512 | priv->card_8192_version = VERSION_8190_BD; |
| 2513 | break; |
| 2514 | } |
| 2515 | RT_TRACE(COMP_INIT, "\nIC Version = 0x%x\n", priv->card_8192_version); |
| 2516 | } |
| 2517 | else |
| 2518 | { |
| 2519 | priv->card_8192_version = VERSION_8190_BD; |
| 2520 | priv->eeprom_vid = 0; |
| 2521 | priv->eeprom_did = 0; |
| 2522 | priv->eeprom_CustomerID = 0; |
| 2523 | priv->eeprom_ChannelPlan = 0; |
| 2524 | RT_TRACE(COMP_INIT, "\nIC Version = 0x%x\n", 0xff); |
| 2525 | } |
| 2526 | |
| 2527 | RT_TRACE(COMP_INIT, "EEPROM VID = 0x%4x\n", priv->eeprom_vid); |
| 2528 | RT_TRACE(COMP_INIT, "EEPROM DID = 0x%4x\n", priv->eeprom_did); |
| 2529 | RT_TRACE(COMP_INIT,"EEPROM Customer ID: 0x%2x\n", priv->eeprom_CustomerID); |
| 2530 | |
| 2531 | //2 Read Permanent MAC address |
| 2532 | if(!priv->AutoloadFailFlag) |
| 2533 | { |
| 2534 | for(i = 0; i < 6; i += 2) |
| 2535 | { |
| 2536 | usValue = eprom_read(dev, (u16) ((EEPROM_NODE_ADDRESS_BYTE_0+i)>>1)); |
| 2537 | *(u16*)(&dev->dev_addr[i]) = usValue; |
| 2538 | } |
| 2539 | } else { |
| 2540 | // when auto load failed, the last address byte set to be a random one. |
| 2541 | // added by david woo.2007/11/7 |
| 2542 | memcpy(dev->dev_addr, bMac_Tmp_Addr, 6); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
H Hartley Sweeten | 820793c | 2009-12-28 19:28:11 -0500 | [diff] [blame] | 2545 | RT_TRACE(COMP_INIT, "Permanent Address = %pM\n", dev->dev_addr); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2546 | |
| 2547 | //2 TX Power Check EEPROM Fail or not |
| 2548 | if(priv->card_8192_version > VERSION_8190_BD) { |
| 2549 | priv->bTXPowerDataReadFromEEPORM = true; |
| 2550 | } else { |
| 2551 | priv->bTXPowerDataReadFromEEPORM = false; |
| 2552 | } |
| 2553 | |
André Goddard Rosa | bbc9a99 | 2009-11-14 13:09:06 -0200 | [diff] [blame] | 2554 | // 2007/11/15 MH 8190PCI Default=2T4R, 8192PCIE default=1T2R |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2555 | priv->rf_type = RTL819X_DEFAULT_RF_TYPE; |
| 2556 | |
| 2557 | if(priv->card_8192_version > VERSION_8190_BD) |
| 2558 | { |
| 2559 | // Read RF-indication and Tx Power gain index diff of legacy to HT OFDM rate. |
| 2560 | if(!priv->AutoloadFailFlag) |
| 2561 | { |
| 2562 | tempval = (eprom_read(dev, (EEPROM_RFInd_PowerDiff>>1))) & 0xff; |
| 2563 | priv->EEPROMLegacyHTTxPowerDiff = tempval & 0xf; // bit[3:0] |
| 2564 | |
| 2565 | if (tempval&0x80) //RF-indication, bit[7] |
| 2566 | priv->rf_type = RF_1T2R; |
| 2567 | else |
| 2568 | priv->rf_type = RF_2T4R; |
| 2569 | } |
| 2570 | else |
| 2571 | { |
| 2572 | priv->EEPROMLegacyHTTxPowerDiff = EEPROM_Default_LegacyHTTxPowerDiff; |
| 2573 | } |
| 2574 | RT_TRACE(COMP_INIT, "EEPROMLegacyHTTxPowerDiff = %d\n", |
| 2575 | priv->EEPROMLegacyHTTxPowerDiff); |
| 2576 | |
| 2577 | // Read ThermalMeter from EEPROM |
| 2578 | if(!priv->AutoloadFailFlag) |
| 2579 | { |
| 2580 | priv->EEPROMThermalMeter = (u8)(((eprom_read(dev, (EEPROM_ThermalMeter>>1))) & 0xff00)>>8); |
| 2581 | } |
| 2582 | else |
| 2583 | { |
| 2584 | priv->EEPROMThermalMeter = EEPROM_Default_ThermalMeter; |
| 2585 | } |
| 2586 | RT_TRACE(COMP_INIT, "ThermalMeter = %d\n", priv->EEPROMThermalMeter); |
| 2587 | //vivi, for tx power track |
| 2588 | priv->TSSI_13dBm = priv->EEPROMThermalMeter *100; |
| 2589 | |
| 2590 | if(priv->epromtype == EPROM_93c46) |
| 2591 | { |
| 2592 | // Read antenna tx power offset of B/C/D to A and CrystalCap from EEPROM |
| 2593 | if(!priv->AutoloadFailFlag) |
| 2594 | { |
| 2595 | usValue = eprom_read(dev, (EEPROM_TxPwDiff_CrystalCap>>1)); |
| 2596 | priv->EEPROMAntPwDiff = (usValue&0x0fff); |
| 2597 | priv->EEPROMCrystalCap = (u8)((usValue&0xf000)>>12); |
| 2598 | } |
| 2599 | else |
| 2600 | { |
| 2601 | priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff; |
| 2602 | priv->EEPROMCrystalCap = EEPROM_Default_TxPwDiff_CrystalCap; |
| 2603 | } |
| 2604 | RT_TRACE(COMP_INIT, "EEPROMAntPwDiff = %d\n", priv->EEPROMAntPwDiff); |
| 2605 | RT_TRACE(COMP_INIT, "EEPROMCrystalCap = %d\n", priv->EEPROMCrystalCap); |
| 2606 | |
| 2607 | // |
| 2608 | // Get per-channel Tx Power Level |
| 2609 | // |
| 2610 | for(i=0; i<14; i+=2) |
| 2611 | { |
| 2612 | if(!priv->AutoloadFailFlag) |
| 2613 | { |
| 2614 | usValue = eprom_read(dev, (u16) ((EEPROM_TxPwIndex_CCK+i)>>1) ); |
| 2615 | } |
| 2616 | else |
| 2617 | { |
| 2618 | usValue = EEPROM_Default_TxPower; |
| 2619 | } |
| 2620 | *((u16*)(&priv->EEPROMTxPowerLevelCCK[i])) = usValue; |
| 2621 | RT_TRACE(COMP_INIT,"CCK Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelCCK[i]); |
| 2622 | RT_TRACE(COMP_INIT, "CCK Tx Power Level, Index %d = 0x%02x\n", i+1, priv->EEPROMTxPowerLevelCCK[i+1]); |
| 2623 | } |
| 2624 | for(i=0; i<14; i+=2) |
| 2625 | { |
| 2626 | if(!priv->AutoloadFailFlag) |
| 2627 | { |
| 2628 | usValue = eprom_read(dev, (u16) ((EEPROM_TxPwIndex_OFDM_24G+i)>>1) ); |
| 2629 | } |
| 2630 | else |
| 2631 | { |
| 2632 | usValue = EEPROM_Default_TxPower; |
| 2633 | } |
| 2634 | *((u16*)(&priv->EEPROMTxPowerLevelOFDM24G[i])) = usValue; |
| 2635 | RT_TRACE(COMP_INIT, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i, priv->EEPROMTxPowerLevelOFDM24G[i]); |
| 2636 | RT_TRACE(COMP_INIT, "OFDM 2.4G Tx Power Level, Index %d = 0x%02x\n", i+1, priv->EEPROMTxPowerLevelOFDM24G[i+1]); |
| 2637 | } |
| 2638 | } |
| 2639 | else if(priv->epromtype== EPROM_93c56) |
| 2640 | { |
| 2641 | #ifdef RTL8190P |
| 2642 | // Read CrystalCap from EEPROM |
| 2643 | if(!priv->AutoloadFailFlag) |
| 2644 | { |
| 2645 | priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff; |
| 2646 | priv->EEPROMCrystalCap = (u8)(((eprom_read(dev, (EEPROM_C56_CrystalCap>>1))) & 0xf000)>>12); |
| 2647 | } |
| 2648 | else |
| 2649 | { |
| 2650 | priv->EEPROMAntPwDiff = EEPROM_Default_AntTxPowerDiff; |
| 2651 | priv->EEPROMCrystalCap = EEPROM_Default_TxPwDiff_CrystalCap; |
| 2652 | } |
| 2653 | RT_TRACE(COMP_INIT,"EEPROMAntPwDiff = %d\n", priv->EEPROMAntPwDiff); |
| 2654 | RT_TRACE(COMP_INIT, "EEPROMCrystalCap = %d\n", priv->EEPROMCrystalCap); |
| 2655 | |
| 2656 | // Get Tx Power Level by Channel |
| 2657 | if(!priv->AutoloadFailFlag) |
| 2658 | { |
| 2659 | // Read Tx power of Channel 1 ~ 14 from EEPROM. |
| 2660 | for(i = 0; i < 12; i+=2) |
| 2661 | { |
| 2662 | if (i <6) |
| 2663 | offset = EEPROM_C56_RfA_CCK_Chnl1_TxPwIndex + i; |
| 2664 | else |
| 2665 | offset = EEPROM_C56_RfC_CCK_Chnl1_TxPwIndex + i - 6; |
| 2666 | usValue = eprom_read(dev, (offset>>1)); |
| 2667 | *((u16*)(&EepromTxPower[i])) = usValue; |
| 2668 | } |
| 2669 | |
| 2670 | for(i = 0; i < 12; i++) |
| 2671 | { |
| 2672 | if (i <= 2) |
| 2673 | priv->EEPROMRfACCKChnl1TxPwLevel[i] = EepromTxPower[i]; |
| 2674 | else if ((i >=3 )&&(i <= 5)) |
| 2675 | priv->EEPROMRfAOfdmChnlTxPwLevel[i-3] = EepromTxPower[i]; |
| 2676 | else if ((i >=6 )&&(i <= 8)) |
| 2677 | priv->EEPROMRfCCCKChnl1TxPwLevel[i-6] = EepromTxPower[i]; |
| 2678 | else |
| 2679 | priv->EEPROMRfCOfdmChnlTxPwLevel[i-9] = EepromTxPower[i]; |
| 2680 | } |
| 2681 | } |
| 2682 | else |
| 2683 | { |
| 2684 | priv->EEPROMRfACCKChnl1TxPwLevel[0] = EEPROM_Default_TxPowerLevel; |
| 2685 | priv->EEPROMRfACCKChnl1TxPwLevel[1] = EEPROM_Default_TxPowerLevel; |
| 2686 | priv->EEPROMRfACCKChnl1TxPwLevel[2] = EEPROM_Default_TxPowerLevel; |
| 2687 | |
| 2688 | priv->EEPROMRfAOfdmChnlTxPwLevel[0] = EEPROM_Default_TxPowerLevel; |
| 2689 | priv->EEPROMRfAOfdmChnlTxPwLevel[1] = EEPROM_Default_TxPowerLevel; |
| 2690 | priv->EEPROMRfAOfdmChnlTxPwLevel[2] = EEPROM_Default_TxPowerLevel; |
| 2691 | |
| 2692 | priv->EEPROMRfCCCKChnl1TxPwLevel[0] = EEPROM_Default_TxPowerLevel; |
| 2693 | priv->EEPROMRfCCCKChnl1TxPwLevel[1] = EEPROM_Default_TxPowerLevel; |
| 2694 | priv->EEPROMRfCCCKChnl1TxPwLevel[2] = EEPROM_Default_TxPowerLevel; |
| 2695 | |
| 2696 | priv->EEPROMRfCOfdmChnlTxPwLevel[0] = EEPROM_Default_TxPowerLevel; |
| 2697 | priv->EEPROMRfCOfdmChnlTxPwLevel[1] = EEPROM_Default_TxPowerLevel; |
| 2698 | priv->EEPROMRfCOfdmChnlTxPwLevel[2] = EEPROM_Default_TxPowerLevel; |
| 2699 | } |
| 2700 | RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[0] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[0]); |
| 2701 | RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[1] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[1]); |
| 2702 | RT_TRACE(COMP_INIT, "priv->EEPROMRfACCKChnl1TxPwLevel[2] = 0x%x\n", priv->EEPROMRfACCKChnl1TxPwLevel[2]); |
| 2703 | RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[0] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[0]); |
| 2704 | RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[1] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[1]); |
| 2705 | RT_TRACE(COMP_INIT, "priv->EEPROMRfAOfdmChnlTxPwLevel[2] = 0x%x\n", priv->EEPROMRfAOfdmChnlTxPwLevel[2]); |
| 2706 | RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[0] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[0]); |
| 2707 | RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[1] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[1]); |
| 2708 | RT_TRACE(COMP_INIT, "priv->EEPROMRfCCCKChnl1TxPwLevel[2] = 0x%x\n", priv->EEPROMRfCCCKChnl1TxPwLevel[2]); |
| 2709 | RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[0] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[0]); |
| 2710 | RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[1] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[1]); |
| 2711 | RT_TRACE(COMP_INIT, "priv->EEPROMRfCOfdmChnlTxPwLevel[2] = 0x%x\n", priv->EEPROMRfCOfdmChnlTxPwLevel[2]); |
| 2712 | #endif |
| 2713 | |
| 2714 | } |
| 2715 | // |
| 2716 | // Update HAL variables. |
| 2717 | // |
| 2718 | if(priv->epromtype == EPROM_93c46) |
| 2719 | { |
| 2720 | for(i=0; i<14; i++) |
| 2721 | { |
| 2722 | priv->TxPowerLevelCCK[i] = priv->EEPROMTxPowerLevelCCK[i]; |
| 2723 | priv->TxPowerLevelOFDM24G[i] = priv->EEPROMTxPowerLevelOFDM24G[i]; |
| 2724 | } |
| 2725 | priv->LegacyHTTxPowerDiff = priv->EEPROMLegacyHTTxPowerDiff; |
| 2726 | // Antenna B gain offset to antenna A, bit0~3 |
| 2727 | priv->AntennaTxPwDiff[0] = (priv->EEPROMAntPwDiff & 0xf); |
| 2728 | // Antenna C gain offset to antenna A, bit4~7 |
| 2729 | priv->AntennaTxPwDiff[1] = ((priv->EEPROMAntPwDiff & 0xf0)>>4); |
| 2730 | // Antenna D gain offset to antenna A, bit8~11 |
| 2731 | priv->AntennaTxPwDiff[2] = ((priv->EEPROMAntPwDiff & 0xf00)>>8); |
| 2732 | // CrystalCap, bit12~15 |
| 2733 | priv->CrystalCap = priv->EEPROMCrystalCap; |
| 2734 | // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2 |
| 2735 | priv->ThermalMeter[0] = (priv->EEPROMThermalMeter & 0xf); |
| 2736 | priv->ThermalMeter[1] = ((priv->EEPROMThermalMeter & 0xf0)>>4); |
| 2737 | } |
| 2738 | else if(priv->epromtype == EPROM_93c56) |
| 2739 | { |
| 2740 | //char cck_pwr_diff_a=0, cck_pwr_diff_c=0; |
| 2741 | |
| 2742 | //cck_pwr_diff_a = pHalData->EEPROMRfACCKChnl7TxPwLevel - pHalData->EEPROMRfAOfdmChnlTxPwLevel[1]; |
| 2743 | //cck_pwr_diff_c = pHalData->EEPROMRfCCCKChnl7TxPwLevel - pHalData->EEPROMRfCOfdmChnlTxPwLevel[1]; |
| 2744 | for(i=0; i<3; i++) // channel 1~3 use the same Tx Power Level. |
| 2745 | { |
| 2746 | priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[0]; |
| 2747 | priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[0]; |
| 2748 | priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[0]; |
| 2749 | priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[0]; |
| 2750 | } |
| 2751 | for(i=3; i<9; i++) // channel 4~9 use the same Tx Power Level |
| 2752 | { |
| 2753 | priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[1]; |
| 2754 | priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[1]; |
| 2755 | priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[1]; |
| 2756 | priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[1]; |
| 2757 | } |
| 2758 | for(i=9; i<14; i++) // channel 10~14 use the same Tx Power Level |
| 2759 | { |
| 2760 | priv->TxPowerLevelCCK_A[i] = priv->EEPROMRfACCKChnl1TxPwLevel[2]; |
| 2761 | priv->TxPowerLevelOFDM24G_A[i] = priv->EEPROMRfAOfdmChnlTxPwLevel[2]; |
| 2762 | priv->TxPowerLevelCCK_C[i] = priv->EEPROMRfCCCKChnl1TxPwLevel[2]; |
| 2763 | priv->TxPowerLevelOFDM24G_C[i] = priv->EEPROMRfCOfdmChnlTxPwLevel[2]; |
| 2764 | } |
| 2765 | for(i=0; i<14; i++) |
| 2766 | RT_TRACE(COMP_INIT, "priv->TxPowerLevelCCK_A[%d] = 0x%x\n", i, priv->TxPowerLevelCCK_A[i]); |
| 2767 | for(i=0; i<14; i++) |
| 2768 | RT_TRACE(COMP_INIT,"priv->TxPowerLevelOFDM24G_A[%d] = 0x%x\n", i, priv->TxPowerLevelOFDM24G_A[i]); |
| 2769 | for(i=0; i<14; i++) |
| 2770 | RT_TRACE(COMP_INIT, "priv->TxPowerLevelCCK_C[%d] = 0x%x\n", i, priv->TxPowerLevelCCK_C[i]); |
| 2771 | for(i=0; i<14; i++) |
| 2772 | RT_TRACE(COMP_INIT, "priv->TxPowerLevelOFDM24G_C[%d] = 0x%x\n", i, priv->TxPowerLevelOFDM24G_C[i]); |
| 2773 | priv->LegacyHTTxPowerDiff = priv->EEPROMLegacyHTTxPowerDiff; |
| 2774 | priv->AntennaTxPwDiff[0] = 0; |
| 2775 | priv->AntennaTxPwDiff[1] = 0; |
| 2776 | priv->AntennaTxPwDiff[2] = 0; |
| 2777 | priv->CrystalCap = priv->EEPROMCrystalCap; |
| 2778 | // ThermalMeter, bit0~3 for RFIC1, bit4~7 for RFIC2 |
| 2779 | priv->ThermalMeter[0] = (priv->EEPROMThermalMeter & 0xf); |
| 2780 | priv->ThermalMeter[1] = ((priv->EEPROMThermalMeter & 0xf0)>>4); |
| 2781 | } |
| 2782 | } |
| 2783 | |
| 2784 | if(priv->rf_type == RF_1T2R) |
| 2785 | { |
| 2786 | RT_TRACE(COMP_INIT, "\n1T2R config\n"); |
| 2787 | } |
| 2788 | else if (priv->rf_type == RF_2T4R) |
| 2789 | { |
| 2790 | RT_TRACE(COMP_INIT, "\n2T4R config\n"); |
| 2791 | } |
| 2792 | |
| 2793 | // 2008/01/16 MH We can only know RF type in the function. So we have to init |
| 2794 | // DIG RATR table again. |
| 2795 | init_rate_adaptive(dev); |
| 2796 | |
| 2797 | //1 Make a copy for following variables and we can change them if we want |
| 2798 | |
| 2799 | priv->rf_chip= RF_8256; |
| 2800 | |
| 2801 | if(priv->RegChannelPlan == 0xf) |
| 2802 | { |
| 2803 | priv->ChannelPlan = priv->eeprom_ChannelPlan; |
| 2804 | } |
| 2805 | else |
| 2806 | { |
| 2807 | priv->ChannelPlan = priv->RegChannelPlan; |
| 2808 | } |
| 2809 | |
| 2810 | // |
| 2811 | // Used PID and DID to Set CustomerID |
| 2812 | // |
| 2813 | if( priv->eeprom_vid == 0x1186 && priv->eeprom_did == 0x3304 ) |
| 2814 | { |
| 2815 | priv->CustomerID = RT_CID_DLINK; |
| 2816 | } |
| 2817 | |
| 2818 | switch(priv->eeprom_CustomerID) |
| 2819 | { |
| 2820 | case EEPROM_CID_DEFAULT: |
| 2821 | priv->CustomerID = RT_CID_DEFAULT; |
| 2822 | break; |
| 2823 | case EEPROM_CID_CAMEO: |
| 2824 | priv->CustomerID = RT_CID_819x_CAMEO; |
| 2825 | break; |
| 2826 | case EEPROM_CID_RUNTOP: |
| 2827 | priv->CustomerID = RT_CID_819x_RUNTOP; |
| 2828 | break; |
| 2829 | case EEPROM_CID_NetCore: |
| 2830 | priv->CustomerID = RT_CID_819x_Netcore; |
| 2831 | break; |
| 2832 | case EEPROM_CID_TOSHIBA: // Merge by Jacken, 2008/01/31 |
| 2833 | priv->CustomerID = RT_CID_TOSHIBA; |
| 2834 | if(priv->eeprom_ChannelPlan&0x80) |
| 2835 | priv->ChannelPlan = priv->eeprom_ChannelPlan&0x7f; |
| 2836 | else |
| 2837 | priv->ChannelPlan = 0x0; |
| 2838 | RT_TRACE(COMP_INIT, "Toshiba ChannelPlan = 0x%x\n", |
| 2839 | priv->ChannelPlan); |
| 2840 | break; |
| 2841 | case EEPROM_CID_Nettronix: |
| 2842 | priv->ScanDelay = 100; //cosa add for scan |
| 2843 | priv->CustomerID = RT_CID_Nettronix; |
| 2844 | break; |
| 2845 | case EEPROM_CID_Pronet: |
| 2846 | priv->CustomerID = RT_CID_PRONET; |
| 2847 | break; |
| 2848 | case EEPROM_CID_DLINK: |
| 2849 | priv->CustomerID = RT_CID_DLINK; |
| 2850 | break; |
| 2851 | |
| 2852 | case EEPROM_CID_WHQL: |
| 2853 | //Adapter->bInHctTest = TRUE;//do not supported |
| 2854 | |
| 2855 | //priv->bSupportTurboMode = FALSE; |
| 2856 | //priv->bAutoTurboBy8186 = FALSE; |
| 2857 | |
| 2858 | //pMgntInfo->PowerSaveControl.bInactivePs = FALSE; |
| 2859 | //pMgntInfo->PowerSaveControl.bIPSModeBackup = FALSE; |
| 2860 | //pMgntInfo->PowerSaveControl.bLeisurePs = FALSE; |
| 2861 | |
| 2862 | break; |
| 2863 | default: |
| 2864 | // value from RegCustomerID |
| 2865 | break; |
| 2866 | } |
| 2867 | |
| 2868 | //Avoid the channel plan array overflow, by Bruce, 2007-08-27. |
| 2869 | if(priv->ChannelPlan > CHANNEL_PLAN_LEN - 1) |
| 2870 | priv->ChannelPlan = 0; //FCC |
| 2871 | |
| 2872 | switch(priv->CustomerID) |
| 2873 | { |
| 2874 | case RT_CID_DEFAULT: |
| 2875 | #ifdef RTL8190P |
| 2876 | priv->LedStrategy = HW_LED; |
| 2877 | #else |
| 2878 | #ifdef RTL8192E |
| 2879 | priv->LedStrategy = SW_LED_MODE1; |
| 2880 | #endif |
| 2881 | #endif |
| 2882 | break; |
| 2883 | |
| 2884 | case RT_CID_819x_CAMEO: |
| 2885 | priv->LedStrategy = SW_LED_MODE2; |
| 2886 | break; |
| 2887 | |
| 2888 | case RT_CID_819x_RUNTOP: |
| 2889 | priv->LedStrategy = SW_LED_MODE3; |
| 2890 | break; |
| 2891 | |
| 2892 | case RT_CID_819x_Netcore: |
| 2893 | priv->LedStrategy = SW_LED_MODE4; |
| 2894 | break; |
| 2895 | |
| 2896 | case RT_CID_Nettronix: |
| 2897 | priv->LedStrategy = SW_LED_MODE5; |
| 2898 | break; |
| 2899 | |
| 2900 | case RT_CID_PRONET: |
| 2901 | priv->LedStrategy = SW_LED_MODE6; |
| 2902 | break; |
| 2903 | |
| 2904 | case RT_CID_TOSHIBA: //Modify by Jacken 2008/01/31 |
| 2905 | // Do nothing. |
| 2906 | //break; |
| 2907 | |
| 2908 | default: |
| 2909 | #ifdef RTL8190P |
| 2910 | priv->LedStrategy = HW_LED; |
| 2911 | #else |
| 2912 | #ifdef RTL8192E |
| 2913 | priv->LedStrategy = SW_LED_MODE1; |
| 2914 | #endif |
| 2915 | #endif |
| 2916 | break; |
| 2917 | } |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2918 | |
| 2919 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2920 | if( priv->eeprom_vid == 0x1186 && priv->eeprom_did == 0x3304) |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2921 | priv->ieee80211->bSupportRemoteWakeUp = true; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2922 | else |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 2923 | priv->ieee80211->bSupportRemoteWakeUp = false; |
| 2924 | |
| 2925 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2926 | RT_TRACE(COMP_INIT, "RegChannelPlan(%d)\n", priv->RegChannelPlan); |
| 2927 | RT_TRACE(COMP_INIT, "ChannelPlan = %d \n", priv->ChannelPlan); |
| 2928 | RT_TRACE(COMP_INIT, "LedStrategy = %d \n", priv->LedStrategy); |
| 2929 | RT_TRACE(COMP_TRACE, "<==== ReadAdapterInfo\n"); |
| 2930 | |
| 2931 | return ; |
| 2932 | } |
| 2933 | |
| 2934 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 2935 | static short rtl8192_get_channel_map(struct net_device * dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2936 | { |
| 2937 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2938 | #ifdef ENABLE_DOT11D |
| 2939 | if(priv->ChannelPlan> COUNTRY_CODE_GLOBAL_DOMAIN){ |
| 2940 | printk("rtl8180_init:Error channel plan! Set to default.\n"); |
| 2941 | priv->ChannelPlan= 0; |
| 2942 | } |
| 2943 | RT_TRACE(COMP_INIT, "Channel plan is %d\n",priv->ChannelPlan); |
| 2944 | |
| 2945 | rtl819x_set_channel_map(priv->ChannelPlan, priv); |
| 2946 | #else |
| 2947 | int ch,i; |
| 2948 | //Set Default Channel Plan |
| 2949 | if(!channels){ |
| 2950 | DMESG("No channels, aborting"); |
| 2951 | return -1; |
| 2952 | } |
| 2953 | ch=channels; |
| 2954 | priv->ChannelPlan= 0;//hikaru |
| 2955 | // set channels 1..14 allowed in given locale |
| 2956 | for (i=1; i<=14; i++) { |
| 2957 | (priv->ieee80211->channel_map)[i] = (u8)(ch & 0x01); |
| 2958 | ch >>= 1; |
| 2959 | } |
| 2960 | #endif |
| 2961 | return 0; |
| 2962 | } |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 2963 | |
| 2964 | static short rtl8192_init(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2965 | { |
| 2966 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 2967 | memset(&(priv->stats),0,sizeof(struct Stats)); |
| 2968 | rtl8192_init_priv_variable(dev); |
| 2969 | rtl8192_init_priv_lock(priv); |
| 2970 | rtl8192_init_priv_task(dev); |
| 2971 | rtl8192_get_eeprom_size(dev); |
| 2972 | rtl8192_read_eeprom_info(dev); |
| 2973 | rtl8192_get_channel_map(dev); |
| 2974 | init_hal_dm(dev); |
| 2975 | init_timer(&priv->watch_dog_timer); |
| 2976 | priv->watch_dog_timer.data = (unsigned long)dev; |
| 2977 | priv->watch_dog_timer.function = watch_dog_timer_callback; |
| 2978 | #if defined(IRQF_SHARED) |
| 2979 | if(request_irq(dev->irq, (void*)rtl8192_interrupt, IRQF_SHARED, dev->name, dev)){ |
| 2980 | #else |
| 2981 | if(request_irq(dev->irq, (void *)rtl8192_interrupt, SA_SHIRQ, dev->name, dev)){ |
| 2982 | #endif |
| 2983 | printk("Error allocating IRQ %d",dev->irq); |
| 2984 | return -1; |
| 2985 | }else{ |
| 2986 | priv->irq=dev->irq; |
| 2987 | printk("IRQ %d",dev->irq); |
| 2988 | } |
| 2989 | if(rtl8192_pci_initdescring(dev)!=0){ |
| 2990 | printk("Endopoints initialization failed"); |
| 2991 | return -1; |
| 2992 | } |
| 2993 | |
| 2994 | //rtl8192_rx_enable(dev); |
| 2995 | //rtl8192_adapter_start(dev); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 2996 | return 0; |
| 2997 | } |
| 2998 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 2999 | /* |
| 3000 | * Actually only set RRSR, RATR and BW_OPMODE registers |
| 3001 | * not to do all the hw config as its name says |
| 3002 | * This part need to modified according to the rate set we filtered |
| 3003 | */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 3004 | static void rtl8192_hwconfig(struct net_device* dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3005 | { |
| 3006 | u32 regRATR = 0, regRRSR = 0; |
| 3007 | u8 regBwOpMode = 0, regTmp = 0; |
| 3008 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 3009 | |
| 3010 | // Set RRSR, RATR, and BW_OPMODE registers |
| 3011 | // |
| 3012 | switch(priv->ieee80211->mode) |
| 3013 | { |
| 3014 | case WIRELESS_MODE_B: |
| 3015 | regBwOpMode = BW_OPMODE_20MHZ; |
| 3016 | regRATR = RATE_ALL_CCK; |
| 3017 | regRRSR = RATE_ALL_CCK; |
| 3018 | break; |
| 3019 | case WIRELESS_MODE_A: |
| 3020 | regBwOpMode = BW_OPMODE_5G |BW_OPMODE_20MHZ; |
| 3021 | regRATR = RATE_ALL_OFDM_AG; |
| 3022 | regRRSR = RATE_ALL_OFDM_AG; |
| 3023 | break; |
| 3024 | case WIRELESS_MODE_G: |
| 3025 | regBwOpMode = BW_OPMODE_20MHZ; |
| 3026 | regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG; |
| 3027 | regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG; |
| 3028 | break; |
| 3029 | case WIRELESS_MODE_AUTO: |
| 3030 | case WIRELESS_MODE_N_24G: |
| 3031 | // It support CCK rate by default. |
| 3032 | // CCK rate will be filtered out only when associated AP does not support it. |
| 3033 | regBwOpMode = BW_OPMODE_20MHZ; |
| 3034 | regRATR = RATE_ALL_CCK | RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS; |
| 3035 | regRRSR = RATE_ALL_CCK | RATE_ALL_OFDM_AG; |
| 3036 | break; |
| 3037 | case WIRELESS_MODE_N_5G: |
| 3038 | regBwOpMode = BW_OPMODE_5G; |
| 3039 | regRATR = RATE_ALL_OFDM_AG | RATE_ALL_OFDM_1SS | RATE_ALL_OFDM_2SS; |
| 3040 | regRRSR = RATE_ALL_OFDM_AG; |
| 3041 | break; |
| 3042 | } |
| 3043 | |
| 3044 | write_nic_byte(dev, BW_OPMODE, regBwOpMode); |
| 3045 | { |
| 3046 | u32 ratr_value = 0; |
| 3047 | ratr_value = regRATR; |
| 3048 | if (priv->rf_type == RF_1T2R) |
| 3049 | { |
| 3050 | ratr_value &= ~(RATE_ALL_OFDM_2SS); |
| 3051 | } |
| 3052 | write_nic_dword(dev, RATR0, ratr_value); |
| 3053 | write_nic_byte(dev, UFWP, 1); |
| 3054 | } |
| 3055 | regTmp = read_nic_byte(dev, 0x313); |
| 3056 | regRRSR = ((regTmp) << 24) | (regRRSR & 0x00ffffff); |
| 3057 | write_nic_dword(dev, RRSR, regRRSR); |
| 3058 | |
| 3059 | // |
| 3060 | // Set Retry Limit here |
| 3061 | // |
| 3062 | write_nic_word(dev, RETRY_LIMIT, |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 3063 | priv->ShortRetryLimit << RETRY_LIMIT_SHORT_SHIFT | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3064 | priv->LongRetryLimit << RETRY_LIMIT_LONG_SHIFT); |
| 3065 | // Set Contention Window here |
| 3066 | |
| 3067 | // Set Tx AGC |
| 3068 | |
| 3069 | // Set Tx Antenna including Feedback control |
| 3070 | |
| 3071 | // Set Auto Rate fallback control |
| 3072 | |
| 3073 | |
| 3074 | } |
| 3075 | |
| 3076 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 3077 | static RT_STATUS rtl8192_adapter_start(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3078 | { |
| 3079 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 3080 | // struct ieee80211_device *ieee = priv->ieee80211; |
| 3081 | u32 ulRegRead; |
| 3082 | RT_STATUS rtStatus = RT_STATUS_SUCCESS; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3083 | //u8 eRFPath; |
| 3084 | u8 tmpvalue; |
| 3085 | #ifdef RTL8192E |
| 3086 | u8 ICVersion,SwitchingRegulatorOutput; |
| 3087 | #endif |
| 3088 | bool bfirmwareok = true; |
| 3089 | #ifdef RTL8190P |
| 3090 | u8 ucRegRead; |
| 3091 | #endif |
| 3092 | u32 tmpRegA, tmpRegC, TempCCk; |
| 3093 | int i =0; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3094 | |
| 3095 | RT_TRACE(COMP_INIT, "====>%s()\n", __FUNCTION__); |
| 3096 | priv->being_init_adapter = true; |
| 3097 | rtl8192_pci_resetdescring(dev); |
| 3098 | // 2007/11/02 MH Before initalizing RF. We can not use FW to do RF-R/W. |
| 3099 | priv->Rf_Mode = RF_OP_By_SW_3wire; |
| 3100 | #ifdef RTL8192E |
| 3101 | //dPLL on |
| 3102 | if(priv->ResetProgress == RESET_TYPE_NORESET) |
| 3103 | { |
| 3104 | write_nic_byte(dev, ANAPAR, 0x37); |
| 3105 | // Accordign to designer's explain, LBUS active will never > 10ms. We delay 10ms |
| 3106 | // Joseph increae the time to prevent firmware download fail |
| 3107 | mdelay(500); |
| 3108 | } |
| 3109 | #endif |
| 3110 | //PlatformSleepUs(10000); |
| 3111 | // For any kind of InitializeAdapter process, we shall use system now!! |
| 3112 | priv->pFirmware->firmware_status = FW_STATUS_0_INIT; |
| 3113 | |
| 3114 | // Set to eRfoff in order not to count receive count. |
| 3115 | if(priv->RegRfOff == TRUE) |
| 3116 | priv->ieee80211->eRFPowerState = eRfOff; |
| 3117 | |
| 3118 | // |
| 3119 | //3 //Config CPUReset Register |
| 3120 | //3// |
| 3121 | //3 Firmware Reset Or Not |
| 3122 | ulRegRead = read_nic_dword(dev, CPU_GEN); |
| 3123 | if(priv->pFirmware->firmware_status == FW_STATUS_0_INIT) |
| 3124 | { //called from MPInitialized. do nothing |
| 3125 | ulRegRead |= CPU_GEN_SYSTEM_RESET; |
| 3126 | }else if(priv->pFirmware->firmware_status == FW_STATUS_5_READY) |
| 3127 | ulRegRead |= CPU_GEN_FIRMWARE_RESET; // Called from MPReset |
| 3128 | else |
| 3129 | RT_TRACE(COMP_ERR, "ERROR in %s(): undefined firmware state(%d)\n", __FUNCTION__, priv->pFirmware->firmware_status); |
| 3130 | |
| 3131 | #ifdef RTL8190P |
| 3132 | //2008.06.03, for WOL 90 hw bug |
| 3133 | ulRegRead &= (~(CPU_GEN_GPIO_UART)); |
| 3134 | #endif |
| 3135 | |
| 3136 | write_nic_dword(dev, CPU_GEN, ulRegRead); |
| 3137 | //mdelay(100); |
| 3138 | |
| 3139 | #ifdef RTL8192E |
| 3140 | |
| 3141 | //3// |
| 3142 | //3 //Fix the issue of E-cut high temperature issue |
| 3143 | //3// |
| 3144 | // TODO: E cut only |
| 3145 | ICVersion = read_nic_byte(dev, IC_VERRSION); |
| 3146 | if(ICVersion >= 0x4) //E-cut only |
| 3147 | { |
| 3148 | // HW SD suggest that we should not wirte this register too often, so driver |
| 3149 | // should readback this register. This register will be modified only when |
| 3150 | // power on reset |
| 3151 | SwitchingRegulatorOutput = read_nic_byte(dev, SWREGULATOR); |
| 3152 | if(SwitchingRegulatorOutput != 0xb8) |
| 3153 | { |
| 3154 | write_nic_byte(dev, SWREGULATOR, 0xa8); |
| 3155 | mdelay(1); |
| 3156 | write_nic_byte(dev, SWREGULATOR, 0xb8); |
| 3157 | } |
| 3158 | } |
| 3159 | #endif |
| 3160 | |
| 3161 | |
| 3162 | //3// |
| 3163 | //3// Initialize BB before MAC |
| 3164 | //3// |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3165 | RT_TRACE(COMP_INIT, "BB Config Start!\n"); |
| 3166 | rtStatus = rtl8192_BBConfig(dev); |
| 3167 | if(rtStatus != RT_STATUS_SUCCESS) |
| 3168 | { |
| 3169 | RT_TRACE(COMP_ERR, "BB Config failed\n"); |
| 3170 | return rtStatus; |
| 3171 | } |
| 3172 | RT_TRACE(COMP_INIT,"BB Config Finished!\n"); |
| 3173 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3174 | //3//Set Loopback mode or Normal mode |
| 3175 | //3// |
| 3176 | //2006.12.13 by emily. Note!We should not merge these two CPU_GEN register writings |
| 3177 | // because setting of System_Reset bit reset MAC to default transmission mode. |
| 3178 | //Loopback mode or not |
| 3179 | priv->LoopbackMode = RTL819X_NO_LOOPBACK; |
| 3180 | //priv->LoopbackMode = RTL819X_MAC_LOOPBACK; |
| 3181 | if(priv->ResetProgress == RESET_TYPE_NORESET) |
| 3182 | { |
| 3183 | ulRegRead = read_nic_dword(dev, CPU_GEN); |
| 3184 | if(priv->LoopbackMode == RTL819X_NO_LOOPBACK) |
| 3185 | { |
| 3186 | ulRegRead = ((ulRegRead & CPU_GEN_NO_LOOPBACK_MSK) | CPU_GEN_NO_LOOPBACK_SET); |
| 3187 | } |
| 3188 | else if (priv->LoopbackMode == RTL819X_MAC_LOOPBACK ) |
| 3189 | { |
| 3190 | ulRegRead |= CPU_CCK_LOOPBACK; |
| 3191 | } |
| 3192 | else |
| 3193 | { |
| 3194 | RT_TRACE(COMP_ERR,"Serious error: wrong loopback mode setting\n"); |
| 3195 | } |
| 3196 | |
| 3197 | //2008.06.03, for WOL |
| 3198 | //ulRegRead &= (~(CPU_GEN_GPIO_UART)); |
| 3199 | write_nic_dword(dev, CPU_GEN, ulRegRead); |
| 3200 | |
| 3201 | // 2006.11.29. After reset cpu, we sholud wait for a second, otherwise, it may fail to write registers. Emily |
| 3202 | udelay(500); |
| 3203 | } |
| 3204 | //3Set Hardware(Do nothing now) |
| 3205 | rtl8192_hwconfig(dev); |
| 3206 | //2======================================================= |
| 3207 | // Common Setting for all of the FPGA platform. (part 1) |
| 3208 | //2======================================================= |
| 3209 | // If there is changes, please make sure it applies to all of the FPGA version |
| 3210 | //3 Turn on Tx/Rx |
| 3211 | write_nic_byte(dev, CMDR, CR_RE|CR_TE); |
| 3212 | |
| 3213 | //2Set Tx dma burst |
| 3214 | #ifdef RTL8190P |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 3215 | write_nic_byte(dev, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) | |
| 3216 | (MXDMA2_NoLimit<<MXDMA2_TX_SHIFT) | |
| 3217 | (1<<MULRW_SHIFT))); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3218 | #else |
| 3219 | #ifdef RTL8192E |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 3220 | write_nic_byte(dev, PCIF, ((MXDMA2_NoLimit<<MXDMA2_RX_SHIFT) | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3221 | (MXDMA2_NoLimit<<MXDMA2_TX_SHIFT) )); |
| 3222 | #endif |
| 3223 | #endif |
| 3224 | //set IDR0 here |
| 3225 | write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]); |
| 3226 | write_nic_word(dev, MAC4, ((u16*)(dev->dev_addr + 4))[0]); |
| 3227 | //set RCR |
| 3228 | write_nic_dword(dev, RCR, priv->ReceiveConfig); |
| 3229 | |
| 3230 | //3 Initialize Number of Reserved Pages in Firmware Queue |
| 3231 | #ifdef TO_DO_LIST |
| 3232 | if(priv->bInHctTest) |
| 3233 | { |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 3234 | PlatformEFIOWrite4Byte(Adapter, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK_DTM << RSVD_FW_QUEUE_PAGE_BK_SHIFT | |
| 3235 | NUM_OF_PAGE_IN_FW_QUEUE_BE_DTM << RSVD_FW_QUEUE_PAGE_BE_SHIFT | |
| 3236 | NUM_OF_PAGE_IN_FW_QUEUE_VI_DTM << RSVD_FW_QUEUE_PAGE_VI_SHIFT | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3237 | NUM_OF_PAGE_IN_FW_QUEUE_VO_DTM <<RSVD_FW_QUEUE_PAGE_VO_SHIFT); |
| 3238 | PlatformEFIOWrite4Byte(Adapter, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT); |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 3239 | PlatformEFIOWrite4Byte(Adapter, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW| |
| 3240 | NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT| |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3241 | NUM_OF_PAGE_IN_FW_QUEUE_PUB_DTM<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT); |
| 3242 | } |
| 3243 | else |
| 3244 | #endif |
| 3245 | { |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 3246 | write_nic_dword(dev, RQPN1, NUM_OF_PAGE_IN_FW_QUEUE_BK << RSVD_FW_QUEUE_PAGE_BK_SHIFT | |
| 3247 | NUM_OF_PAGE_IN_FW_QUEUE_BE << RSVD_FW_QUEUE_PAGE_BE_SHIFT | |
| 3248 | NUM_OF_PAGE_IN_FW_QUEUE_VI << RSVD_FW_QUEUE_PAGE_VI_SHIFT | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3249 | NUM_OF_PAGE_IN_FW_QUEUE_VO <<RSVD_FW_QUEUE_PAGE_VO_SHIFT); |
| 3250 | write_nic_dword(dev, RQPN2, NUM_OF_PAGE_IN_FW_QUEUE_MGNT << RSVD_FW_QUEUE_PAGE_MGNT_SHIFT); |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 3251 | write_nic_dword(dev, RQPN3, APPLIED_RESERVED_QUEUE_IN_FW| |
| 3252 | NUM_OF_PAGE_IN_FW_QUEUE_BCN<<RSVD_FW_QUEUE_PAGE_BCN_SHIFT| |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3253 | NUM_OF_PAGE_IN_FW_QUEUE_PUB<<RSVD_FW_QUEUE_PAGE_PUB_SHIFT); |
| 3254 | } |
| 3255 | |
| 3256 | rtl8192_tx_enable(dev); |
| 3257 | rtl8192_rx_enable(dev); |
| 3258 | //3Set Response Rate Setting Register |
| 3259 | // CCK rate is supported by default. |
| 3260 | // CCK rate will be filtered out only when associated AP does not support it. |
| 3261 | ulRegRead = (0xFFF00000 & read_nic_dword(dev, RRSR)) | RATE_ALL_OFDM_AG | RATE_ALL_CCK; |
| 3262 | write_nic_dword(dev, RRSR, ulRegRead); |
| 3263 | write_nic_dword(dev, RATR0+4*7, (RATE_ALL_OFDM_AG | RATE_ALL_CCK)); |
| 3264 | |
| 3265 | //2Set AckTimeout |
| 3266 | // TODO: (it value is only for FPGA version). need to be changed!!2006.12.18, by Emily |
| 3267 | write_nic_byte(dev, ACK_TIMEOUT, 0x30); |
| 3268 | |
| 3269 | //rtl8192_actset_wirelessmode(dev,priv->RegWirelessMode); |
| 3270 | if(priv->ResetProgress == RESET_TYPE_NORESET) |
| 3271 | rtl8192_SetWirelessMode(dev, priv->ieee80211->mode); |
| 3272 | //----------------------------------------------------------------------------- |
| 3273 | // Set up security related. 070106, by rcnjko: |
| 3274 | // 1. Clear all H/W keys. |
| 3275 | // 2. Enable H/W encryption/decryption. |
| 3276 | //----------------------------------------------------------------------------- |
| 3277 | CamResetAllEntry(dev); |
| 3278 | { |
| 3279 | u8 SECR_value = 0x0; |
| 3280 | SECR_value |= SCR_TxEncEnable; |
| 3281 | SECR_value |= SCR_RxDecEnable; |
| 3282 | SECR_value |= SCR_NoSKMC; |
| 3283 | write_nic_byte(dev, SECR, SECR_value); |
| 3284 | } |
| 3285 | //3Beacon related |
| 3286 | write_nic_word(dev, ATIMWND, 2); |
| 3287 | write_nic_word(dev, BCN_INTERVAL, 100); |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 3288 | for (i=0; i<QOS_QUEUE_NUM; i++) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3289 | write_nic_dword(dev, WDCAPARA_ADD[i], 0x005e4332); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3290 | // |
| 3291 | // Switching regulator controller: This is set temporarily. |
| 3292 | // It's not sure if this can be removed in the future. |
| 3293 | // PJ advised to leave it by default. |
| 3294 | // |
| 3295 | write_nic_byte(dev, 0xbe, 0xc0); |
| 3296 | |
| 3297 | //2======================================================= |
| 3298 | // Set PHY related configuration defined in MAC register bank |
| 3299 | //2======================================================= |
| 3300 | rtl8192_phy_configmac(dev); |
| 3301 | |
| 3302 | if (priv->card_8192_version > (u8) VERSION_8190_BD) { |
| 3303 | rtl8192_phy_getTxPower(dev); |
| 3304 | rtl8192_phy_setTxPower(dev, priv->chan); |
| 3305 | } |
| 3306 | |
| 3307 | //if D or C cut |
| 3308 | tmpvalue = read_nic_byte(dev, IC_VERRSION); |
| 3309 | priv->IC_Cut = tmpvalue; |
| 3310 | RT_TRACE(COMP_INIT, "priv->IC_Cut = 0x%x\n", priv->IC_Cut); |
| 3311 | if(priv->IC_Cut >= IC_VersionCut_D) |
| 3312 | { |
| 3313 | //pHalData->bDcut = TRUE; |
| 3314 | if(priv->IC_Cut == IC_VersionCut_D) |
| 3315 | RT_TRACE(COMP_INIT, "D-cut\n"); |
| 3316 | if(priv->IC_Cut == IC_VersionCut_E) |
| 3317 | { |
| 3318 | RT_TRACE(COMP_INIT, "E-cut\n"); |
| 3319 | // HW SD suggest that we should not wirte this register too often, so driver |
| 3320 | // should readback this register. This register will be modified only when |
| 3321 | // power on reset |
| 3322 | } |
| 3323 | } |
| 3324 | else |
| 3325 | { |
| 3326 | //pHalData->bDcut = FALSE; |
| 3327 | RT_TRACE(COMP_INIT, "Before C-cut\n"); |
| 3328 | } |
| 3329 | |
| 3330 | #if 1 |
| 3331 | //Firmware download |
| 3332 | RT_TRACE(COMP_INIT, "Load Firmware!\n"); |
| 3333 | bfirmwareok = init_firmware(dev); |
| 3334 | if(bfirmwareok != true) { |
| 3335 | rtStatus = RT_STATUS_FAILURE; |
| 3336 | return rtStatus; |
| 3337 | } |
| 3338 | RT_TRACE(COMP_INIT, "Load Firmware finished!\n"); |
| 3339 | #endif |
| 3340 | //RF config |
| 3341 | if(priv->ResetProgress == RESET_TYPE_NORESET) |
| 3342 | { |
| 3343 | RT_TRACE(COMP_INIT, "RF Config Started!\n"); |
| 3344 | rtStatus = rtl8192_phy_RFConfig(dev); |
| 3345 | if(rtStatus != RT_STATUS_SUCCESS) |
| 3346 | { |
| 3347 | RT_TRACE(COMP_ERR, "RF Config failed\n"); |
| 3348 | return rtStatus; |
| 3349 | } |
| 3350 | RT_TRACE(COMP_INIT, "RF Config Finished!\n"); |
| 3351 | } |
| 3352 | rtl8192_phy_updateInitGain(dev); |
| 3353 | |
| 3354 | /*---- Set CCK and OFDM Block "ON"----*/ |
| 3355 | rtl8192_setBBreg(dev, rFPGA0_RFMOD, bCCKEn, 0x1); |
| 3356 | rtl8192_setBBreg(dev, rFPGA0_RFMOD, bOFDMEn, 0x1); |
| 3357 | |
| 3358 | #ifdef RTL8192E |
| 3359 | //Enable Led |
| 3360 | write_nic_byte(dev, 0x87, 0x0); |
| 3361 | #endif |
| 3362 | #ifdef RTL8190P |
| 3363 | //2008.06.03, for WOL |
| 3364 | ucRegRead = read_nic_byte(dev, GPE); |
| 3365 | ucRegRead |= BIT0; |
| 3366 | write_nic_byte(dev, GPE, ucRegRead); |
| 3367 | |
| 3368 | ucRegRead = read_nic_byte(dev, GPO); |
| 3369 | ucRegRead &= ~BIT0; |
| 3370 | write_nic_byte(dev, GPO, ucRegRead); |
| 3371 | #endif |
| 3372 | |
| 3373 | //2======================================================= |
| 3374 | // RF Power Save |
| 3375 | //2======================================================= |
| 3376 | #ifdef ENABLE_IPS |
| 3377 | |
| 3378 | { |
| 3379 | if(priv->RegRfOff == TRUE) |
| 3380 | { // User disable RF via registry. |
| 3381 | RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RegRfOff ----------\n",__FUNCTION__); |
| 3382 | MgntActSet_RF_State(dev, eRfOff, RF_CHANGE_BY_SW); |
| 3383 | #if 0//cosa, ask SD3 willis and he doesn't know what is this for |
| 3384 | // Those action will be discard in MgntActSet_RF_State because off the same state |
| 3385 | for(eRFPath = 0; eRFPath <pHalData->NumTotalRFPath; eRFPath++) |
| 3386 | PHY_SetRFReg(Adapter, (RF90_RADIO_PATH_E)eRFPath, 0x4, 0xC00, 0x0); |
| 3387 | #endif |
| 3388 | } |
| 3389 | else if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_PS) |
| 3390 | { // H/W or S/W RF OFF before sleep. |
| 3391 | RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d) ----------\n", __FUNCTION__,priv->ieee80211->RfOffReason); |
| 3392 | MgntActSet_RF_State(dev, eRfOff, priv->ieee80211->RfOffReason); |
| 3393 | } |
| 3394 | else if(priv->ieee80211->RfOffReason >= RF_CHANGE_BY_IPS) |
| 3395 | { // H/W or S/W RF OFF before sleep. |
| 3396 | RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): Turn off RF for RfOffReason(%d) ----------\n", __FUNCTION__,priv->ieee80211->RfOffReason); |
| 3397 | MgntActSet_RF_State(dev, eRfOff, priv->ieee80211->RfOffReason); |
| 3398 | } |
| 3399 | else |
| 3400 | { |
| 3401 | RT_TRACE((COMP_INIT|COMP_RF|COMP_POWER), "%s(): RF-ON \n",__FUNCTION__); |
| 3402 | priv->ieee80211->eRFPowerState = eRfOn; |
| 3403 | priv->ieee80211->RfOffReason = 0; |
| 3404 | //DrvIFIndicateCurrentPhyStatus(Adapter); |
| 3405 | // LED control |
| 3406 | //Adapter->HalFunc.LedControlHandler(Adapter, LED_CTL_POWER_ON); |
| 3407 | |
| 3408 | // |
| 3409 | // If inactive power mode is enabled, disable rf while in disconnected state. |
| 3410 | // But we should still tell upper layer we are in rf on state. |
| 3411 | // 2007.07.16, by shien chang. |
| 3412 | // |
| 3413 | //if(!Adapter->bInHctTest) |
| 3414 | //IPSEnter(Adapter); |
| 3415 | |
| 3416 | } |
| 3417 | } |
| 3418 | #endif |
| 3419 | if(1){ |
| 3420 | #ifdef RTL8192E |
| 3421 | // We can force firmware to do RF-R/W |
| 3422 | if(priv->ieee80211->FwRWRF) |
| 3423 | priv->Rf_Mode = RF_OP_By_FW; |
| 3424 | else |
| 3425 | priv->Rf_Mode = RF_OP_By_SW_3wire; |
| 3426 | #else |
| 3427 | priv->Rf_Mode = RF_OP_By_SW_3wire; |
| 3428 | #endif |
| 3429 | } |
| 3430 | #ifdef RTL8190P |
| 3431 | if(priv->ResetProgress == RESET_TYPE_NORESET) |
| 3432 | { |
| 3433 | dm_initialize_txpower_tracking(dev); |
| 3434 | |
| 3435 | tmpRegA= rtl8192_QueryBBReg(dev,rOFDM0_XATxIQImbalance,bMaskDWord); |
| 3436 | tmpRegC= rtl8192_QueryBBReg(dev,rOFDM0_XCTxIQImbalance,bMaskDWord); |
| 3437 | |
| 3438 | if(priv->rf_type == RF_2T4R){ |
| 3439 | for(i = 0; i<TxBBGainTableLength; i++) |
| 3440 | { |
| 3441 | if(tmpRegA == priv->txbbgain_table[i].txbbgain_value) |
| 3442 | { |
| 3443 | priv->rfa_txpowertrackingindex= (u8)i; |
| 3444 | priv->rfa_txpowertrackingindex_real= (u8)i; |
| 3445 | priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex; |
| 3446 | break; |
| 3447 | } |
| 3448 | } |
| 3449 | } |
| 3450 | for(i = 0; i<TxBBGainTableLength; i++) |
| 3451 | { |
| 3452 | if(tmpRegC == priv->txbbgain_table[i].txbbgain_value) |
| 3453 | { |
| 3454 | priv->rfc_txpowertrackingindex= (u8)i; |
| 3455 | priv->rfc_txpowertrackingindex_real= (u8)i; |
| 3456 | priv->rfc_txpowertracking_default = priv->rfc_txpowertrackingindex; |
| 3457 | break; |
| 3458 | } |
| 3459 | } |
| 3460 | TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2); |
| 3461 | |
| 3462 | for(i=0 ; i<CCKTxBBGainTableLength ; i++) |
| 3463 | { |
| 3464 | if(TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0]) |
| 3465 | { |
| 3466 | priv->CCKPresentAttentuation_20Mdefault =(u8) i; |
| 3467 | break; |
| 3468 | } |
| 3469 | } |
| 3470 | priv->CCKPresentAttentuation_40Mdefault = 0; |
| 3471 | priv->CCKPresentAttentuation_difference = 0; |
| 3472 | priv->CCKPresentAttentuation = priv->CCKPresentAttentuation_20Mdefault; |
| 3473 | RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_initial = %d\n", priv->rfa_txpowertrackingindex); |
| 3474 | RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real__initial = %d\n", priv->rfa_txpowertrackingindex_real); |
| 3475 | RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex_initial = %d\n", priv->rfc_txpowertrackingindex); |
| 3476 | RT_TRACE(COMP_POWER_TRACKING, "priv->rfc_txpowertrackingindex_real_initial = %d\n", priv->rfc_txpowertrackingindex_real); |
| 3477 | RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_difference_initial = %d\n", priv->CCKPresentAttentuation_difference); |
| 3478 | RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_initial = %d\n", priv->CCKPresentAttentuation); |
| 3479 | } |
| 3480 | #else |
| 3481 | #ifdef RTL8192E |
| 3482 | if(priv->ResetProgress == RESET_TYPE_NORESET) |
| 3483 | { |
| 3484 | dm_initialize_txpower_tracking(dev); |
| 3485 | |
| 3486 | if(priv->IC_Cut >= IC_VersionCut_D) |
| 3487 | { |
| 3488 | tmpRegA= rtl8192_QueryBBReg(dev,rOFDM0_XATxIQImbalance,bMaskDWord); |
| 3489 | tmpRegC= rtl8192_QueryBBReg(dev,rOFDM0_XCTxIQImbalance,bMaskDWord); |
| 3490 | for(i = 0; i<TxBBGainTableLength; i++) |
| 3491 | { |
| 3492 | if(tmpRegA == priv->txbbgain_table[i].txbbgain_value) |
| 3493 | { |
| 3494 | priv->rfa_txpowertrackingindex= (u8)i; |
| 3495 | priv->rfa_txpowertrackingindex_real= (u8)i; |
| 3496 | priv->rfa_txpowertracking_default = priv->rfa_txpowertrackingindex; |
| 3497 | break; |
| 3498 | } |
| 3499 | } |
| 3500 | |
| 3501 | TempCCk = rtl8192_QueryBBReg(dev, rCCK0_TxFilter1, bMaskByte2); |
| 3502 | |
| 3503 | for(i=0 ; i<CCKTxBBGainTableLength ; i++) |
| 3504 | { |
| 3505 | if(TempCCk == priv->cck_txbbgain_table[i].ccktxbb_valuearray[0]) |
| 3506 | { |
| 3507 | priv->CCKPresentAttentuation_20Mdefault =(u8) i; |
| 3508 | break; |
| 3509 | } |
| 3510 | } |
| 3511 | priv->CCKPresentAttentuation_40Mdefault = 0; |
| 3512 | priv->CCKPresentAttentuation_difference = 0; |
| 3513 | priv->CCKPresentAttentuation = priv->CCKPresentAttentuation_20Mdefault; |
| 3514 | RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_initial = %d\n", priv->rfa_txpowertrackingindex); |
| 3515 | RT_TRACE(COMP_POWER_TRACKING, "priv->rfa_txpowertrackingindex_real__initial = %d\n", priv->rfa_txpowertrackingindex_real); |
| 3516 | RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_difference_initial = %d\n", priv->CCKPresentAttentuation_difference); |
| 3517 | RT_TRACE(COMP_POWER_TRACKING, "priv->CCKPresentAttentuation_initial = %d\n", priv->CCKPresentAttentuation); |
| 3518 | priv->btxpower_tracking = FALSE;//TEMPLY DISABLE |
| 3519 | } |
| 3520 | } |
| 3521 | #endif |
| 3522 | #endif |
| 3523 | rtl8192_irq_enable(dev); |
| 3524 | priv->being_init_adapter = false; |
| 3525 | return rtStatus; |
| 3526 | |
| 3527 | } |
| 3528 | |
Mike McCormack | 559fba5 | 2010-07-26 22:57:52 +0900 | [diff] [blame] | 3529 | static void rtl8192_prepare_beacon(struct r8192_priv *priv) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3530 | { |
| 3531 | struct sk_buff *skb; |
| 3532 | //unsigned long flags; |
| 3533 | cb_desc *tcb_desc; |
| 3534 | |
| 3535 | skb = ieee80211_get_beacon(priv->ieee80211); |
| 3536 | tcb_desc = (cb_desc *)(skb->cb + 8); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3537 | //spin_lock_irqsave(&priv->tx_lock,flags); |
| 3538 | /* prepare misc info for the beacon xmit */ |
| 3539 | tcb_desc->queue_index = BEACON_QUEUE; |
André Goddard Rosa | bbc9a99 | 2009-11-14 13:09:06 -0200 | [diff] [blame] | 3540 | /* IBSS does not support HT yet, use 1M defaultly */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3541 | tcb_desc->data_rate = 2; |
| 3542 | tcb_desc->RATRIndex = 7; |
| 3543 | tcb_desc->bTxDisableRateFallBack = 1; |
| 3544 | tcb_desc->bTxUseDriverAssingedRate = 1; |
| 3545 | |
| 3546 | skb_push(skb, priv->ieee80211->tx_headroom); |
| 3547 | if(skb){ |
| 3548 | rtl8192_tx(priv->ieee80211->dev,skb); |
| 3549 | } |
| 3550 | //spin_unlock_irqrestore (&priv->tx_lock, flags); |
| 3551 | } |
| 3552 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3553 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 3554 | /* |
| 3555 | * configure registers for beacon tx and enables it via |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3556 | * rtl8192_beacon_tx_enable(). rtl8192_beacon_tx_disable() might |
| 3557 | * be used to stop beacon transmission |
| 3558 | */ |
Mike McCormack | 559fba5 | 2010-07-26 22:57:52 +0900 | [diff] [blame] | 3559 | static void rtl8192_start_beacon(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3560 | { |
| 3561 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 3562 | struct ieee80211_network *net = &priv->ieee80211->current_network; |
| 3563 | u16 BcnTimeCfg = 0; |
| 3564 | u16 BcnCW = 6; |
| 3565 | u16 BcnIFS = 0xf; |
| 3566 | |
| 3567 | DMESG("Enabling beacon TX"); |
| 3568 | //rtl8192_prepare_beacon(dev); |
| 3569 | rtl8192_irq_disable(dev); |
| 3570 | //rtl8192_beacon_tx_enable(dev); |
| 3571 | |
| 3572 | /* ATIM window */ |
| 3573 | write_nic_word(dev, ATIMWND, 2); |
| 3574 | |
| 3575 | /* Beacon interval (in unit of TU) */ |
| 3576 | write_nic_word(dev, BCN_INTERVAL, net->beacon_interval); |
| 3577 | |
| 3578 | /* |
| 3579 | * DrvErlyInt (in unit of TU). |
| 3580 | * (Time to send interrupt to notify driver to c |
| 3581 | * hange beacon content) |
| 3582 | * */ |
| 3583 | write_nic_word(dev, BCN_DRV_EARLY_INT, 10); |
| 3584 | |
| 3585 | /* |
| 3586 | * BcnDMATIM(in unit of us). |
| 3587 | * Indicates the time before TBTT to perform beacon queue DMA |
| 3588 | * */ |
| 3589 | write_nic_word(dev, BCN_DMATIME, 256); |
| 3590 | |
| 3591 | /* |
| 3592 | * Force beacon frame transmission even after receiving |
| 3593 | * beacon frame from other ad hoc STA |
| 3594 | * */ |
| 3595 | write_nic_byte(dev, BCN_ERR_THRESH, 100); |
| 3596 | |
| 3597 | /* Set CW and IFS */ |
| 3598 | BcnTimeCfg |= BcnCW<<BCN_TCFG_CW_SHIFT; |
| 3599 | BcnTimeCfg |= BcnIFS<<BCN_TCFG_IFS; |
| 3600 | write_nic_word(dev, BCN_TCFG, BcnTimeCfg); |
| 3601 | |
| 3602 | |
| 3603 | /* enable the interrupt for ad-hoc process */ |
| 3604 | rtl8192_irq_enable(dev); |
| 3605 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3606 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 3607 | static bool HalTxCheckStuck8190Pci(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3608 | { |
| 3609 | u16 RegTxCounter = read_nic_word(dev, 0x128); |
| 3610 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 3611 | bool bStuck = FALSE; |
| 3612 | RT_TRACE(COMP_RESET,"%s():RegTxCounter is %d,TxCounter is %d\n",__FUNCTION__,RegTxCounter,priv->TxCounter); |
| 3613 | if(priv->TxCounter==RegTxCounter) |
| 3614 | bStuck = TRUE; |
| 3615 | |
| 3616 | priv->TxCounter = RegTxCounter; |
| 3617 | |
| 3618 | return bStuck; |
| 3619 | } |
| 3620 | |
| 3621 | /* |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 3622 | * Assumption: RT_TX_SPINLOCK is acquired. |
| 3623 | */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 3624 | static RESET_TYPE |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3625 | TxCheckStuck(struct net_device *dev) |
| 3626 | { |
| 3627 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 3628 | u8 QueueID; |
| 3629 | ptx_ring head=NULL,tail=NULL,txring = NULL; |
| 3630 | u8 ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE; |
| 3631 | bool bCheckFwTxCnt = false; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3632 | |
| 3633 | // |
| 3634 | // Decide Stuch threshold according to current power save mode |
| 3635 | // |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3636 | switch (priv->ieee80211->dot11PowerSaveMode) |
| 3637 | { |
| 3638 | // The threshold value may required to be adjusted . |
| 3639 | case eActive: // Active/Continuous access. |
| 3640 | ResetThreshold = NIC_SEND_HANG_THRESHOLD_NORMAL; |
| 3641 | break; |
| 3642 | case eMaxPs: // Max power save mode. |
| 3643 | ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE; |
| 3644 | break; |
| 3645 | case eFastPs: // Fast power save mode. |
| 3646 | ResetThreshold = NIC_SEND_HANG_THRESHOLD_POWERSAVE; |
| 3647 | break; |
| 3648 | } |
| 3649 | |
| 3650 | // |
| 3651 | // Check whether specific tcb has been queued for a specific time |
| 3652 | // |
| 3653 | for(QueueID = 0; QueueID < MAX_TX_QUEUE; QueueID++) |
| 3654 | { |
| 3655 | |
| 3656 | |
| 3657 | if(QueueID == TXCMD_QUEUE) |
| 3658 | continue; |
| 3659 | |
| 3660 | switch(QueueID) { |
| 3661 | case MGNT_QUEUE: |
| 3662 | tail=priv->txmapringtail; |
| 3663 | head=priv->txmapringhead; |
| 3664 | break; |
| 3665 | |
| 3666 | case BK_QUEUE: |
| 3667 | tail=priv->txbkpringtail; |
| 3668 | head=priv->txbkpringhead; |
| 3669 | break; |
| 3670 | |
| 3671 | case BE_QUEUE: |
| 3672 | tail=priv->txbepringtail; |
| 3673 | head=priv->txbepringhead; |
| 3674 | break; |
| 3675 | |
| 3676 | case VI_QUEUE: |
| 3677 | tail=priv->txvipringtail; |
| 3678 | head=priv->txvipringhead; |
| 3679 | break; |
| 3680 | |
| 3681 | case VO_QUEUE: |
| 3682 | tail=priv->txvopringtail; |
| 3683 | head=priv->txvopringhead; |
| 3684 | break; |
| 3685 | |
| 3686 | default: |
| 3687 | tail=head=NULL; |
| 3688 | break; |
| 3689 | } |
| 3690 | |
| 3691 | if(tail == head) |
| 3692 | continue; |
| 3693 | else |
| 3694 | { |
| 3695 | txring = head; |
| 3696 | if(txring == NULL) |
| 3697 | { |
| 3698 | RT_TRACE(COMP_ERR,"%s():txring is NULL , BUG!\n",__FUNCTION__); |
| 3699 | continue; |
| 3700 | } |
| 3701 | txring->nStuckCount++; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3702 | bCheckFwTxCnt = TRUE; |
| 3703 | } |
| 3704 | } |
| 3705 | #if 1 |
| 3706 | if(bCheckFwTxCnt) |
| 3707 | { |
| 3708 | if(HalTxCheckStuck8190Pci(dev)) |
| 3709 | { |
| 3710 | RT_TRACE(COMP_RESET, "TxCheckStuck(): Fw indicates no Tx condition! \n"); |
| 3711 | return RESET_TYPE_SILENT; |
| 3712 | } |
| 3713 | } |
| 3714 | #endif |
| 3715 | return RESET_TYPE_NORESET; |
| 3716 | } |
| 3717 | |
| 3718 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 3719 | static bool HalRxCheckStuck8190Pci(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3720 | { |
| 3721 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 3722 | u16 RegRxCounter = read_nic_word(dev, 0x130); |
| 3723 | bool bStuck = FALSE; |
| 3724 | static u8 rx_chk_cnt = 0; |
| 3725 | RT_TRACE(COMP_RESET,"%s(): RegRxCounter is %d,RxCounter is %d\n",__FUNCTION__,RegRxCounter,priv->RxCounter); |
| 3726 | // If rssi is small, we should check rx for long time because of bad rx. |
| 3727 | // or maybe it will continuous silent reset every 2 seconds. |
| 3728 | rx_chk_cnt++; |
| 3729 | if(priv->undecorated_smoothed_pwdb >= (RateAdaptiveTH_High+5)) |
| 3730 | { |
| 3731 | rx_chk_cnt = 0; //high rssi, check rx stuck right now. |
| 3732 | } |
| 3733 | else if(priv->undecorated_smoothed_pwdb < (RateAdaptiveTH_High+5) && |
| 3734 | ((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_40M) || |
| 3735 | (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb>=RateAdaptiveTH_Low_20M)) ) |
| 3736 | |
| 3737 | { |
| 3738 | if(rx_chk_cnt < 2) |
| 3739 | { |
| 3740 | return bStuck; |
| 3741 | } |
| 3742 | else |
| 3743 | { |
| 3744 | rx_chk_cnt = 0; |
| 3745 | } |
| 3746 | } |
| 3747 | else if(((priv->CurrentChannelBW!=HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_40M) || |
| 3748 | (priv->CurrentChannelBW==HT_CHANNEL_WIDTH_20&&priv->undecorated_smoothed_pwdb<RateAdaptiveTH_Low_20M)) && |
| 3749 | priv->undecorated_smoothed_pwdb >= VeryLowRSSI) |
| 3750 | { |
| 3751 | if(rx_chk_cnt < 4) |
| 3752 | { |
| 3753 | //DbgPrint("RSSI < %d && RSSI >= %d, no check this time \n", RateAdaptiveTH_Low, VeryLowRSSI); |
| 3754 | return bStuck; |
| 3755 | } |
| 3756 | else |
| 3757 | { |
| 3758 | rx_chk_cnt = 0; |
| 3759 | //DbgPrint("RSSI < %d && RSSI >= %d, check this time \n", RateAdaptiveTH_Low, VeryLowRSSI); |
| 3760 | } |
| 3761 | } |
| 3762 | else |
| 3763 | { |
| 3764 | if(rx_chk_cnt < 8) |
| 3765 | { |
| 3766 | //DbgPrint("RSSI <= %d, no check this time \n", VeryLowRSSI); |
| 3767 | return bStuck; |
| 3768 | } |
| 3769 | else |
| 3770 | { |
| 3771 | rx_chk_cnt = 0; |
| 3772 | //DbgPrint("RSSI <= %d, check this time \n", VeryLowRSSI); |
| 3773 | } |
| 3774 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3775 | if(priv->RxCounter==RegRxCounter) |
| 3776 | bStuck = TRUE; |
| 3777 | |
| 3778 | priv->RxCounter = RegRxCounter; |
| 3779 | |
| 3780 | return bStuck; |
| 3781 | } |
| 3782 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 3783 | static RESET_TYPE RxCheckStuck(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3784 | { |
| 3785 | |
| 3786 | if(HalRxCheckStuck8190Pci(dev)) |
| 3787 | { |
| 3788 | RT_TRACE(COMP_RESET, "RxStuck Condition\n"); |
| 3789 | return RESET_TYPE_SILENT; |
| 3790 | } |
| 3791 | |
| 3792 | return RESET_TYPE_NORESET; |
| 3793 | } |
| 3794 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 3795 | static RESET_TYPE |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3796 | rtl819x_ifcheck_resetornot(struct net_device *dev) |
| 3797 | { |
| 3798 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 3799 | RESET_TYPE TxResetType = RESET_TYPE_NORESET; |
| 3800 | RESET_TYPE RxResetType = RESET_TYPE_NORESET; |
| 3801 | RT_RF_POWER_STATE rfState; |
| 3802 | |
| 3803 | rfState = priv->ieee80211->eRFPowerState; |
| 3804 | |
| 3805 | TxResetType = TxCheckStuck(dev); |
| 3806 | #if 1 |
| 3807 | if( rfState != eRfOff && |
| 3808 | /*ADAPTER_TEST_STATUS_FLAG(Adapter, ADAPTER_STATUS_FW_DOWNLOAD_FAILURE)) &&*/ |
| 3809 | (priv->ieee80211->iw_mode != IW_MODE_ADHOC)) |
| 3810 | { |
| 3811 | // If driver is in the status of firmware download failure , driver skips RF initialization and RF is |
| 3812 | // in turned off state. Driver should check whether Rx stuck and do silent reset. And |
| 3813 | // if driver is in firmware download failure status, driver should initialize RF in the following |
| 3814 | // silent reset procedure Emily, 2008.01.21 |
| 3815 | |
| 3816 | // Driver should not check RX stuck in IBSS mode because it is required to |
| 3817 | // set Check BSSID in order to send beacon, however, if check BSSID is |
| 3818 | // set, STA cannot hear any packet a all. Emily, 2008.04.12 |
| 3819 | RxResetType = RxCheckStuck(dev); |
| 3820 | } |
| 3821 | #endif |
| 3822 | |
| 3823 | RT_TRACE(COMP_RESET,"%s(): TxResetType is %d, RxResetType is %d\n",__FUNCTION__,TxResetType,RxResetType); |
| 3824 | if(TxResetType==RESET_TYPE_NORMAL || RxResetType==RESET_TYPE_NORMAL) |
| 3825 | return RESET_TYPE_NORMAL; |
| 3826 | else if(TxResetType==RESET_TYPE_SILENT || RxResetType==RESET_TYPE_SILENT) |
| 3827 | return RESET_TYPE_SILENT; |
| 3828 | else |
| 3829 | return RESET_TYPE_NORESET; |
| 3830 | |
| 3831 | } |
| 3832 | |
| 3833 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 3834 | static void CamRestoreAllEntry(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3835 | { |
| 3836 | u8 EntryId = 0; |
| 3837 | struct r8192_priv *priv = ieee80211_priv(dev); |
Mike McCormack | 881a975 | 2010-07-26 22:58:03 +0900 | [diff] [blame] | 3838 | const u8* MacAddr = priv->ieee80211->current_network.bssid; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3839 | |
Mike McCormack | 881a975 | 2010-07-26 22:58:03 +0900 | [diff] [blame] | 3840 | static const u8 CAM_CONST_ADDR[4][6] = { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3841 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, |
| 3842 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, |
| 3843 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, |
| 3844 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x03}}; |
Mike McCormack | 881a975 | 2010-07-26 22:58:03 +0900 | [diff] [blame] | 3845 | static const u8 CAM_CONST_BROAD[] = |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3846 | {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 3847 | |
| 3848 | RT_TRACE(COMP_SEC, "CamRestoreAllEntry: \n"); |
| 3849 | |
| 3850 | |
| 3851 | if ((priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP40)|| |
| 3852 | (priv->ieee80211->pairwise_key_type == KEY_TYPE_WEP104)) |
| 3853 | { |
| 3854 | |
| 3855 | for(EntryId=0; EntryId<4; EntryId++) |
| 3856 | { |
| 3857 | { |
| 3858 | MacAddr = CAM_CONST_ADDR[EntryId]; |
| 3859 | setKey(dev, |
| 3860 | EntryId , |
| 3861 | EntryId, |
| 3862 | priv->ieee80211->pairwise_key_type, |
| 3863 | MacAddr, |
| 3864 | 0, |
| 3865 | NULL); |
| 3866 | } |
| 3867 | } |
| 3868 | |
| 3869 | } |
| 3870 | else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_TKIP) |
| 3871 | { |
| 3872 | |
| 3873 | { |
| 3874 | if(priv->ieee80211->iw_mode == IW_MODE_ADHOC) |
| 3875 | setKey(dev, |
| 3876 | 4, |
| 3877 | 0, |
| 3878 | priv->ieee80211->pairwise_key_type, |
| 3879 | (u8*)dev->dev_addr, |
| 3880 | 0, |
| 3881 | NULL); |
| 3882 | else |
| 3883 | setKey(dev, |
| 3884 | 4, |
| 3885 | 0, |
| 3886 | priv->ieee80211->pairwise_key_type, |
| 3887 | MacAddr, |
| 3888 | 0, |
| 3889 | NULL); |
| 3890 | } |
| 3891 | } |
| 3892 | else if(priv->ieee80211->pairwise_key_type == KEY_TYPE_CCMP) |
| 3893 | { |
| 3894 | |
| 3895 | { |
| 3896 | if(priv->ieee80211->iw_mode == IW_MODE_ADHOC) |
| 3897 | setKey(dev, |
| 3898 | 4, |
| 3899 | 0, |
| 3900 | priv->ieee80211->pairwise_key_type, |
| 3901 | (u8*)dev->dev_addr, |
| 3902 | 0, |
| 3903 | NULL); |
| 3904 | else |
| 3905 | setKey(dev, |
| 3906 | 4, |
| 3907 | 0, |
| 3908 | priv->ieee80211->pairwise_key_type, |
| 3909 | MacAddr, |
| 3910 | 0, |
| 3911 | NULL); |
| 3912 | } |
| 3913 | } |
| 3914 | |
| 3915 | |
| 3916 | |
| 3917 | if(priv->ieee80211->group_key_type == KEY_TYPE_TKIP) |
| 3918 | { |
| 3919 | MacAddr = CAM_CONST_BROAD; |
| 3920 | for(EntryId=1 ; EntryId<4 ; EntryId++) |
| 3921 | { |
| 3922 | { |
| 3923 | setKey(dev, |
| 3924 | EntryId, |
| 3925 | EntryId, |
| 3926 | priv->ieee80211->group_key_type, |
| 3927 | MacAddr, |
| 3928 | 0, |
| 3929 | NULL); |
| 3930 | } |
| 3931 | } |
| 3932 | if(priv->ieee80211->iw_mode == IW_MODE_ADHOC) |
| 3933 | setKey(dev, |
| 3934 | 0, |
| 3935 | 0, |
| 3936 | priv->ieee80211->group_key_type, |
| 3937 | CAM_CONST_ADDR[0], |
| 3938 | 0, |
| 3939 | NULL); |
| 3940 | } |
| 3941 | else if(priv->ieee80211->group_key_type == KEY_TYPE_CCMP) |
| 3942 | { |
| 3943 | MacAddr = CAM_CONST_BROAD; |
| 3944 | for(EntryId=1; EntryId<4 ; EntryId++) |
| 3945 | { |
| 3946 | { |
| 3947 | setKey(dev, |
| 3948 | EntryId , |
| 3949 | EntryId, |
| 3950 | priv->ieee80211->group_key_type, |
| 3951 | MacAddr, |
| 3952 | 0, |
| 3953 | NULL); |
| 3954 | } |
| 3955 | } |
| 3956 | |
| 3957 | if(priv->ieee80211->iw_mode == IW_MODE_ADHOC) |
| 3958 | setKey(dev, |
| 3959 | 0 , |
| 3960 | 0, |
| 3961 | priv->ieee80211->group_key_type, |
| 3962 | CAM_CONST_ADDR[0], |
| 3963 | 0, |
| 3964 | NULL); |
| 3965 | } |
| 3966 | } |
| 3967 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3968 | /* |
| 3969 | * This function is used to fix Tx/Rx stop bug temporarily. |
| 3970 | * This function will do "system reset" to NIC when Tx or Rx is stuck. |
| 3971 | * The method checking Tx/Rx stuck of this function is supported by FW, |
| 3972 | * which reports Tx and Rx counter to register 0x128 and 0x130. |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 3973 | */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 3974 | static void rtl819x_ifsilentreset(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3975 | { |
| 3976 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 3977 | u8 reset_times = 0; |
| 3978 | int reset_status = 0; |
| 3979 | struct ieee80211_device *ieee = priv->ieee80211; |
| 3980 | |
| 3981 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 3982 | return; |
| 3983 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3984 | // 2007.07.20. If we need to check CCK stop, please uncomment this line. |
| 3985 | //bStuck = Adapter->HalFunc.CheckHWStopHandler(Adapter); |
| 3986 | |
| 3987 | if(priv->ResetProgress==RESET_TYPE_NORESET) |
| 3988 | { |
| 3989 | RESET_START: |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 3990 | #ifdef ENABLE_LPS |
| 3991 | //LZM for PS-Poll AID issue. 090429 |
| 3992 | if(priv->ieee80211->state == IEEE80211_LINKED) |
| 3993 | LeisurePSLeave(dev); |
| 3994 | #endif |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 3995 | |
| 3996 | RT_TRACE(COMP_RESET,"=========>Reset progress!! \n"); |
| 3997 | |
| 3998 | // Set the variable for reset. |
| 3999 | priv->ResetProgress = RESET_TYPE_SILENT; |
| 4000 | // rtl8192_close(dev); |
| 4001 | #if 1 |
| 4002 | down(&priv->wx_sem); |
| 4003 | if(priv->up == 0) |
| 4004 | { |
| 4005 | RT_TRACE(COMP_ERR,"%s():the driver is not up! return\n",__FUNCTION__); |
| 4006 | up(&priv->wx_sem); |
| 4007 | return ; |
| 4008 | } |
| 4009 | priv->up = 0; |
| 4010 | RT_TRACE(COMP_RESET,"%s():======>start to down the driver\n",__FUNCTION__); |
| 4011 | if(!netif_queue_stopped(dev)) |
| 4012 | netif_stop_queue(dev); |
| 4013 | |
| 4014 | dm_backup_dynamic_mechanism_state(dev); |
| 4015 | |
| 4016 | rtl8192_irq_disable(dev); |
| 4017 | rtl8192_cancel_deferred_work(priv); |
| 4018 | deinit_hal_dm(dev); |
| 4019 | del_timer_sync(&priv->watch_dog_timer); |
| 4020 | ieee->sync_scan_hurryup = 1; |
| 4021 | if(ieee->state == IEEE80211_LINKED) |
| 4022 | { |
| 4023 | down(&ieee->wx_sem); |
| 4024 | printk("ieee->state is IEEE80211_LINKED\n"); |
| 4025 | ieee80211_stop_send_beacons(priv->ieee80211); |
| 4026 | del_timer_sync(&ieee->associate_timer); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4027 | cancel_delayed_work(&ieee->associate_retry_wq); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4028 | ieee80211_stop_scan(ieee); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4029 | up(&ieee->wx_sem); |
| 4030 | } |
| 4031 | else{ |
| 4032 | printk("ieee->state is NOT LINKED\n"); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4033 | ieee80211_softmac_stop_protocol(priv->ieee80211,true); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4034 | } |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4035 | rtl8192_halt_adapter(dev, true); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4036 | up(&priv->wx_sem); |
| 4037 | RT_TRACE(COMP_RESET,"%s():<==========down process is finished\n",__FUNCTION__); |
| 4038 | RT_TRACE(COMP_RESET,"%s():===========>start to up the driver\n",__FUNCTION__); |
| 4039 | reset_status = _rtl8192_up(dev); |
| 4040 | |
| 4041 | RT_TRACE(COMP_RESET,"%s():<===========up process is finished\n",__FUNCTION__); |
| 4042 | if(reset_status == -1) |
| 4043 | { |
| 4044 | if(reset_times < 3) |
| 4045 | { |
| 4046 | reset_times++; |
| 4047 | goto RESET_START; |
| 4048 | } |
| 4049 | else |
| 4050 | { |
| 4051 | RT_TRACE(COMP_ERR," ERR!!! %s(): Reset Failed!!\n",__FUNCTION__); |
| 4052 | } |
| 4053 | } |
| 4054 | #endif |
| 4055 | ieee->is_silent_reset = 1; |
| 4056 | #if 1 |
| 4057 | EnableHWSecurityConfig8192(dev); |
| 4058 | #if 1 |
| 4059 | if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA) |
| 4060 | { |
| 4061 | ieee->set_chan(ieee->dev, ieee->current_network.channel); |
| 4062 | |
| 4063 | #if 1 |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4064 | queue_work(ieee->wq, &ieee->associate_complete_wq); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4065 | #endif |
| 4066 | |
| 4067 | } |
| 4068 | else if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_ADHOC) |
| 4069 | { |
| 4070 | ieee->set_chan(ieee->dev, ieee->current_network.channel); |
| 4071 | ieee->link_change(ieee->dev); |
| 4072 | |
| 4073 | // notify_wx_assoc_event(ieee); |
| 4074 | |
| 4075 | ieee80211_start_send_beacons(ieee); |
| 4076 | |
| 4077 | if (ieee->data_hard_resume) |
| 4078 | ieee->data_hard_resume(ieee->dev); |
| 4079 | netif_carrier_on(ieee->dev); |
| 4080 | } |
| 4081 | #endif |
| 4082 | |
| 4083 | CamRestoreAllEntry(dev); |
| 4084 | |
| 4085 | // Restore the previous setting for all dynamic mechanism |
| 4086 | dm_restore_dynamic_mechanism_state(dev); |
| 4087 | |
| 4088 | priv->ResetProgress = RESET_TYPE_NORESET; |
| 4089 | priv->reset_count++; |
| 4090 | |
| 4091 | priv->bForcedSilentReset =false; |
| 4092 | priv->bResetInProgress = false; |
| 4093 | |
| 4094 | // For test --> force write UFWP. |
| 4095 | write_nic_byte(dev, UFWP, 1); |
| 4096 | RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", priv->reset_count); |
| 4097 | #endif |
| 4098 | } |
| 4099 | } |
| 4100 | |
| 4101 | #ifdef ENABLE_IPS |
| 4102 | void InactivePsWorkItemCallback(struct net_device *dev) |
| 4103 | { |
| 4104 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4105 | PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl)); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4106 | |
| 4107 | RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() ---------> \n"); |
| 4108 | // |
| 4109 | // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem |
| 4110 | // is really scheduled. |
| 4111 | // The old code, sets this flag before scheduling the IPS workitem and however, at the same time the |
| 4112 | // previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing |
| 4113 | // blocks the IPS procedure of switching RF. |
| 4114 | // By Bruce, 2007-12-25. |
| 4115 | // |
| 4116 | pPSC->bSwRfProcessing = TRUE; |
| 4117 | |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 4118 | RT_TRACE(COMP_RF, "InactivePsWorkItemCallback(): Set RF to %s.\n", |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4119 | pPSC->eInactivePowerState == eRfOff?"OFF":"ON"); |
| 4120 | |
| 4121 | |
| 4122 | MgntActSet_RF_State(dev, pPSC->eInactivePowerState, RF_CHANGE_BY_IPS); |
| 4123 | |
| 4124 | // |
| 4125 | // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20. |
| 4126 | // |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4127 | pPSC->bSwRfProcessing = FALSE; |
| 4128 | RT_TRACE(COMP_POWER, "InactivePsWorkItemCallback() <--------- \n"); |
| 4129 | } |
| 4130 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4131 | #ifdef ENABLE_LPS |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 4132 | /* Change current and default preamble mode. */ |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4133 | bool MgntActSet_802_11_PowerSaveMode(struct net_device *dev, u8 rtPsMode) |
| 4134 | { |
| 4135 | struct r8192_priv *priv = ieee80211_priv(dev); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4136 | |
| 4137 | // Currently, we do not change power save mode on IBSS mode. |
| 4138 | if(priv->ieee80211->iw_mode == IW_MODE_ADHOC) |
| 4139 | { |
| 4140 | return false; |
| 4141 | } |
| 4142 | |
| 4143 | // |
| 4144 | // <RJ_NOTE> If we make HW to fill up the PwrMgt bit for us, |
| 4145 | // some AP will not response to our mgnt frames with PwrMgt bit set, |
| 4146 | // e.g. cannot associate the AP. |
| 4147 | // So I commented out it. 2005.02.16, by rcnjko. |
| 4148 | // |
| 4149 | // // Change device's power save mode. |
| 4150 | // Adapter->HalFunc.SetPSModeHandler( Adapter, rtPsMode ); |
| 4151 | |
| 4152 | // Update power save mode configured. |
| 4153 | //RT_TRACE(COMP_LPS,"%s(): set ieee->ps = %x\n",__FUNCTION__,rtPsMode); |
| 4154 | if(!priv->ps_force) { |
| 4155 | priv->ieee80211->ps = rtPsMode; |
| 4156 | } |
| 4157 | |
| 4158 | // Awake immediately |
| 4159 | if(priv->ieee80211->sta_sleep != 0 && rtPsMode == IEEE80211_PS_DISABLED) |
| 4160 | { |
| 4161 | unsigned long flags; |
| 4162 | |
| 4163 | //PlatformSetTimer(Adapter, &(pMgntInfo->AwakeTimer), 0); |
| 4164 | // Notify the AP we awke. |
| 4165 | rtl8192_hw_wakeup(dev); |
| 4166 | priv->ieee80211->sta_sleep = 0; |
| 4167 | |
| 4168 | spin_lock_irqsave(&(priv->ieee80211->mgmt_tx_lock), flags); |
| 4169 | printk("LPS leave: notify AP we are awaked ++++++++++ SendNullFunctionData\n"); |
| 4170 | ieee80211_sta_ps_send_null_frame(priv->ieee80211, 0); |
| 4171 | spin_unlock_irqrestore(&(priv->ieee80211->mgmt_tx_lock), flags); |
| 4172 | } |
| 4173 | |
| 4174 | return true; |
| 4175 | } |
| 4176 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 4177 | /* Enter the leisure power save mode. */ |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4178 | void LeisurePSEnter(struct net_device *dev) |
| 4179 | { |
| 4180 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4181 | PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl)); |
| 4182 | |
| 4183 | //RT_TRACE(COMP_PS, "LeisurePSEnter()...\n"); |
| 4184 | //RT_TRACE(COMP_PS, "pPSC->bLeisurePs = %d, ieee->ps = %d,pPSC->LpsIdleCount is %d,RT_CHECK_FOR_HANG_PERIOD is %d\n", |
| 4185 | // pPSC->bLeisurePs, priv->ieee80211->ps,pPSC->LpsIdleCount,RT_CHECK_FOR_HANG_PERIOD); |
| 4186 | |
| 4187 | if(!((priv->ieee80211->iw_mode == IW_MODE_INFRA) && |
| 4188 | (priv->ieee80211->state == IEEE80211_LINKED)) || |
| 4189 | (priv->ieee80211->iw_mode == IW_MODE_ADHOC) || |
| 4190 | (priv->ieee80211->iw_mode == IW_MODE_MASTER)) |
| 4191 | return; |
| 4192 | |
| 4193 | if (pPSC->bLeisurePs) |
| 4194 | { |
| 4195 | // Idle for a while if we connect to AP a while ago. |
| 4196 | if(pPSC->LpsIdleCount >= RT_CHECK_FOR_HANG_PERIOD) // 4 Sec |
| 4197 | { |
| 4198 | |
| 4199 | if(priv->ieee80211->ps == IEEE80211_PS_DISABLED) |
| 4200 | { |
| 4201 | |
| 4202 | //RT_TRACE(COMP_LPS, "LeisurePSEnter(): Enter 802.11 power save mode...\n"); |
| 4203 | MgntActSet_802_11_PowerSaveMode(dev, IEEE80211_PS_MBCAST|IEEE80211_PS_UNICAST); |
| 4204 | |
| 4205 | } |
| 4206 | } |
| 4207 | else |
| 4208 | pPSC->LpsIdleCount++; |
| 4209 | } |
| 4210 | } |
| 4211 | |
| 4212 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 4213 | /* Leave leisure power save mode. */ |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4214 | void LeisurePSLeave(struct net_device *dev) |
| 4215 | { |
| 4216 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4217 | PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl)); |
| 4218 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4219 | if (pPSC->bLeisurePs) |
| 4220 | { |
| 4221 | if(priv->ieee80211->ps != IEEE80211_PS_DISABLED) |
| 4222 | { |
| 4223 | // move to lps_wakecomplete() |
| 4224 | //RT_TRACE(COMP_LPS, "LeisurePSLeave(): Busy Traffic , Leave 802.11 power save..\n"); |
| 4225 | MgntActSet_802_11_PowerSaveMode(dev, IEEE80211_PS_DISABLED); |
| 4226 | |
| 4227 | } |
| 4228 | } |
| 4229 | } |
| 4230 | #endif |
| 4231 | |
| 4232 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 4233 | /* Enter the inactive power save mode. RF will be off */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4234 | void |
| 4235 | IPSEnter(struct net_device *dev) |
| 4236 | { |
| 4237 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4238 | PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl)); |
| 4239 | RT_RF_POWER_STATE rtState; |
| 4240 | |
| 4241 | if (pPSC->bInactivePs) |
| 4242 | { |
| 4243 | rtState = priv->ieee80211->eRFPowerState; |
| 4244 | // |
| 4245 | // Added by Bruce, 2007-12-25. |
| 4246 | // Do not enter IPS in the following conditions: |
| 4247 | // (1) RF is already OFF or Sleep |
| 4248 | // (2) bSwRfProcessing (indicates the IPS is still under going) |
| 4249 | // (3) Connectted (only disconnected can trigger IPS) |
| 4250 | // (4) IBSS (send Beacon) |
| 4251 | // (5) AP mode (send Beacon) |
| 4252 | // |
| 4253 | if (rtState == eRfOn && !pPSC->bSwRfProcessing |
| 4254 | && (priv->ieee80211->state != IEEE80211_LINKED) ) |
| 4255 | { |
| 4256 | RT_TRACE(COMP_RF,"IPSEnter(): Turn off RF.\n"); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4257 | //printk("IPSEnter(): Turn off RF.\n"); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4258 | pPSC->eInactivePowerState = eRfOff; |
| 4259 | // queue_work(priv->priv_wq,&(pPSC->InactivePsWorkItem)); |
| 4260 | InactivePsWorkItemCallback(dev); |
| 4261 | } |
| 4262 | } |
| 4263 | } |
| 4264 | |
| 4265 | // |
| 4266 | // Description: |
| 4267 | // Leave the inactive power save mode, RF will be on. |
| 4268 | // 2007.08.17, by shien chang. |
| 4269 | // |
| 4270 | void |
| 4271 | IPSLeave(struct net_device *dev) |
| 4272 | { |
| 4273 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4274 | PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl)); |
| 4275 | RT_RF_POWER_STATE rtState; |
| 4276 | |
| 4277 | if (pPSC->bInactivePs) |
| 4278 | { |
| 4279 | rtState = priv->ieee80211->eRFPowerState; |
| 4280 | if (rtState != eRfOn && !pPSC->bSwRfProcessing && priv->ieee80211->RfOffReason <= RF_CHANGE_BY_IPS) |
| 4281 | { |
| 4282 | RT_TRACE(COMP_POWER, "IPSLeave(): Turn on RF.\n"); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4283 | //printk("IPSLeave(): Turn on RF.\n"); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4284 | pPSC->eInactivePowerState = eRfOn; |
| 4285 | // queue_work(priv->priv_wq,&(pPSC->InactivePsWorkItem)); |
| 4286 | InactivePsWorkItemCallback(dev); |
| 4287 | } |
| 4288 | } |
| 4289 | } |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4290 | |
| 4291 | void IPSLeave_wq(void *data) |
| 4292 | { |
| 4293 | struct ieee80211_device *ieee = container_of(data,struct ieee80211_device,ips_leave_wq); |
| 4294 | struct net_device *dev = ieee->dev; |
| 4295 | |
| 4296 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 4297 | down(&priv->ieee80211->ips_sem); |
| 4298 | IPSLeave(dev); |
| 4299 | up(&priv->ieee80211->ips_sem); |
| 4300 | } |
| 4301 | |
| 4302 | void ieee80211_ips_leave_wq(struct net_device *dev) |
| 4303 | { |
| 4304 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 4305 | RT_RF_POWER_STATE rtState; |
| 4306 | rtState = priv->ieee80211->eRFPowerState; |
| 4307 | |
| 4308 | if(priv->ieee80211->PowerSaveControl.bInactivePs){ |
| 4309 | if(rtState == eRfOff){ |
| 4310 | if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_IPS) |
| 4311 | { |
| 4312 | RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__); |
| 4313 | return; |
| 4314 | } |
| 4315 | else{ |
| 4316 | printk("=========>%s(): IPSLeave\n",__FUNCTION__); |
| 4317 | queue_work(priv->ieee80211->wq,&priv->ieee80211->ips_leave_wq); |
| 4318 | } |
| 4319 | } |
| 4320 | } |
| 4321 | } |
| 4322 | //added by amy 090331 end |
| 4323 | void ieee80211_ips_leave(struct net_device *dev) |
| 4324 | { |
| 4325 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 4326 | down(&priv->ieee80211->ips_sem); |
| 4327 | IPSLeave(dev); |
| 4328 | up(&priv->ieee80211->ips_sem); |
| 4329 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4330 | #endif |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4331 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 4332 | static void rtl819x_update_rxcounts( |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4333 | struct r8192_priv *priv, |
| 4334 | u32* TotalRxBcnNum, |
| 4335 | u32* TotalRxDataNum |
| 4336 | ) |
| 4337 | { |
| 4338 | u16 SlotIndex; |
| 4339 | u8 i; |
| 4340 | |
| 4341 | *TotalRxBcnNum = 0; |
| 4342 | *TotalRxDataNum = 0; |
| 4343 | |
| 4344 | SlotIndex = (priv->ieee80211->LinkDetectInfo.SlotIndex++)%(priv->ieee80211->LinkDetectInfo.SlotNum); |
| 4345 | priv->ieee80211->LinkDetectInfo.RxBcnNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvBcnInPeriod; |
| 4346 | priv->ieee80211->LinkDetectInfo.RxDataNum[SlotIndex] = priv->ieee80211->LinkDetectInfo.NumRecvDataInPeriod; |
| 4347 | for( i=0; i<priv->ieee80211->LinkDetectInfo.SlotNum; i++ ){ |
| 4348 | *TotalRxBcnNum += priv->ieee80211->LinkDetectInfo.RxBcnNum[i]; |
| 4349 | *TotalRxDataNum += priv->ieee80211->LinkDetectInfo.RxDataNum[i]; |
| 4350 | } |
| 4351 | } |
| 4352 | |
| 4353 | |
Mike McCormack | 559fba5 | 2010-07-26 22:57:52 +0900 | [diff] [blame] | 4354 | static void rtl819x_watchdog_wqcallback(struct work_struct *work) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4355 | { |
| 4356 | struct delayed_work *dwork = container_of(work,struct delayed_work,work); |
| 4357 | struct r8192_priv *priv = container_of(dwork,struct r8192_priv,watch_dog_wq); |
| 4358 | struct net_device *dev = priv->ieee80211->dev; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4359 | struct ieee80211_device* ieee = priv->ieee80211; |
| 4360 | RESET_TYPE ResetType = RESET_TYPE_NORESET; |
| 4361 | static u8 check_reset_cnt=0; |
| 4362 | unsigned long flags; |
| 4363 | bool bBusyTraffic = false; |
| 4364 | static u8 last_time = 0; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4365 | bool bEnterPS = false; |
| 4366 | |
Mike McCormack | f500e25 | 2010-08-10 23:44:45 +0900 | [diff] [blame] | 4367 | if ((!priv->up) || priv->bHwRadioOff) |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4368 | return; |
| 4369 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4370 | if(!priv->up) |
| 4371 | return; |
| 4372 | hal_dm_watchdog(dev); |
| 4373 | #ifdef ENABLE_IPS |
| 4374 | // printk("watch_dog ENABLE_IPS\n"); |
| 4375 | if(ieee->actscanning == false){ |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4376 | //printk("%d,%d,%d,%d\n", ieee->eRFPowerState, ieee->is_set_key, ieee->proto_stoppping, ieee->wx_set_enc); |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 4377 | if((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state == IEEE80211_NOLINK) && |
| 4378 | (ieee->eRFPowerState == eRfOn)&&!ieee->is_set_key && |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4379 | (!ieee->proto_stoppping) && !ieee->wx_set_enc){ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4380 | if(ieee->PowerSaveControl.ReturnPoint == IPS_CALLBACK_NONE){ |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4381 | //printk("====================>haha:IPSEnter()\n"); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4382 | IPSEnter(dev); |
| 4383 | //ieee80211_stop_scan(priv->ieee80211); |
| 4384 | } |
| 4385 | } |
| 4386 | } |
| 4387 | #endif |
| 4388 | {//to get busy traffic condition |
| 4389 | if(ieee->state == IEEE80211_LINKED) |
| 4390 | { |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4391 | if( ieee->LinkDetectInfo.NumRxOkInPeriod> 100 || |
| 4392 | ieee->LinkDetectInfo.NumTxOkInPeriod> 100 ) { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4393 | bBusyTraffic = true; |
| 4394 | } |
| 4395 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4396 | #ifdef ENABLE_LPS |
| 4397 | //added by amy for Leisure PS |
| 4398 | if( ((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod + ieee->LinkDetectInfo.NumTxOkInPeriod) > 8 ) || |
| 4399 | (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2) ) |
| 4400 | { |
| 4401 | //printk("ieee->LinkDetectInfo.NumRxUnicastOkInPeriod is %d,ieee->LinkDetectInfo.NumTxOkInPeriod is %d\n", |
| 4402 | // ieee->LinkDetectInfo.NumRxUnicastOkInPeriod,ieee->LinkDetectInfo.NumTxOkInPeriod); |
| 4403 | bEnterPS= false; |
| 4404 | } |
| 4405 | else |
| 4406 | { |
| 4407 | bEnterPS= true; |
| 4408 | } |
| 4409 | |
| 4410 | //printk("***bEnterPS = %d\n", bEnterPS); |
| 4411 | // LeisurePS only work in infra mode. |
| 4412 | if(bEnterPS) |
| 4413 | { |
| 4414 | LeisurePSEnter(dev); |
| 4415 | } |
| 4416 | else |
| 4417 | { |
| 4418 | LeisurePSLeave(dev); |
| 4419 | } |
| 4420 | #endif |
| 4421 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4422 | } |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4423 | else |
| 4424 | { |
| 4425 | #ifdef ENABLE_LPS |
| 4426 | //RT_TRACE(COMP_LPS,"====>no link LPS leave\n"); |
| 4427 | LeisurePSLeave(dev); |
| 4428 | #endif |
| 4429 | } |
| 4430 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4431 | ieee->LinkDetectInfo.NumRxOkInPeriod = 0; |
| 4432 | ieee->LinkDetectInfo.NumTxOkInPeriod = 0; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4433 | ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4434 | ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic; |
| 4435 | } |
| 4436 | |
| 4437 | |
| 4438 | //added by amy for AP roaming |
| 4439 | if (1) |
| 4440 | { |
| 4441 | if(ieee->state == IEEE80211_LINKED && ieee->iw_mode == IW_MODE_INFRA) |
| 4442 | { |
| 4443 | u32 TotalRxBcnNum = 0; |
| 4444 | u32 TotalRxDataNum = 0; |
| 4445 | |
| 4446 | rtl819x_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum); |
| 4447 | if((TotalRxBcnNum+TotalRxDataNum) == 0) |
| 4448 | { |
| 4449 | if( ieee->eRFPowerState == eRfOff) |
| 4450 | RT_TRACE(COMP_ERR,"========>%s()\n",__FUNCTION__); |
| 4451 | printk("===>%s(): AP is power off,connect another one\n",__FUNCTION__); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4452 | // Dot11d_Reset(dev); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4453 | ieee->state = IEEE80211_ASSOCIATING; |
| 4454 | notify_wx_assoc_event(priv->ieee80211); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4455 | RemovePeerTS(priv->ieee80211,priv->ieee80211->current_network.bssid); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4456 | ieee->is_roaming = true; |
| 4457 | ieee->is_set_key = false; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4458 | ieee->link_change(dev); |
| 4459 | queue_work(ieee->wq, &ieee->associate_procedure_wq); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4460 | } |
| 4461 | } |
| 4462 | ieee->LinkDetectInfo.NumRecvBcnInPeriod=0; |
| 4463 | ieee->LinkDetectInfo.NumRecvDataInPeriod=0; |
| 4464 | |
| 4465 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4466 | //check if reset the driver |
| 4467 | spin_lock_irqsave(&priv->tx_lock,flags); |
| 4468 | if(check_reset_cnt++ >= 3 && !ieee->is_roaming && (last_time != 1)) |
| 4469 | { |
| 4470 | ResetType = rtl819x_ifcheck_resetornot(dev); |
| 4471 | check_reset_cnt = 3; |
| 4472 | //DbgPrint("Start to check silent reset\n"); |
| 4473 | } |
| 4474 | spin_unlock_irqrestore(&priv->tx_lock,flags); |
| 4475 | if(!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL) |
| 4476 | { |
| 4477 | priv->ResetProgress = RESET_TYPE_NORMAL; |
| 4478 | RT_TRACE(COMP_RESET,"%s(): NOMAL RESET\n",__FUNCTION__); |
| 4479 | return; |
| 4480 | } |
| 4481 | /* disable silent reset temply 2008.9.11*/ |
| 4482 | #if 1 |
| 4483 | if( ((priv->force_reset) || (!priv->bDisableNormalResetCheck && ResetType==RESET_TYPE_SILENT))) // This is control by OID set in Pomelo |
| 4484 | { |
| 4485 | last_time = 1; |
| 4486 | rtl819x_ifsilentreset(dev); |
| 4487 | } |
| 4488 | else |
| 4489 | last_time = 0; |
| 4490 | #endif |
| 4491 | priv->force_reset = false; |
| 4492 | priv->bForcedSilentReset = false; |
| 4493 | priv->bResetInProgress = false; |
| 4494 | RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n"); |
| 4495 | |
| 4496 | } |
| 4497 | |
| 4498 | void watch_dog_timer_callback(unsigned long data) |
| 4499 | { |
| 4500 | struct r8192_priv *priv = ieee80211_priv((struct net_device *) data); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4501 | queue_delayed_work(priv->priv_wq,&priv->watch_dog_wq,0); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4502 | mod_timer(&priv->watch_dog_timer, jiffies + MSECS(IEEE80211_WATCH_DOG_TIME)); |
| 4503 | |
| 4504 | } |
Mike McCormack | 5b3b1a7 | 2010-08-10 23:44:36 +0900 | [diff] [blame] | 4505 | |
| 4506 | static int _rtl8192_up(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4507 | { |
| 4508 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4509 | //int i; |
| 4510 | RT_STATUS init_status = RT_STATUS_SUCCESS; |
| 4511 | priv->up=1; |
| 4512 | priv->ieee80211->ieee_up=1; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4513 | priv->bdisable_nic = false; //YJ,add,091111 |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4514 | RT_TRACE(COMP_INIT, "Bringing up iface"); |
| 4515 | |
| 4516 | init_status = rtl8192_adapter_start(dev); |
| 4517 | if(init_status != RT_STATUS_SUCCESS) |
| 4518 | { |
| 4519 | RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__); |
| 4520 | return -1; |
| 4521 | } |
| 4522 | RT_TRACE(COMP_INIT, "start adapter finished\n"); |
| 4523 | #ifdef RTL8192E |
| 4524 | if(priv->ieee80211->eRFPowerState!=eRfOn) |
| 4525 | MgntActSet_RF_State(dev, eRfOn, priv->ieee80211->RfOffReason); |
| 4526 | #endif |
| 4527 | if(priv->ieee80211->state != IEEE80211_LINKED) |
| 4528 | ieee80211_softmac_start_protocol(priv->ieee80211); |
| 4529 | ieee80211_reset_queue(priv->ieee80211); |
| 4530 | watch_dog_timer_callback((unsigned long) dev); |
| 4531 | if(!netif_queue_stopped(dev)) |
| 4532 | netif_start_queue(dev); |
| 4533 | else |
| 4534 | netif_wake_queue(dev); |
| 4535 | |
| 4536 | return 0; |
| 4537 | } |
| 4538 | |
| 4539 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 4540 | static int rtl8192_open(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4541 | { |
| 4542 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4543 | int ret; |
| 4544 | |
| 4545 | down(&priv->wx_sem); |
| 4546 | ret = rtl8192_up(dev); |
| 4547 | up(&priv->wx_sem); |
| 4548 | return ret; |
| 4549 | |
| 4550 | } |
| 4551 | |
| 4552 | |
| 4553 | int rtl8192_up(struct net_device *dev) |
| 4554 | { |
| 4555 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4556 | |
| 4557 | if (priv->up == 1) return -1; |
| 4558 | |
| 4559 | return _rtl8192_up(dev); |
| 4560 | } |
| 4561 | |
| 4562 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 4563 | static int rtl8192_close(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4564 | { |
| 4565 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4566 | int ret; |
| 4567 | |
| 4568 | down(&priv->wx_sem); |
| 4569 | |
| 4570 | ret = rtl8192_down(dev); |
| 4571 | |
| 4572 | up(&priv->wx_sem); |
| 4573 | |
| 4574 | return ret; |
| 4575 | |
| 4576 | } |
| 4577 | |
| 4578 | int rtl8192_down(struct net_device *dev) |
| 4579 | { |
| 4580 | struct r8192_priv *priv = ieee80211_priv(dev); |
Mike McCormack | 16d74da | 2010-09-20 23:11:14 +0900 | [diff] [blame] | 4581 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4582 | if (priv->up == 0) return -1; |
| 4583 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4584 | #ifdef ENABLE_LPS |
| 4585 | //LZM for PS-Poll AID issue. 090429 |
| 4586 | if(priv->ieee80211->state == IEEE80211_LINKED) |
| 4587 | LeisurePSLeave(dev); |
| 4588 | #endif |
| 4589 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4590 | priv->up=0; |
| 4591 | priv->ieee80211->ieee_up = 0; |
| 4592 | RT_TRACE(COMP_DOWN, "==========>%s()\n", __FUNCTION__); |
| 4593 | /* FIXME */ |
| 4594 | if (!netif_queue_stopped(dev)) |
| 4595 | netif_stop_queue(dev); |
| 4596 | |
| 4597 | rtl8192_irq_disable(dev); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4598 | rtl8192_cancel_deferred_work(priv); |
| 4599 | deinit_hal_dm(dev); |
| 4600 | del_timer_sync(&priv->watch_dog_timer); |
| 4601 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4602 | ieee80211_softmac_stop_protocol(priv->ieee80211,true); |
| 4603 | |
| 4604 | rtl8192_halt_adapter(dev,false); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4605 | memset(&priv->ieee80211->current_network, 0 , offsetof(struct ieee80211_network, list)); |
| 4606 | |
| 4607 | RT_TRACE(COMP_DOWN, "<==========%s()\n", __FUNCTION__); |
| 4608 | |
Mike McCormack | 16d74da | 2010-09-20 23:11:14 +0900 | [diff] [blame] | 4609 | return 0; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | |
| 4613 | void rtl8192_commit(struct net_device *dev) |
| 4614 | { |
| 4615 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4616 | |
| 4617 | if (priv->up == 0) return ; |
| 4618 | |
| 4619 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4620 | ieee80211_softmac_stop_protocol(priv->ieee80211,true); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4621 | |
| 4622 | rtl8192_irq_disable(dev); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 4623 | rtl8192_halt_adapter(dev,true); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4624 | _rtl8192_up(dev); |
| 4625 | } |
| 4626 | |
Mike McCormack | 5b3b1a7 | 2010-08-10 23:44:36 +0900 | [diff] [blame] | 4627 | static void rtl8192_restart(struct work_struct *work) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4628 | { |
| 4629 | struct r8192_priv *priv = container_of(work, struct r8192_priv, reset_wq); |
| 4630 | struct net_device *dev = priv->ieee80211->dev; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4631 | |
| 4632 | down(&priv->wx_sem); |
| 4633 | |
| 4634 | rtl8192_commit(dev); |
| 4635 | |
| 4636 | up(&priv->wx_sem); |
| 4637 | } |
| 4638 | |
| 4639 | static void r8192_set_multicast(struct net_device *dev) |
| 4640 | { |
| 4641 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4642 | short promisc; |
| 4643 | |
| 4644 | //down(&priv->wx_sem); |
| 4645 | |
| 4646 | /* FIXME FIXME */ |
| 4647 | |
| 4648 | promisc = (dev->flags & IFF_PROMISC) ? 1:0; |
| 4649 | |
| 4650 | if (promisc != priv->promisc) { |
| 4651 | ; |
| 4652 | // rtl8192_commit(dev); |
| 4653 | } |
| 4654 | |
| 4655 | priv->promisc = promisc; |
| 4656 | |
| 4657 | //schedule_work(&priv->reset_wq); |
| 4658 | //up(&priv->wx_sem); |
| 4659 | } |
| 4660 | |
| 4661 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 4662 | static int r8192_set_mac_adr(struct net_device *dev, void *mac) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4663 | { |
| 4664 | struct r8192_priv *priv = ieee80211_priv(dev); |
| 4665 | struct sockaddr *addr = mac; |
| 4666 | |
| 4667 | down(&priv->wx_sem); |
| 4668 | |
| 4669 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); |
| 4670 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4671 | schedule_work(&priv->reset_wq); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4672 | up(&priv->wx_sem); |
| 4673 | |
| 4674 | return 0; |
| 4675 | } |
| 4676 | |
| 4677 | /* based on ipw2200 driver */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 4678 | static int rtl8192_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4679 | { |
| 4680 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 4681 | struct iwreq *wrq = (struct iwreq *)rq; |
| 4682 | int ret=-1; |
| 4683 | struct ieee80211_device *ieee = priv->ieee80211; |
| 4684 | u32 key[4]; |
| 4685 | u8 broadcast_addr[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; |
| 4686 | struct iw_point *p = &wrq->u.data; |
| 4687 | struct ieee_param *ipw = NULL;//(struct ieee_param *)wrq->u.data.pointer; |
| 4688 | |
| 4689 | down(&priv->wx_sem); |
| 4690 | |
| 4691 | |
| 4692 | if (p->length < sizeof(struct ieee_param) || !p->pointer){ |
| 4693 | ret = -EINVAL; |
| 4694 | goto out; |
| 4695 | } |
| 4696 | |
Julia Lawall | 3241487 | 2010-05-11 20:26:57 +0200 | [diff] [blame] | 4697 | ipw = kmalloc(p->length, GFP_KERNEL); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4698 | if (ipw == NULL){ |
| 4699 | ret = -ENOMEM; |
| 4700 | goto out; |
| 4701 | } |
| 4702 | if (copy_from_user(ipw, p->pointer, p->length)) { |
| 4703 | kfree(ipw); |
| 4704 | ret = -EFAULT; |
| 4705 | goto out; |
| 4706 | } |
| 4707 | |
| 4708 | switch (cmd) { |
| 4709 | case RTL_IOCTL_WPA_SUPPLICANT: |
| 4710 | //parse here for HW security |
| 4711 | if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) |
| 4712 | { |
| 4713 | if (ipw->u.crypt.set_tx) |
| 4714 | { |
| 4715 | if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) |
| 4716 | ieee->pairwise_key_type = KEY_TYPE_CCMP; |
| 4717 | else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) |
| 4718 | ieee->pairwise_key_type = KEY_TYPE_TKIP; |
| 4719 | else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) |
| 4720 | { |
| 4721 | if (ipw->u.crypt.key_len == 13) |
| 4722 | ieee->pairwise_key_type = KEY_TYPE_WEP104; |
| 4723 | else if (ipw->u.crypt.key_len == 5) |
| 4724 | ieee->pairwise_key_type = KEY_TYPE_WEP40; |
| 4725 | } |
| 4726 | else |
| 4727 | ieee->pairwise_key_type = KEY_TYPE_NA; |
| 4728 | |
| 4729 | if (ieee->pairwise_key_type) |
| 4730 | { |
| 4731 | memcpy((u8*)key, ipw->u.crypt.key, 16); |
| 4732 | EnableHWSecurityConfig8192(dev); |
| 4733 | //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! |
| 4734 | //added by WB. |
| 4735 | setKey(dev, 4, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key); |
| 4736 | if (ieee->auth_mode != 2) //LEAP WEP will never set this. |
| 4737 | setKey(dev, ipw->u.crypt.idx, ipw->u.crypt.idx, ieee->pairwise_key_type, (u8*)ieee->ap_mac_addr, 0, key); |
| 4738 | } |
| 4739 | if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) && ieee->pHTInfo->bCurrentHTSupport){ |
| 4740 | write_nic_byte(dev, 0x173, 1); //fix aes bug |
| 4741 | } |
| 4742 | |
| 4743 | } |
| 4744 | else //if (ipw->u.crypt.idx) //group key use idx > 0 |
| 4745 | { |
| 4746 | memcpy((u8*)key, ipw->u.crypt.key, 16); |
| 4747 | if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) |
| 4748 | ieee->group_key_type= KEY_TYPE_CCMP; |
| 4749 | else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) |
| 4750 | ieee->group_key_type = KEY_TYPE_TKIP; |
| 4751 | else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) |
| 4752 | { |
| 4753 | if (ipw->u.crypt.key_len == 13) |
| 4754 | ieee->group_key_type = KEY_TYPE_WEP104; |
| 4755 | else if (ipw->u.crypt.key_len == 5) |
| 4756 | ieee->group_key_type = KEY_TYPE_WEP40; |
| 4757 | } |
| 4758 | else |
| 4759 | ieee->group_key_type = KEY_TYPE_NA; |
| 4760 | |
| 4761 | if (ieee->group_key_type) |
| 4762 | { |
| 4763 | setKey( dev, |
| 4764 | ipw->u.crypt.idx, |
| 4765 | ipw->u.crypt.idx, //KeyIndex |
| 4766 | ieee->group_key_type, //KeyType |
| 4767 | broadcast_addr, //MacAddr |
| 4768 | 0, //DefaultKey |
| 4769 | key); //KeyContent |
| 4770 | } |
| 4771 | } |
| 4772 | } |
| 4773 | #ifdef JOHN_DEBUG |
| 4774 | //john's test 0711 |
| 4775 | { |
| 4776 | int i; |
| 4777 | printk("@@ wrq->u pointer = "); |
| 4778 | for(i=0;i<wrq->u.data.length;i++){ |
| 4779 | if(i%10==0) printk("\n"); |
| 4780 | printk( "%8x|", ((u32*)wrq->u.data.pointer)[i] ); |
| 4781 | } |
| 4782 | printk("\n"); |
| 4783 | } |
| 4784 | #endif /*JOHN_DEBUG*/ |
| 4785 | ret = ieee80211_wpa_supplicant_ioctl(priv->ieee80211, &wrq->u.data); |
| 4786 | break; |
| 4787 | |
| 4788 | default: |
| 4789 | ret = -EOPNOTSUPP; |
| 4790 | break; |
| 4791 | } |
| 4792 | |
| 4793 | kfree(ipw); |
| 4794 | out: |
| 4795 | up(&priv->wx_sem); |
| 4796 | |
| 4797 | return ret; |
| 4798 | } |
| 4799 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 4800 | static u8 HwRateToMRate90(bool bIsHT, u8 rate) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4801 | { |
| 4802 | u8 ret_rate = 0x02; |
| 4803 | |
| 4804 | if(!bIsHT) { |
| 4805 | switch(rate) { |
| 4806 | case DESC90_RATE1M: ret_rate = MGN_1M; break; |
| 4807 | case DESC90_RATE2M: ret_rate = MGN_2M; break; |
| 4808 | case DESC90_RATE5_5M: ret_rate = MGN_5_5M; break; |
| 4809 | case DESC90_RATE11M: ret_rate = MGN_11M; break; |
| 4810 | case DESC90_RATE6M: ret_rate = MGN_6M; break; |
| 4811 | case DESC90_RATE9M: ret_rate = MGN_9M; break; |
| 4812 | case DESC90_RATE12M: ret_rate = MGN_12M; break; |
| 4813 | case DESC90_RATE18M: ret_rate = MGN_18M; break; |
| 4814 | case DESC90_RATE24M: ret_rate = MGN_24M; break; |
| 4815 | case DESC90_RATE36M: ret_rate = MGN_36M; break; |
| 4816 | case DESC90_RATE48M: ret_rate = MGN_48M; break; |
| 4817 | case DESC90_RATE54M: ret_rate = MGN_54M; break; |
| 4818 | |
| 4819 | default: |
| 4820 | RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n", rate, bIsHT); |
| 4821 | break; |
| 4822 | } |
| 4823 | |
| 4824 | } else { |
| 4825 | switch(rate) { |
| 4826 | case DESC90_RATEMCS0: ret_rate = MGN_MCS0; break; |
| 4827 | case DESC90_RATEMCS1: ret_rate = MGN_MCS1; break; |
| 4828 | case DESC90_RATEMCS2: ret_rate = MGN_MCS2; break; |
| 4829 | case DESC90_RATEMCS3: ret_rate = MGN_MCS3; break; |
| 4830 | case DESC90_RATEMCS4: ret_rate = MGN_MCS4; break; |
| 4831 | case DESC90_RATEMCS5: ret_rate = MGN_MCS5; break; |
| 4832 | case DESC90_RATEMCS6: ret_rate = MGN_MCS6; break; |
| 4833 | case DESC90_RATEMCS7: ret_rate = MGN_MCS7; break; |
| 4834 | case DESC90_RATEMCS8: ret_rate = MGN_MCS8; break; |
| 4835 | case DESC90_RATEMCS9: ret_rate = MGN_MCS9; break; |
| 4836 | case DESC90_RATEMCS10: ret_rate = MGN_MCS10; break; |
| 4837 | case DESC90_RATEMCS11: ret_rate = MGN_MCS11; break; |
| 4838 | case DESC90_RATEMCS12: ret_rate = MGN_MCS12; break; |
| 4839 | case DESC90_RATEMCS13: ret_rate = MGN_MCS13; break; |
| 4840 | case DESC90_RATEMCS14: ret_rate = MGN_MCS14; break; |
| 4841 | case DESC90_RATEMCS15: ret_rate = MGN_MCS15; break; |
| 4842 | case DESC90_RATEMCS32: ret_rate = (0x80|0x20); break; |
| 4843 | |
| 4844 | default: |
| 4845 | RT_TRACE(COMP_RECV, "HwRateToMRate90(): Non supported Rate [%x], bIsHT = %d!!!\n",rate, bIsHT); |
| 4846 | break; |
| 4847 | } |
| 4848 | } |
| 4849 | |
| 4850 | return ret_rate; |
| 4851 | } |
| 4852 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 4853 | /* Record the TSF time stamp when receiving a packet */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 4854 | static void UpdateRxPktTimeStamp8190 (struct net_device *dev, struct ieee80211_rx_stats *stats) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4855 | { |
| 4856 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 4857 | |
| 4858 | if(stats->bIsAMPDU && !stats->bFirstMPDU) { |
| 4859 | stats->mac_time[0] = priv->LastRxDescTSFLow; |
| 4860 | stats->mac_time[1] = priv->LastRxDescTSFHigh; |
| 4861 | } else { |
| 4862 | priv->LastRxDescTSFLow = stats->mac_time[0]; |
| 4863 | priv->LastRxDescTSFHigh = stats->mac_time[1]; |
| 4864 | } |
| 4865 | } |
| 4866 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 4867 | static long rtl819x_translate_todbm(u8 signal_strength_index)// 0-100 index. |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4868 | { |
| 4869 | long signal_power; // in dBm. |
| 4870 | |
| 4871 | // Translate to dBm (x=0.5y-95). |
| 4872 | signal_power = (long)((signal_strength_index + 1) >> 1); |
| 4873 | signal_power -= 95; |
| 4874 | |
| 4875 | return signal_power; |
| 4876 | } |
| 4877 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 4878 | /* |
| 4879 | * Update Rx signal related information in the packet reeived |
| 4880 | * to RxStats. User application can query RxStats to realize |
| 4881 | * current Rx signal status. |
| 4882 | * |
| 4883 | * In normal operation, user only care about the information of the BSS |
| 4884 | * and we shall invoke this function if the packet received is from the BSS. |
| 4885 | */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 4886 | static void |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4887 | rtl819x_update_rxsignalstatistics8190pci( |
| 4888 | struct r8192_priv * priv, |
| 4889 | struct ieee80211_rx_stats * pprevious_stats |
| 4890 | ) |
| 4891 | { |
| 4892 | int weighting = 0; |
| 4893 | |
| 4894 | //2 <ToDo> Update Rx Statistics (such as signal strength and signal quality). |
| 4895 | |
| 4896 | // Initila state |
| 4897 | if(priv->stats.recv_signal_power == 0) |
| 4898 | priv->stats.recv_signal_power = pprevious_stats->RecvSignalPower; |
| 4899 | |
| 4900 | // To avoid the past result restricting the statistics sensitivity, weight the current power (5/6) to speed up the |
| 4901 | // reaction of smoothed Signal Power. |
| 4902 | if(pprevious_stats->RecvSignalPower > priv->stats.recv_signal_power) |
| 4903 | weighting = 5; |
| 4904 | else if(pprevious_stats->RecvSignalPower < priv->stats.recv_signal_power) |
| 4905 | weighting = (-5); |
| 4906 | // |
| 4907 | // We need more correct power of received packets and the "SignalStrength" of RxStats have been beautified or translated, |
| 4908 | // so we record the correct power in Dbm here. By Bruce, 2008-03-07. |
| 4909 | // |
| 4910 | priv->stats.recv_signal_power = (priv->stats.recv_signal_power * 5 + pprevious_stats->RecvSignalPower + weighting) / 6; |
| 4911 | } |
| 4912 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 4913 | static void |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4914 | rtl8190_process_cck_rxpathsel( |
| 4915 | struct r8192_priv * priv, |
| 4916 | struct ieee80211_rx_stats * pprevious_stats |
| 4917 | ) |
| 4918 | { |
| 4919 | #ifdef RTL8190P //Only 90P 2T4R need to check |
| 4920 | char last_cck_adc_pwdb[4]={0,0,0,0}; |
| 4921 | u8 i; |
| 4922 | //cosa add for Rx path selection |
| 4923 | if(priv->rf_type == RF_2T4R && DM_RxPathSelTable.Enable) |
| 4924 | { |
| 4925 | if(pprevious_stats->bIsCCK && |
| 4926 | (pprevious_stats->bPacketToSelf ||pprevious_stats->bPacketBeacon)) |
| 4927 | { |
| 4928 | /* record the cck adc_pwdb to the sliding window. */ |
| 4929 | if(priv->stats.cck_adc_pwdb.TotalNum++ >= PHY_RSSI_SLID_WIN_MAX) |
| 4930 | { |
| 4931 | priv->stats.cck_adc_pwdb.TotalNum = PHY_RSSI_SLID_WIN_MAX; |
| 4932 | for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++) |
| 4933 | { |
| 4934 | last_cck_adc_pwdb[i] = priv->stats.cck_adc_pwdb.elements[i][priv->stats.cck_adc_pwdb.index]; |
| 4935 | priv->stats.cck_adc_pwdb.TotalVal[i] -= last_cck_adc_pwdb[i]; |
| 4936 | } |
| 4937 | } |
| 4938 | for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++) |
| 4939 | { |
| 4940 | priv->stats.cck_adc_pwdb.TotalVal[i] += pprevious_stats->cck_adc_pwdb[i]; |
| 4941 | priv->stats.cck_adc_pwdb.elements[i][priv->stats.cck_adc_pwdb.index] = pprevious_stats->cck_adc_pwdb[i]; |
| 4942 | } |
| 4943 | priv->stats.cck_adc_pwdb.index++; |
| 4944 | if(priv->stats.cck_adc_pwdb.index >= PHY_RSSI_SLID_WIN_MAX) |
| 4945 | priv->stats.cck_adc_pwdb.index = 0; |
| 4946 | |
| 4947 | for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++) |
| 4948 | { |
| 4949 | DM_RxPathSelTable.cck_pwdb_sta[i] = priv->stats.cck_adc_pwdb.TotalVal[i]/priv->stats.cck_adc_pwdb.TotalNum; |
| 4950 | } |
| 4951 | |
| 4952 | for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++) |
| 4953 | { |
| 4954 | if(pprevious_stats->cck_adc_pwdb[i] > (char)priv->undecorated_smoothed_cck_adc_pwdb[i]) |
| 4955 | { |
| 4956 | priv->undecorated_smoothed_cck_adc_pwdb[i] = |
| 4957 | ( (priv->undecorated_smoothed_cck_adc_pwdb[i]*(Rx_Smooth_Factor-1)) + |
| 4958 | (pprevious_stats->cck_adc_pwdb[i])) /(Rx_Smooth_Factor); |
| 4959 | priv->undecorated_smoothed_cck_adc_pwdb[i] = priv->undecorated_smoothed_cck_adc_pwdb[i] + 1; |
| 4960 | } |
| 4961 | else |
| 4962 | { |
| 4963 | priv->undecorated_smoothed_cck_adc_pwdb[i] = |
| 4964 | ( (priv->undecorated_smoothed_cck_adc_pwdb[i]*(Rx_Smooth_Factor-1)) + |
| 4965 | (pprevious_stats->cck_adc_pwdb[i])) /(Rx_Smooth_Factor); |
| 4966 | } |
| 4967 | } |
| 4968 | } |
| 4969 | } |
| 4970 | #endif |
| 4971 | } |
| 4972 | |
| 4973 | |
| 4974 | /* 2008/01/22 MH We can not delcare RSSI/EVM total value of sliding window to |
| 4975 | be a local static. Otherwise, it may increase when we return from S3/S4. The |
| 4976 | value will be kept in memory or disk. We must delcare the value in adapter |
| 4977 | and it will be reinitialized when return from S3/S4. */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 4978 | static void rtl8192_process_phyinfo(struct r8192_priv * priv, u8* buffer,struct ieee80211_rx_stats * pprevious_stats, struct ieee80211_rx_stats * pcurrent_stats) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 4979 | { |
| 4980 | bool bcheck = false; |
| 4981 | u8 rfpath; |
| 4982 | u32 nspatial_stream, tmp_val; |
| 4983 | //u8 i; |
| 4984 | static u32 slide_rssi_index=0, slide_rssi_statistics=0; |
| 4985 | static u32 slide_evm_index=0, slide_evm_statistics=0; |
| 4986 | static u32 last_rssi=0, last_evm=0; |
| 4987 | //cosa add for rx path selection |
| 4988 | // static long slide_cck_adc_pwdb_index=0, slide_cck_adc_pwdb_statistics=0; |
| 4989 | // static char last_cck_adc_pwdb[4]={0,0,0,0}; |
| 4990 | //cosa add for beacon rssi smoothing |
| 4991 | static u32 slide_beacon_adc_pwdb_index=0, slide_beacon_adc_pwdb_statistics=0; |
| 4992 | static u32 last_beacon_adc_pwdb=0; |
| 4993 | |
| 4994 | struct ieee80211_hdr_3addr *hdr; |
| 4995 | u16 sc ; |
| 4996 | unsigned int frag,seq; |
| 4997 | hdr = (struct ieee80211_hdr_3addr *)buffer; |
| 4998 | sc = le16_to_cpu(hdr->seq_ctl); |
| 4999 | frag = WLAN_GET_SEQ_FRAG(sc); |
| 5000 | seq = WLAN_GET_SEQ_SEQ(sc); |
| 5001 | //cosa add 04292008 to record the sequence number |
| 5002 | pcurrent_stats->Seq_Num = seq; |
| 5003 | // |
| 5004 | // Check whether we should take the previous packet into accounting |
| 5005 | // |
| 5006 | if(!pprevious_stats->bIsAMPDU) |
| 5007 | { |
| 5008 | // if previous packet is not aggregated packet |
| 5009 | bcheck = true; |
| 5010 | }else |
| 5011 | { |
| 5012 | //remve for that we don't use AMPDU to calculate PWDB,because the reported PWDB of some AP is fault. |
| 5013 | #if 0 |
| 5014 | // if previous packet is aggregated packet, and current packet |
| 5015 | // (1) is not AMPDU |
| 5016 | // (2) is the first packet of one AMPDU |
| 5017 | // that means the previous packet is the last one aggregated packet |
| 5018 | if( !pcurrent_stats->bIsAMPDU || pcurrent_stats->bFirstMPDU) |
| 5019 | bcheck = true; |
| 5020 | #endif |
| 5021 | } |
| 5022 | |
| 5023 | if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX) |
| 5024 | { |
| 5025 | slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX; |
| 5026 | last_rssi = priv->stats.slide_signal_strength[slide_rssi_index]; |
| 5027 | priv->stats.slide_rssi_total -= last_rssi; |
| 5028 | } |
| 5029 | priv->stats.slide_rssi_total += pprevious_stats->SignalStrength; |
| 5030 | |
| 5031 | priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength; |
| 5032 | if(slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX) |
| 5033 | slide_rssi_index = 0; |
| 5034 | |
| 5035 | // <1> Showed on UI for user, in dbm |
| 5036 | tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics; |
| 5037 | priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val); |
| 5038 | pcurrent_stats->rssi = priv->stats.signal_strength; |
| 5039 | // |
| 5040 | // If the previous packet does not match the criteria, neglect it |
| 5041 | // |
| 5042 | if(!pprevious_stats->bPacketMatchBSSID) |
| 5043 | { |
| 5044 | if(!pprevious_stats->bToSelfBA) |
| 5045 | return; |
| 5046 | } |
| 5047 | |
| 5048 | if(!bcheck) |
| 5049 | return; |
| 5050 | |
| 5051 | rtl8190_process_cck_rxpathsel(priv,pprevious_stats); |
| 5052 | |
| 5053 | // |
| 5054 | // Check RSSI |
| 5055 | // |
| 5056 | priv->stats.num_process_phyinfo++; |
| 5057 | #if 0 |
| 5058 | /* record the general signal strength to the sliding window. */ |
| 5059 | if(slide_rssi_statistics++ >= PHY_RSSI_SLID_WIN_MAX) |
| 5060 | { |
| 5061 | slide_rssi_statistics = PHY_RSSI_SLID_WIN_MAX; |
| 5062 | last_rssi = priv->stats.slide_signal_strength[slide_rssi_index]; |
| 5063 | priv->stats.slide_rssi_total -= last_rssi; |
| 5064 | } |
| 5065 | priv->stats.slide_rssi_total += pprevious_stats->SignalStrength; |
| 5066 | |
| 5067 | priv->stats.slide_signal_strength[slide_rssi_index++] = pprevious_stats->SignalStrength; |
| 5068 | if(slide_rssi_index >= PHY_RSSI_SLID_WIN_MAX) |
| 5069 | slide_rssi_index = 0; |
| 5070 | |
| 5071 | // <1> Showed on UI for user, in dbm |
| 5072 | tmp_val = priv->stats.slide_rssi_total/slide_rssi_statistics; |
| 5073 | priv->stats.signal_strength = rtl819x_translate_todbm((u8)tmp_val); |
| 5074 | |
| 5075 | #endif |
| 5076 | // <2> Showed on UI for engineering |
| 5077 | // hardware does not provide rssi information for each rf path in CCK |
| 5078 | if(!pprevious_stats->bIsCCK && pprevious_stats->bPacketToSelf) |
| 5079 | { |
| 5080 | for (rfpath = RF90_PATH_A; rfpath < RF90_PATH_C; rfpath++) |
| 5081 | { |
| 5082 | if (!rtl8192_phy_CheckIsLegalRFPath(priv->ieee80211->dev, rfpath)) |
| 5083 | continue; |
| 5084 | RT_TRACE(COMP_DBG,"Jacken -> pPreviousstats->RxMIMOSignalStrength[rfpath] = %d \n" ,pprevious_stats->RxMIMOSignalStrength[rfpath] ); |
| 5085 | //Fixed by Jacken 2008-03-20 |
| 5086 | if(priv->stats.rx_rssi_percentage[rfpath] == 0) |
| 5087 | { |
| 5088 | priv->stats.rx_rssi_percentage[rfpath] = pprevious_stats->RxMIMOSignalStrength[rfpath]; |
| 5089 | //DbgPrint("MIMO RSSI initialize \n"); |
| 5090 | } |
| 5091 | if(pprevious_stats->RxMIMOSignalStrength[rfpath] > priv->stats.rx_rssi_percentage[rfpath]) |
| 5092 | { |
| 5093 | priv->stats.rx_rssi_percentage[rfpath] = |
| 5094 | ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) + |
| 5095 | (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor); |
| 5096 | priv->stats.rx_rssi_percentage[rfpath] = priv->stats.rx_rssi_percentage[rfpath] + 1; |
| 5097 | } |
| 5098 | else |
| 5099 | { |
| 5100 | priv->stats.rx_rssi_percentage[rfpath] = |
| 5101 | ( (priv->stats.rx_rssi_percentage[rfpath]*(Rx_Smooth_Factor-1)) + |
| 5102 | (pprevious_stats->RxMIMOSignalStrength[rfpath])) /(Rx_Smooth_Factor); |
| 5103 | } |
| 5104 | RT_TRACE(COMP_DBG,"Jacken -> priv->RxStats.RxRSSIPercentage[rfPath] = %d \n" ,priv->stats.rx_rssi_percentage[rfpath] ); |
| 5105 | } |
| 5106 | } |
| 5107 | |
| 5108 | |
| 5109 | // |
| 5110 | // Check PWDB. |
| 5111 | // |
| 5112 | //cosa add for beacon rssi smoothing by average. |
| 5113 | if(pprevious_stats->bPacketBeacon) |
| 5114 | { |
| 5115 | /* record the beacon pwdb to the sliding window. */ |
| 5116 | if(slide_beacon_adc_pwdb_statistics++ >= PHY_Beacon_RSSI_SLID_WIN_MAX) |
| 5117 | { |
| 5118 | slide_beacon_adc_pwdb_statistics = PHY_Beacon_RSSI_SLID_WIN_MAX; |
| 5119 | last_beacon_adc_pwdb = priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index]; |
| 5120 | priv->stats.Slide_Beacon_Total -= last_beacon_adc_pwdb; |
| 5121 | //DbgPrint("slide_beacon_adc_pwdb_index = %d, last_beacon_adc_pwdb = %d, Adapter->RxStats.Slide_Beacon_Total = %d\n", |
| 5122 | // slide_beacon_adc_pwdb_index, last_beacon_adc_pwdb, Adapter->RxStats.Slide_Beacon_Total); |
| 5123 | } |
| 5124 | priv->stats.Slide_Beacon_Total += pprevious_stats->RxPWDBAll; |
| 5125 | priv->stats.Slide_Beacon_pwdb[slide_beacon_adc_pwdb_index] = pprevious_stats->RxPWDBAll; |
| 5126 | //DbgPrint("slide_beacon_adc_pwdb_index = %d, pPreviousRfd->Status.RxPWDBAll = %d\n", slide_beacon_adc_pwdb_index, pPreviousRfd->Status.RxPWDBAll); |
| 5127 | slide_beacon_adc_pwdb_index++; |
| 5128 | if(slide_beacon_adc_pwdb_index >= PHY_Beacon_RSSI_SLID_WIN_MAX) |
| 5129 | slide_beacon_adc_pwdb_index = 0; |
| 5130 | pprevious_stats->RxPWDBAll = priv->stats.Slide_Beacon_Total/slide_beacon_adc_pwdb_statistics; |
| 5131 | if(pprevious_stats->RxPWDBAll >= 3) |
| 5132 | pprevious_stats->RxPWDBAll -= 3; |
| 5133 | } |
| 5134 | |
| 5135 | RT_TRACE(COMP_RXDESC, "Smooth %s PWDB = %d\n", |
| 5136 | pprevious_stats->bIsCCK? "CCK": "OFDM", |
| 5137 | pprevious_stats->RxPWDBAll); |
| 5138 | |
| 5139 | if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) |
| 5140 | { |
| 5141 | if(priv->undecorated_smoothed_pwdb < 0) // initialize |
| 5142 | { |
| 5143 | priv->undecorated_smoothed_pwdb = pprevious_stats->RxPWDBAll; |
| 5144 | //DbgPrint("First pwdb initialize \n"); |
| 5145 | } |
| 5146 | #if 1 |
| 5147 | if(pprevious_stats->RxPWDBAll > (u32)priv->undecorated_smoothed_pwdb) |
| 5148 | { |
| 5149 | priv->undecorated_smoothed_pwdb = |
| 5150 | ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) + |
| 5151 | (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor); |
| 5152 | priv->undecorated_smoothed_pwdb = priv->undecorated_smoothed_pwdb + 1; |
| 5153 | } |
| 5154 | else |
| 5155 | { |
| 5156 | priv->undecorated_smoothed_pwdb = |
| 5157 | ( ((priv->undecorated_smoothed_pwdb)*(Rx_Smooth_Factor-1)) + |
| 5158 | (pprevious_stats->RxPWDBAll)) /(Rx_Smooth_Factor); |
| 5159 | } |
| 5160 | #else |
| 5161 | //Fixed by Jacken 2008-03-20 |
| 5162 | if(pPreviousRfd->Status.RxPWDBAll > (u32)pHalData->UndecoratedSmoothedPWDB) |
| 5163 | { |
| 5164 | pHalData->UndecoratedSmoothedPWDB = |
| 5165 | ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6; |
| 5166 | pHalData->UndecoratedSmoothedPWDB = pHalData->UndecoratedSmoothedPWDB + 1; |
| 5167 | } |
| 5168 | else |
| 5169 | { |
| 5170 | pHalData->UndecoratedSmoothedPWDB = |
| 5171 | ( ((pHalData->UndecoratedSmoothedPWDB)* 5) + (pPreviousRfd->Status.RxPWDBAll)) / 6; |
| 5172 | } |
| 5173 | #endif |
| 5174 | rtl819x_update_rxsignalstatistics8190pci(priv,pprevious_stats); |
| 5175 | } |
| 5176 | |
| 5177 | // |
| 5178 | // Check EVM |
| 5179 | // |
| 5180 | /* record the general EVM to the sliding window. */ |
| 5181 | if(pprevious_stats->SignalQuality == 0) |
| 5182 | { |
| 5183 | } |
| 5184 | else |
| 5185 | { |
| 5186 | if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA){ |
| 5187 | if(slide_evm_statistics++ >= PHY_RSSI_SLID_WIN_MAX){ |
| 5188 | slide_evm_statistics = PHY_RSSI_SLID_WIN_MAX; |
| 5189 | last_evm = priv->stats.slide_evm[slide_evm_index]; |
| 5190 | priv->stats.slide_evm_total -= last_evm; |
| 5191 | } |
| 5192 | |
| 5193 | priv->stats.slide_evm_total += pprevious_stats->SignalQuality; |
| 5194 | |
| 5195 | priv->stats.slide_evm[slide_evm_index++] = pprevious_stats->SignalQuality; |
| 5196 | if(slide_evm_index >= PHY_RSSI_SLID_WIN_MAX) |
| 5197 | slide_evm_index = 0; |
| 5198 | |
| 5199 | // <1> Showed on UI for user, in percentage. |
| 5200 | tmp_val = priv->stats.slide_evm_total/slide_evm_statistics; |
| 5201 | priv->stats.signal_quality = tmp_val; |
| 5202 | //cosa add 10/11/2007, Showed on UI for user in Windows Vista, for Link quality. |
| 5203 | priv->stats.last_signal_strength_inpercent = tmp_val; |
| 5204 | } |
| 5205 | |
| 5206 | // <2> Showed on UI for engineering |
| 5207 | if(pprevious_stats->bPacketToSelf || pprevious_stats->bPacketBeacon || pprevious_stats->bToSelfBA) |
| 5208 | { |
| 5209 | for(nspatial_stream = 0; nspatial_stream<2 ; nspatial_stream++) // 2 spatial stream |
| 5210 | { |
| 5211 | if(pprevious_stats->RxMIMOSignalQuality[nspatial_stream] != -1) |
| 5212 | { |
| 5213 | if(priv->stats.rx_evm_percentage[nspatial_stream] == 0) // initialize |
| 5214 | { |
| 5215 | priv->stats.rx_evm_percentage[nspatial_stream] = pprevious_stats->RxMIMOSignalQuality[nspatial_stream]; |
| 5216 | } |
| 5217 | priv->stats.rx_evm_percentage[nspatial_stream] = |
| 5218 | ( (priv->stats.rx_evm_percentage[nspatial_stream]* (Rx_Smooth_Factor-1)) + |
| 5219 | (pprevious_stats->RxMIMOSignalQuality[nspatial_stream]* 1)) / (Rx_Smooth_Factor); |
| 5220 | } |
| 5221 | } |
| 5222 | } |
| 5223 | } |
| 5224 | |
| 5225 | } |
| 5226 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5227 | static u8 rtl819x_query_rxpwrpercentage( |
| 5228 | char antpower |
| 5229 | ) |
| 5230 | { |
| 5231 | if ((antpower <= -100) || (antpower >= 20)) |
| 5232 | { |
| 5233 | return 0; |
| 5234 | } |
| 5235 | else if (antpower >= 0) |
| 5236 | { |
| 5237 | return 100; |
| 5238 | } |
| 5239 | else |
| 5240 | { |
| 5241 | return (100+antpower); |
| 5242 | } |
| 5243 | |
Mike McCormack | d5abdf7 | 2010-09-08 22:03:59 +0900 | [diff] [blame] | 5244 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5245 | |
| 5246 | static u8 |
| 5247 | rtl819x_evm_dbtopercentage( |
| 5248 | char value |
| 5249 | ) |
| 5250 | { |
| 5251 | char ret_val; |
| 5252 | |
| 5253 | ret_val = value; |
| 5254 | |
| 5255 | if(ret_val >= 0) |
| 5256 | ret_val = 0; |
| 5257 | if(ret_val <= -33) |
| 5258 | ret_val = -33; |
| 5259 | ret_val = 0 - ret_val; |
| 5260 | ret_val*=3; |
| 5261 | if(ret_val == 99) |
| 5262 | ret_val = 100; |
Mike McCormack | c6eae67 | 2010-08-10 23:45:23 +0900 | [diff] [blame] | 5263 | return ret_val; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5264 | } |
| 5265 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 5266 | /* We want good-looking for signal strength/quality */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 5267 | static long rtl819x_signal_scale_mapping(long currsig) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5268 | { |
| 5269 | long retsig; |
| 5270 | |
| 5271 | // Step 1. Scale mapping. |
| 5272 | if(currsig >= 61 && currsig <= 100) |
| 5273 | { |
| 5274 | retsig = 90 + ((currsig - 60) / 4); |
| 5275 | } |
| 5276 | else if(currsig >= 41 && currsig <= 60) |
| 5277 | { |
| 5278 | retsig = 78 + ((currsig - 40) / 2); |
| 5279 | } |
| 5280 | else if(currsig >= 31 && currsig <= 40) |
| 5281 | { |
| 5282 | retsig = 66 + (currsig - 30); |
| 5283 | } |
| 5284 | else if(currsig >= 21 && currsig <= 30) |
| 5285 | { |
| 5286 | retsig = 54 + (currsig - 20); |
| 5287 | } |
| 5288 | else if(currsig >= 5 && currsig <= 20) |
| 5289 | { |
| 5290 | retsig = 42 + (((currsig - 5) * 2) / 3); |
| 5291 | } |
| 5292 | else if(currsig == 4) |
| 5293 | { |
| 5294 | retsig = 36; |
| 5295 | } |
| 5296 | else if(currsig == 3) |
| 5297 | { |
| 5298 | retsig = 27; |
| 5299 | } |
| 5300 | else if(currsig == 2) |
| 5301 | { |
| 5302 | retsig = 18; |
| 5303 | } |
| 5304 | else if(currsig == 1) |
| 5305 | { |
| 5306 | retsig = 9; |
| 5307 | } |
| 5308 | else |
| 5309 | { |
| 5310 | retsig = currsig; |
| 5311 | } |
| 5312 | |
| 5313 | return retsig; |
| 5314 | } |
| 5315 | |
| 5316 | static void rtl8192_query_rxphystatus( |
| 5317 | struct r8192_priv * priv, |
| 5318 | struct ieee80211_rx_stats * pstats, |
| 5319 | prx_desc_819x_pci pdesc, |
| 5320 | prx_fwinfo_819x_pci pdrvinfo, |
| 5321 | struct ieee80211_rx_stats * precord_stats, |
| 5322 | bool bpacket_match_bssid, |
| 5323 | bool bpacket_toself, |
| 5324 | bool bPacketBeacon, |
| 5325 | bool bToSelfBA |
| 5326 | ) |
| 5327 | { |
| 5328 | //PRT_RFD_STATUS pRtRfdStatus = &(pRfd->Status); |
| 5329 | phy_sts_ofdm_819xpci_t* pofdm_buf; |
| 5330 | phy_sts_cck_819xpci_t * pcck_buf; |
| 5331 | phy_ofdm_rx_status_rxsc_sgien_exintfflag* prxsc; |
| 5332 | u8 *prxpkt; |
| 5333 | u8 i,max_spatial_stream, tmp_rxsnr, tmp_rxevm, rxsc_sgien_exflg; |
| 5334 | char rx_pwr[4], rx_pwr_all=0; |
| 5335 | //long rx_avg_pwr = 0; |
| 5336 | char rx_snrX, rx_evmX; |
| 5337 | u8 evm, pwdb_all; |
| 5338 | u32 RSSI, total_rssi=0;//, total_evm=0; |
| 5339 | // long signal_strength_index = 0; |
| 5340 | u8 is_cck_rate=0; |
| 5341 | u8 rf_rx_num = 0; |
| 5342 | |
| 5343 | /* 2007/07/04 MH For OFDM RSSI. For high power or not. */ |
| 5344 | static u8 check_reg824 = 0; |
| 5345 | static u32 reg824_bit9 = 0; |
| 5346 | |
| 5347 | priv->stats.numqry_phystatus++; |
| 5348 | |
| 5349 | is_cck_rate = rx_hal_is_cck_rate(pdrvinfo); |
| 5350 | |
| 5351 | // Record it for next packet processing |
| 5352 | memset(precord_stats, 0, sizeof(struct ieee80211_rx_stats)); |
| 5353 | pstats->bPacketMatchBSSID = precord_stats->bPacketMatchBSSID = bpacket_match_bssid; |
| 5354 | pstats->bPacketToSelf = precord_stats->bPacketToSelf = bpacket_toself; |
| 5355 | pstats->bIsCCK = precord_stats->bIsCCK = is_cck_rate;//RX_HAL_IS_CCK_RATE(pDrvInfo); |
| 5356 | pstats->bPacketBeacon = precord_stats->bPacketBeacon = bPacketBeacon; |
| 5357 | pstats->bToSelfBA = precord_stats->bToSelfBA = bToSelfBA; |
| 5358 | /*2007.08.30 requested by SD3 Jerry */ |
| 5359 | if(check_reg824 == 0) |
| 5360 | { |
| 5361 | reg824_bit9 = rtl8192_QueryBBReg(priv->ieee80211->dev, rFPGA0_XA_HSSIParameter2, 0x200); |
| 5362 | check_reg824 = 1; |
| 5363 | } |
| 5364 | |
| 5365 | |
| 5366 | prxpkt = (u8*)pdrvinfo; |
| 5367 | |
| 5368 | /* Move pointer to the 16th bytes. Phy status start address. */ |
| 5369 | prxpkt += sizeof(rx_fwinfo_819x_pci); |
| 5370 | |
| 5371 | /* Initial the cck and ofdm buffer pointer */ |
| 5372 | pcck_buf = (phy_sts_cck_819xpci_t *)prxpkt; |
| 5373 | pofdm_buf = (phy_sts_ofdm_819xpci_t *)prxpkt; |
| 5374 | |
| 5375 | pstats->RxMIMOSignalQuality[0] = -1; |
| 5376 | pstats->RxMIMOSignalQuality[1] = -1; |
| 5377 | precord_stats->RxMIMOSignalQuality[0] = -1; |
| 5378 | precord_stats->RxMIMOSignalQuality[1] = -1; |
| 5379 | |
| 5380 | if(is_cck_rate) |
| 5381 | { |
| 5382 | // |
| 5383 | // (1)Hardware does not provide RSSI for CCK |
| 5384 | // |
| 5385 | |
| 5386 | // |
| 5387 | // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive) |
| 5388 | // |
| 5389 | u8 report;//, cck_agc_rpt; |
| 5390 | #ifdef RTL8190P |
| 5391 | u8 tmp_pwdb; |
| 5392 | char cck_adc_pwdb[4]; |
| 5393 | #endif |
| 5394 | priv->stats.numqry_phystatusCCK++; |
| 5395 | |
| 5396 | #ifdef RTL8190P //Only 90P 2T4R need to check |
| 5397 | if(priv->rf_type == RF_2T4R && DM_RxPathSelTable.Enable && bpacket_match_bssid) |
| 5398 | { |
| 5399 | for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++) |
| 5400 | { |
| 5401 | tmp_pwdb = pcck_buf->adc_pwdb_X[i]; |
| 5402 | cck_adc_pwdb[i] = (char)tmp_pwdb; |
| 5403 | cck_adc_pwdb[i] /= 2; |
| 5404 | pstats->cck_adc_pwdb[i] = precord_stats->cck_adc_pwdb[i] = cck_adc_pwdb[i]; |
| 5405 | //DbgPrint("RF-%d tmp_pwdb = 0x%x, cck_adc_pwdb = %d", i, tmp_pwdb, cck_adc_pwdb[i]); |
| 5406 | } |
| 5407 | } |
| 5408 | #endif |
| 5409 | |
| 5410 | if(!reg824_bit9) |
| 5411 | { |
| 5412 | report = pcck_buf->cck_agc_rpt & 0xc0; |
| 5413 | report = report>>6; |
| 5414 | switch(report) |
| 5415 | { |
| 5416 | //Fixed by Jacken from Bryant 2008-03-20 |
| 5417 | //Original value is -38 , -26 , -14 , -2 |
| 5418 | //Fixed value is -35 , -23 , -11 , 6 |
| 5419 | case 0x3: |
| 5420 | rx_pwr_all = -35 - (pcck_buf->cck_agc_rpt & 0x3e); |
| 5421 | break; |
| 5422 | case 0x2: |
| 5423 | rx_pwr_all = -23 - (pcck_buf->cck_agc_rpt & 0x3e); |
| 5424 | break; |
| 5425 | case 0x1: |
| 5426 | rx_pwr_all = -11 - (pcck_buf->cck_agc_rpt & 0x3e); |
| 5427 | break; |
| 5428 | case 0x0: |
| 5429 | rx_pwr_all = 8 - (pcck_buf->cck_agc_rpt & 0x3e); |
| 5430 | break; |
| 5431 | } |
| 5432 | } |
| 5433 | else |
| 5434 | { |
| 5435 | report = pcck_buf->cck_agc_rpt & 0x60; |
| 5436 | report = report>>5; |
| 5437 | switch(report) |
| 5438 | { |
| 5439 | case 0x3: |
| 5440 | rx_pwr_all = -35 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ; |
| 5441 | break; |
| 5442 | case 0x2: |
| 5443 | rx_pwr_all = -23 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1); |
| 5444 | break; |
| 5445 | case 0x1: |
| 5446 | rx_pwr_all = -11 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ; |
| 5447 | break; |
| 5448 | case 0x0: |
| 5449 | rx_pwr_all = -8 - ((pcck_buf->cck_agc_rpt & 0x1f)<<1) ; |
| 5450 | break; |
| 5451 | } |
| 5452 | } |
| 5453 | |
| 5454 | pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all); |
| 5455 | pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all; |
| 5456 | pstats->RecvSignalPower = rx_pwr_all; |
| 5457 | |
| 5458 | // |
| 5459 | // (3) Get Signal Quality (EVM) |
| 5460 | // |
| 5461 | if(bpacket_match_bssid) |
| 5462 | { |
| 5463 | u8 sq; |
| 5464 | |
| 5465 | if(pstats->RxPWDBAll > 40) |
| 5466 | { |
| 5467 | sq = 100; |
| 5468 | }else |
| 5469 | { |
| 5470 | sq = pcck_buf->sq_rpt; |
| 5471 | |
| 5472 | if(pcck_buf->sq_rpt > 64) |
| 5473 | sq = 0; |
| 5474 | else if (pcck_buf->sq_rpt < 20) |
| 5475 | sq = 100; |
| 5476 | else |
| 5477 | sq = ((64-sq) * 100) / 44; |
| 5478 | } |
| 5479 | pstats->SignalQuality = precord_stats->SignalQuality = sq; |
| 5480 | pstats->RxMIMOSignalQuality[0] = precord_stats->RxMIMOSignalQuality[0] = sq; |
| 5481 | pstats->RxMIMOSignalQuality[1] = precord_stats->RxMIMOSignalQuality[1] = -1; |
| 5482 | } |
| 5483 | } |
| 5484 | else |
| 5485 | { |
| 5486 | priv->stats.numqry_phystatusHT++; |
| 5487 | // |
| 5488 | // (1)Get RSSI for HT rate |
| 5489 | // |
| 5490 | for(i=RF90_PATH_A; i<RF90_PATH_MAX; i++) |
| 5491 | { |
| 5492 | // 2008/01/30 MH we will judge RF RX path now. |
| 5493 | if (priv->brfpath_rxenable[i]) |
| 5494 | rf_rx_num++; |
| 5495 | //else |
| 5496 | //continue; |
| 5497 | |
| 5498 | //Fixed by Jacken from Bryant 2008-03-20 |
| 5499 | //Original value is 106 |
| 5500 | #ifdef RTL8190P //Modify by Jacken 2008/03/31 |
| 5501 | rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 106; |
| 5502 | #else |
| 5503 | rx_pwr[i] = ((pofdm_buf->trsw_gain_X[i]&0x3F)*2) - 110; |
| 5504 | #endif |
| 5505 | |
| 5506 | //Get Rx snr value in DB |
| 5507 | tmp_rxsnr = pofdm_buf->rxsnr_X[i]; |
| 5508 | rx_snrX = (char)(tmp_rxsnr); |
| 5509 | rx_snrX /= 2; |
| 5510 | priv->stats.rxSNRdB[i] = (long)rx_snrX; |
| 5511 | |
| 5512 | /* Translate DBM to percentage. */ |
| 5513 | RSSI = rtl819x_query_rxpwrpercentage(rx_pwr[i]); |
| 5514 | if (priv->brfpath_rxenable[i]) |
| 5515 | total_rssi += RSSI; |
| 5516 | |
| 5517 | /* Record Signal Strength for next packet */ |
| 5518 | if(bpacket_match_bssid) |
| 5519 | { |
| 5520 | pstats->RxMIMOSignalStrength[i] =(u8) RSSI; |
| 5521 | precord_stats->RxMIMOSignalStrength[i] =(u8) RSSI; |
| 5522 | } |
| 5523 | } |
| 5524 | |
| 5525 | |
| 5526 | // |
| 5527 | // (2)PWDB, Average PWDB cacluated by hardware (for rate adaptive) |
| 5528 | // |
| 5529 | //Fixed by Jacken from Bryant 2008-03-20 |
| 5530 | //Original value is 106 |
| 5531 | rx_pwr_all = (((pofdm_buf->pwdb_all ) >> 1 )& 0x7f) -106; |
| 5532 | pwdb_all = rtl819x_query_rxpwrpercentage(rx_pwr_all); |
| 5533 | |
| 5534 | pstats->RxPWDBAll = precord_stats->RxPWDBAll = pwdb_all; |
| 5535 | pstats->RxPower = precord_stats->RxPower = rx_pwr_all; |
| 5536 | pstats->RecvSignalPower = rx_pwr_all; |
| 5537 | // |
| 5538 | // (3)EVM of HT rate |
| 5539 | // |
| 5540 | if(pdrvinfo->RxHT && pdrvinfo->RxRate>=DESC90_RATEMCS8 && |
| 5541 | pdrvinfo->RxRate<=DESC90_RATEMCS15) |
| 5542 | max_spatial_stream = 2; //both spatial stream make sense |
| 5543 | else |
| 5544 | max_spatial_stream = 1; //only spatial stream 1 makes sense |
| 5545 | |
| 5546 | for(i=0; i<max_spatial_stream; i++) |
| 5547 | { |
| 5548 | tmp_rxevm = pofdm_buf->rxevm_X[i]; |
| 5549 | rx_evmX = (char)(tmp_rxevm); |
| 5550 | |
| 5551 | // Do not use shift operation like "rx_evmX >>= 1" because the compilor of free build environment |
| 5552 | // fill most significant bit to "zero" when doing shifting operation which may change a negative |
| 5553 | // value to positive one, then the dbm value (which is supposed to be negative) is not correct anymore. |
| 5554 | rx_evmX /= 2; //dbm |
| 5555 | |
| 5556 | evm = rtl819x_evm_dbtopercentage(rx_evmX); |
| 5557 | #if 0 |
| 5558 | EVM = SignalScaleMapping(EVM);//make it good looking, from 0~100 |
| 5559 | #endif |
| 5560 | if(bpacket_match_bssid) |
| 5561 | { |
| 5562 | if(i==0) // Fill value in RFD, Get the first spatial stream only |
| 5563 | pstats->SignalQuality = precord_stats->SignalQuality = (u8)(evm & 0xff); |
| 5564 | pstats->RxMIMOSignalQuality[i] = precord_stats->RxMIMOSignalQuality[i] = (u8)(evm & 0xff); |
| 5565 | } |
| 5566 | } |
| 5567 | |
| 5568 | |
| 5569 | /* record rx statistics for debug */ |
| 5570 | rxsc_sgien_exflg = pofdm_buf->rxsc_sgien_exflg; |
| 5571 | prxsc = (phy_ofdm_rx_status_rxsc_sgien_exintfflag *)&rxsc_sgien_exflg; |
| 5572 | if(pdrvinfo->BW) //40M channel |
| 5573 | priv->stats.received_bwtype[1+prxsc->rxsc]++; |
| 5574 | else //20M channel |
| 5575 | priv->stats.received_bwtype[0]++; |
| 5576 | } |
| 5577 | |
| 5578 | //UI BSS List signal strength(in percentage), make it good looking, from 0~100. |
| 5579 | //It is assigned to the BSS List in GetValueFromBeaconOrProbeRsp(). |
| 5580 | if(is_cck_rate) |
| 5581 | { |
| 5582 | pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)pwdb_all));//PWDB_ALL; |
| 5583 | |
| 5584 | } |
| 5585 | else |
| 5586 | { |
| 5587 | //pRfd->Status.SignalStrength = pRecordRfd->Status.SignalStrength = (u1Byte)(SignalScaleMapping(total_rssi/=RF90_PATH_MAX));//(u1Byte)(total_rssi/=RF90_PATH_MAX); |
| 5588 | // We can judge RX path number now. |
| 5589 | if (rf_rx_num != 0) |
| 5590 | pstats->SignalStrength = precord_stats->SignalStrength = (u8)(rtl819x_signal_scale_mapping((long)(total_rssi/=rf_rx_num))); |
| 5591 | } |
Mike McCormack | d5abdf7 | 2010-09-08 22:03:59 +0900 | [diff] [blame] | 5592 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5593 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 5594 | static void |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5595 | rtl8192_record_rxdesc_forlateruse( |
| 5596 | struct ieee80211_rx_stats * psrc_stats, |
| 5597 | struct ieee80211_rx_stats * ptarget_stats |
| 5598 | ) |
| 5599 | { |
| 5600 | ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU; |
| 5601 | ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU; |
| 5602 | //ptarget_stats->Seq_Num = psrc_stats->Seq_Num; |
| 5603 | } |
| 5604 | |
| 5605 | |
| 5606 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 5607 | static void TranslateRxSignalStuff819xpci(struct net_device *dev, |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5608 | struct sk_buff *skb, |
| 5609 | struct ieee80211_rx_stats * pstats, |
| 5610 | prx_desc_819x_pci pdesc, |
| 5611 | prx_fwinfo_819x_pci pdrvinfo) |
| 5612 | { |
| 5613 | // TODO: We must only check packet for current MAC address. Not finish |
| 5614 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 5615 | bool bpacket_match_bssid, bpacket_toself; |
| 5616 | bool bPacketBeacon=false, bToSelfBA=false; |
| 5617 | static struct ieee80211_rx_stats previous_stats; |
| 5618 | struct ieee80211_hdr_3addr *hdr; |
| 5619 | u16 fc,type; |
| 5620 | |
| 5621 | // Get Signal Quality for only RX data queue (but not command queue) |
| 5622 | |
| 5623 | u8* tmp_buf; |
| 5624 | u8 *praddr; |
| 5625 | |
| 5626 | /* Get MAC frame start address. */ |
| 5627 | tmp_buf = skb->data; |
| 5628 | |
| 5629 | hdr = (struct ieee80211_hdr_3addr *)tmp_buf; |
| 5630 | fc = le16_to_cpu(hdr->frame_ctl); |
| 5631 | type = WLAN_FC_GET_TYPE(fc); |
| 5632 | praddr = hdr->addr1; |
| 5633 | |
| 5634 | /* Check if the received packet is acceptabe. */ |
| 5635 | bpacket_match_bssid = ((IEEE80211_FTYPE_CTL != type) && |
| 5636 | (eqMacAddr(priv->ieee80211->current_network.bssid, (fc & IEEE80211_FCTL_TODS)? hdr->addr1 : (fc & IEEE80211_FCTL_FROMDS )? hdr->addr2 : hdr->addr3)) |
| 5637 | && (!pstats->bHwError) && (!pstats->bCRC)&& (!pstats->bICV)); |
| 5638 | bpacket_toself = bpacket_match_bssid & (eqMacAddr(praddr, priv->ieee80211->dev->dev_addr)); |
| 5639 | #if 1//cosa |
| 5640 | if(WLAN_FC_GET_FRAMETYPE(fc)== IEEE80211_STYPE_BEACON) |
| 5641 | { |
| 5642 | bPacketBeacon = true; |
| 5643 | //DbgPrint("Beacon 2, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf); |
| 5644 | } |
| 5645 | if(WLAN_FC_GET_FRAMETYPE(fc) == IEEE80211_STYPE_BLOCKACK) |
| 5646 | { |
| 5647 | if((eqMacAddr(praddr,dev->dev_addr))) |
| 5648 | bToSelfBA = true; |
| 5649 | //DbgPrint("BlockAck, MatchBSSID = %d, ToSelf = %d \n", bPacketMatchBSSID, bPacketToSelf); |
| 5650 | } |
| 5651 | |
| 5652 | #endif |
| 5653 | if(bpacket_match_bssid) |
| 5654 | { |
| 5655 | priv->stats.numpacket_matchbssid++; |
| 5656 | } |
| 5657 | if(bpacket_toself){ |
| 5658 | priv->stats.numpacket_toself++; |
| 5659 | } |
| 5660 | // |
| 5661 | // Process PHY information for previous packet (RSSI/PWDB/EVM) |
| 5662 | // |
| 5663 | // Because phy information is contained in the last packet of AMPDU only, so driver |
| 5664 | // should process phy information of previous packet |
| 5665 | rtl8192_process_phyinfo(priv, tmp_buf,&previous_stats, pstats); |
| 5666 | rtl8192_query_rxphystatus(priv, pstats, pdesc, pdrvinfo, &previous_stats, bpacket_match_bssid, |
| 5667 | bpacket_toself ,bPacketBeacon, bToSelfBA); |
| 5668 | rtl8192_record_rxdesc_forlateruse(pstats, &previous_stats); |
| 5669 | |
| 5670 | } |
| 5671 | |
| 5672 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 5673 | static void rtl8192_tx_resume(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5674 | { |
| 5675 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 5676 | struct ieee80211_device *ieee = priv->ieee80211; |
| 5677 | struct sk_buff *skb; |
| 5678 | int queue_index; |
| 5679 | |
| 5680 | for(queue_index = BK_QUEUE; queue_index < TXCMD_QUEUE;queue_index++) { |
| 5681 | while((!skb_queue_empty(&ieee->skb_waitQ[queue_index]))&& |
| 5682 | (priv->ieee80211->check_nic_enough_desc(dev,queue_index) > 0)) { |
| 5683 | /* 1. dequeue the packet from the wait queue */ |
| 5684 | skb = skb_dequeue(&ieee->skb_waitQ[queue_index]); |
| 5685 | /* 2. tx the packet directly */ |
| 5686 | ieee->softmac_data_hard_start_xmit(skb,dev,0/* rate useless now*/); |
| 5687 | #if 0 |
| 5688 | if(queue_index!=MGNT_QUEUE) { |
| 5689 | ieee->stats.tx_packets++; |
| 5690 | ieee->stats.tx_bytes += skb->len; |
| 5691 | } |
| 5692 | #endif |
| 5693 | } |
| 5694 | } |
| 5695 | } |
| 5696 | |
Mike McCormack | 559fba5 | 2010-07-26 22:57:52 +0900 | [diff] [blame] | 5697 | static void rtl8192_irq_tx_tasklet(struct r8192_priv *priv) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5698 | { |
| 5699 | rtl8192_tx_resume(priv->ieee80211->dev); |
| 5700 | } |
| 5701 | |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 5702 | /* Record the received data rate */ |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 5703 | static void UpdateReceivedRateHistogramStatistics8190( |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5704 | struct net_device *dev, |
| 5705 | struct ieee80211_rx_stats* pstats |
| 5706 | ) |
| 5707 | { |
| 5708 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 5709 | u32 rcvType=1; //0: Total, 1:OK, 2:CRC, 3:ICV |
| 5710 | u32 rateIndex; |
| 5711 | u32 preamble_guardinterval; //1: short preamble/GI, 0: long preamble/GI |
| 5712 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5713 | if(pstats->bCRC) |
| 5714 | rcvType = 2; |
| 5715 | else if(pstats->bICV) |
| 5716 | rcvType = 3; |
| 5717 | |
| 5718 | if(pstats->bShortPreamble) |
| 5719 | preamble_guardinterval = 1;// short |
| 5720 | else |
| 5721 | preamble_guardinterval = 0;// long |
| 5722 | |
| 5723 | switch(pstats->rate) |
| 5724 | { |
| 5725 | // |
| 5726 | // CCK rate |
| 5727 | // |
| 5728 | case MGN_1M: rateIndex = 0; break; |
| 5729 | case MGN_2M: rateIndex = 1; break; |
| 5730 | case MGN_5_5M: rateIndex = 2; break; |
| 5731 | case MGN_11M: rateIndex = 3; break; |
| 5732 | // |
| 5733 | // Legacy OFDM rate |
| 5734 | // |
| 5735 | case MGN_6M: rateIndex = 4; break; |
| 5736 | case MGN_9M: rateIndex = 5; break; |
| 5737 | case MGN_12M: rateIndex = 6; break; |
| 5738 | case MGN_18M: rateIndex = 7; break; |
| 5739 | case MGN_24M: rateIndex = 8; break; |
| 5740 | case MGN_36M: rateIndex = 9; break; |
| 5741 | case MGN_48M: rateIndex = 10; break; |
| 5742 | case MGN_54M: rateIndex = 11; break; |
| 5743 | // |
| 5744 | // 11n High throughput rate |
| 5745 | // |
| 5746 | case MGN_MCS0: rateIndex = 12; break; |
| 5747 | case MGN_MCS1: rateIndex = 13; break; |
| 5748 | case MGN_MCS2: rateIndex = 14; break; |
| 5749 | case MGN_MCS3: rateIndex = 15; break; |
| 5750 | case MGN_MCS4: rateIndex = 16; break; |
| 5751 | case MGN_MCS5: rateIndex = 17; break; |
| 5752 | case MGN_MCS6: rateIndex = 18; break; |
| 5753 | case MGN_MCS7: rateIndex = 19; break; |
| 5754 | case MGN_MCS8: rateIndex = 20; break; |
| 5755 | case MGN_MCS9: rateIndex = 21; break; |
| 5756 | case MGN_MCS10: rateIndex = 22; break; |
| 5757 | case MGN_MCS11: rateIndex = 23; break; |
| 5758 | case MGN_MCS12: rateIndex = 24; break; |
| 5759 | case MGN_MCS13: rateIndex = 25; break; |
| 5760 | case MGN_MCS14: rateIndex = 26; break; |
| 5761 | case MGN_MCS15: rateIndex = 27; break; |
| 5762 | default: rateIndex = 28; break; |
| 5763 | } |
| 5764 | priv->stats.received_preamble_GI[preamble_guardinterval][rateIndex]++; |
| 5765 | priv->stats.received_rate_histogram[0][rateIndex]++; //total |
| 5766 | priv->stats.received_rate_histogram[rcvType][rateIndex]++; |
| 5767 | } |
| 5768 | |
Greg Kroah-Hartman | 5e1ad18 | 2009-08-10 16:34:22 -0700 | [diff] [blame] | 5769 | static void rtl8192_rx(struct net_device *dev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5770 | { |
| 5771 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 5772 | struct ieee80211_hdr_1addr *ieee80211_hdr = NULL; |
| 5773 | bool unicast_packet = false; |
| 5774 | struct ieee80211_rx_stats stats = { |
| 5775 | .signal = 0, |
| 5776 | .noise = -98, |
| 5777 | .rate = 0, |
| 5778 | .freq = IEEE80211_24GHZ_BAND, |
| 5779 | }; |
| 5780 | unsigned int count = priv->rxringcount; |
| 5781 | |
| 5782 | stats.nic_type = NIC_8192E; |
| 5783 | |
| 5784 | while (count--) { |
| 5785 | rx_desc_819x_pci *pdesc = &priv->rx_ring[priv->rx_idx];//rx descriptor |
| 5786 | struct sk_buff *skb = priv->rx_buf[priv->rx_idx];//rx pkt |
| 5787 | |
| 5788 | if (pdesc->OWN){ |
| 5789 | /* wait data to be filled by hardware */ |
| 5790 | return; |
| 5791 | } else { |
| 5792 | stats.bICV = pdesc->ICV; |
| 5793 | stats.bCRC = pdesc->CRC32; |
| 5794 | stats.bHwError = pdesc->CRC32 | pdesc->ICV; |
| 5795 | |
| 5796 | stats.Length = pdesc->Length; |
| 5797 | if(stats.Length < 24) |
| 5798 | stats.bHwError |= 1; |
| 5799 | |
| 5800 | if(stats.bHwError) { |
| 5801 | stats.bShift = false; |
| 5802 | |
| 5803 | if(pdesc->CRC32) { |
| 5804 | if (pdesc->Length <500) |
| 5805 | priv->stats.rxcrcerrmin++; |
| 5806 | else if (pdesc->Length >1000) |
| 5807 | priv->stats.rxcrcerrmax++; |
| 5808 | else |
| 5809 | priv->stats.rxcrcerrmid++; |
| 5810 | } |
| 5811 | goto done; |
| 5812 | } else { |
| 5813 | prx_fwinfo_819x_pci pDrvInfo = NULL; |
| 5814 | struct sk_buff *new_skb = dev_alloc_skb(priv->rxbuffersize); |
| 5815 | |
| 5816 | if (unlikely(!new_skb)) { |
| 5817 | goto done; |
| 5818 | } |
| 5819 | |
| 5820 | stats.RxDrvInfoSize = pdesc->RxDrvInfoSize; |
| 5821 | stats.RxBufShift = ((pdesc->Shift)&0x03); |
| 5822 | stats.Decrypted = !pdesc->SWDec; |
| 5823 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5824 | pci_dma_sync_single_for_cpu(priv->pdev, |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5825 | *((dma_addr_t *)skb->cb), |
| 5826 | priv->rxbuffersize, |
| 5827 | PCI_DMA_FROMDEVICE); |
| 5828 | skb_put(skb, pdesc->Length); |
| 5829 | pDrvInfo = (rx_fwinfo_819x_pci *)(skb->data + stats.RxBufShift); |
| 5830 | skb_reserve(skb, stats.RxDrvInfoSize + stats.RxBufShift); |
| 5831 | |
| 5832 | stats.rate = HwRateToMRate90((bool)pDrvInfo->RxHT, (u8)pDrvInfo->RxRate); |
| 5833 | stats.bShortPreamble = pDrvInfo->SPLCP; |
| 5834 | |
| 5835 | /* it is debug only. It should be disabled in released driver. |
| 5836 | * 2007.1.11 by Emily |
| 5837 | * */ |
| 5838 | UpdateReceivedRateHistogramStatistics8190(dev, &stats); |
| 5839 | |
| 5840 | stats.bIsAMPDU = (pDrvInfo->PartAggr==1); |
| 5841 | stats.bFirstMPDU = (pDrvInfo->PartAggr==1) && (pDrvInfo->FirstAGGR==1); |
| 5842 | |
| 5843 | stats.TimeStampLow = pDrvInfo->TSFL; |
| 5844 | stats.TimeStampHigh = read_nic_dword(dev, TSFR+4); |
| 5845 | |
| 5846 | UpdateRxPktTimeStamp8190(dev, &stats); |
| 5847 | |
| 5848 | // |
| 5849 | // Get Total offset of MPDU Frame Body |
| 5850 | // |
| 5851 | if((stats.RxBufShift + stats.RxDrvInfoSize) > 0) |
| 5852 | stats.bShift = 1; |
| 5853 | |
| 5854 | stats.RxIs40MHzPacket = pDrvInfo->BW; |
| 5855 | |
| 5856 | /* ???? */ |
| 5857 | TranslateRxSignalStuff819xpci(dev,skb, &stats, pdesc, pDrvInfo); |
| 5858 | |
| 5859 | /* Rx A-MPDU */ |
| 5860 | if(pDrvInfo->FirstAGGR==1 || pDrvInfo->PartAggr == 1) |
| 5861 | RT_TRACE(COMP_RXDESC, "pDrvInfo->FirstAGGR = %d, pDrvInfo->PartAggr = %d\n", |
| 5862 | pDrvInfo->FirstAGGR, pDrvInfo->PartAggr); |
| 5863 | skb_trim(skb, skb->len - 4/*sCrcLng*/); |
| 5864 | /* rx packets statistics */ |
| 5865 | ieee80211_hdr = (struct ieee80211_hdr_1addr *)skb->data; |
| 5866 | unicast_packet = false; |
| 5867 | |
| 5868 | if(is_broadcast_ether_addr(ieee80211_hdr->addr1)) { |
| 5869 | //TODO |
| 5870 | }else if(is_multicast_ether_addr(ieee80211_hdr->addr1)){ |
| 5871 | //TODO |
| 5872 | }else { |
| 5873 | /* unicast packet */ |
| 5874 | unicast_packet = true; |
| 5875 | } |
| 5876 | |
| 5877 | stats.packetlength = stats.Length-4; |
| 5878 | stats.fraglength = stats.packetlength; |
| 5879 | stats.fragoffset = 0; |
| 5880 | stats.ntotalfrag = 1; |
| 5881 | |
George Kadianakis | fb5fe27 | 2009-12-17 01:18:08 +0200 | [diff] [blame] | 5882 | if(!ieee80211_rtl_rx(priv->ieee80211, skb, &stats)){ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5883 | dev_kfree_skb_any(skb); |
| 5884 | } else { |
| 5885 | priv->stats.rxok++; |
| 5886 | if(unicast_packet) { |
| 5887 | priv->stats.rxbytesunicast += skb->len; |
| 5888 | } |
| 5889 | } |
| 5890 | |
| 5891 | skb = new_skb; |
| 5892 | priv->rx_buf[priv->rx_idx] = skb; |
Jeff Mahoney | 1c7ec2e | 2010-01-11 10:54:27 -0500 | [diff] [blame] | 5893 | *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev, skb_tail_pointer(skb), priv->rxbuffersize, PCI_DMA_FROMDEVICE); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | } |
| 5897 | done: |
| 5898 | pdesc->BufferAddress = cpu_to_le32(*((dma_addr_t *)skb->cb)); |
| 5899 | pdesc->OWN = 1; |
| 5900 | pdesc->Length = priv->rxbuffersize; |
| 5901 | if (priv->rx_idx == priv->rxringcount-1) |
| 5902 | pdesc->EOR = 1; |
| 5903 | priv->rx_idx = (priv->rx_idx + 1) % priv->rxringcount; |
| 5904 | } |
| 5905 | |
| 5906 | } |
| 5907 | |
Mike McCormack | 559fba5 | 2010-07-26 22:57:52 +0900 | [diff] [blame] | 5908 | static void rtl8192_irq_rx_tasklet(struct r8192_priv *priv) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5909 | { |
| 5910 | rtl8192_rx(priv->ieee80211->dev); |
| 5911 | /* unmask RDU */ |
| 5912 | write_nic_dword(priv->ieee80211->dev, INTA_MASK,read_nic_dword(priv->ieee80211->dev, INTA_MASK) | IMR_RDU); |
| 5913 | } |
| 5914 | |
| 5915 | static const struct net_device_ops rtl8192_netdev_ops = { |
| 5916 | .ndo_open = rtl8192_open, |
| 5917 | .ndo_stop = rtl8192_close, |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5918 | .ndo_tx_timeout = tx_timeout, |
| 5919 | .ndo_do_ioctl = rtl8192_ioctl, |
| 5920 | .ndo_set_multicast_list = r8192_set_multicast, |
| 5921 | .ndo_set_mac_address = r8192_set_mac_adr, |
George Kadianakis | fb5fe27 | 2009-12-17 01:18:08 +0200 | [diff] [blame] | 5922 | .ndo_start_xmit = ieee80211_rtl_xmit, |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5923 | }; |
| 5924 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5925 | static int __devinit rtl8192_pci_probe(struct pci_dev *pdev, |
| 5926 | const struct pci_device_id *id) |
| 5927 | { |
| 5928 | unsigned long ioaddr = 0; |
| 5929 | struct net_device *dev = NULL; |
| 5930 | struct r8192_priv *priv= NULL; |
| 5931 | u8 unit = 0; |
Kulikov Vasiliy | 3a8f2d3 | 2010-08-09 23:51:59 +0400 | [diff] [blame] | 5932 | int ret = -ENODEV; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5933 | |
| 5934 | #ifdef CONFIG_RTL8192_IO_MAP |
| 5935 | unsigned long pio_start, pio_len, pio_flags; |
| 5936 | #else |
| 5937 | unsigned long pmem_start, pmem_len, pmem_flags; |
| 5938 | #endif //end #ifdef RTL_IO_MAP |
| 5939 | |
| 5940 | RT_TRACE(COMP_INIT,"Configuring chip resources"); |
| 5941 | |
| 5942 | if( pci_enable_device (pdev) ){ |
| 5943 | RT_TRACE(COMP_ERR,"Failed to enable PCI device"); |
| 5944 | return -EIO; |
| 5945 | } |
| 5946 | |
| 5947 | pci_set_master(pdev); |
| 5948 | //pci_set_wmi(pdev); |
| 5949 | pci_set_dma_mask(pdev, 0xffffff00ULL); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5950 | pci_set_consistent_dma_mask(pdev,0xffffff00ULL); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5951 | dev = alloc_ieee80211(sizeof(struct r8192_priv)); |
Kulikov Vasiliy | 3a8f2d3 | 2010-08-09 23:51:59 +0400 | [diff] [blame] | 5952 | if (!dev) { |
| 5953 | ret = -ENOMEM; |
| 5954 | goto fail_free; |
| 5955 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5956 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5957 | pci_set_drvdata(pdev, dev); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5958 | SET_NETDEV_DEV(dev, &pdev->dev); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5959 | priv = ieee80211_priv(dev); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5960 | priv->ieee80211 = netdev_priv(dev); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5961 | priv->pdev=pdev; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5962 | if((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK)&&(pdev->subsystem_device == 0x3304)){ |
| 5963 | priv->ieee80211->bSupportRemoteWakeUp = 1; |
| 5964 | } else |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 5965 | { |
| 5966 | priv->ieee80211->bSupportRemoteWakeUp = 0; |
| 5967 | } |
| 5968 | |
| 5969 | #ifdef CONFIG_RTL8192_IO_MAP |
| 5970 | |
| 5971 | pio_start = (unsigned long)pci_resource_start (pdev, 0); |
| 5972 | pio_len = (unsigned long)pci_resource_len (pdev, 0); |
| 5973 | pio_flags = (unsigned long)pci_resource_flags (pdev, 0); |
| 5974 | |
| 5975 | if (!(pio_flags & IORESOURCE_IO)) { |
| 5976 | RT_TRACE(COMP_ERR,"region #0 not a PIO resource, aborting"); |
| 5977 | goto fail; |
| 5978 | } |
| 5979 | |
| 5980 | //DMESG("IO space @ 0x%08lx", pio_start ); |
| 5981 | if( ! request_region( pio_start, pio_len, RTL819xE_MODULE_NAME ) ){ |
| 5982 | RT_TRACE(COMP_ERR,"request_region failed!"); |
| 5983 | goto fail; |
| 5984 | } |
| 5985 | |
| 5986 | ioaddr = pio_start; |
| 5987 | dev->base_addr = ioaddr; // device I/O address |
| 5988 | |
| 5989 | #else |
| 5990 | |
| 5991 | pmem_start = pci_resource_start(pdev, 1); |
| 5992 | pmem_len = pci_resource_len(pdev, 1); |
| 5993 | pmem_flags = pci_resource_flags (pdev, 1); |
| 5994 | |
| 5995 | if (!(pmem_flags & IORESOURCE_MEM)) { |
| 5996 | RT_TRACE(COMP_ERR,"region #1 not a MMIO resource, aborting"); |
| 5997 | goto fail; |
| 5998 | } |
| 5999 | |
| 6000 | //DMESG("Memory mapped space @ 0x%08lx ", pmem_start); |
| 6001 | if( ! request_mem_region(pmem_start, pmem_len, RTL819xE_MODULE_NAME)) { |
| 6002 | RT_TRACE(COMP_ERR,"request_mem_region failed!"); |
| 6003 | goto fail; |
| 6004 | } |
| 6005 | |
| 6006 | |
| 6007 | ioaddr = (unsigned long)ioremap_nocache( pmem_start, pmem_len); |
| 6008 | if( ioaddr == (unsigned long)NULL ){ |
| 6009 | RT_TRACE(COMP_ERR,"ioremap failed!"); |
| 6010 | // release_mem_region( pmem_start, pmem_len ); |
| 6011 | goto fail1; |
| 6012 | } |
| 6013 | |
| 6014 | dev->mem_start = ioaddr; // shared mem start |
| 6015 | dev->mem_end = ioaddr + pci_resource_len(pdev, 0); // shared mem end |
| 6016 | |
| 6017 | #endif //end #ifdef RTL_IO_MAP |
| 6018 | |
| 6019 | /* We disable the RETRY_TIMEOUT register (0x41) to keep |
| 6020 | * PCI Tx retries from interfering with C3 CPU state */ |
| 6021 | pci_write_config_byte(pdev, 0x41, 0x00); |
| 6022 | |
| 6023 | |
| 6024 | pci_read_config_byte(pdev, 0x05, &unit); |
| 6025 | pci_write_config_byte(pdev, 0x05, unit & (~0x04)); |
| 6026 | |
| 6027 | dev->irq = pdev->irq; |
| 6028 | priv->irq = 0; |
| 6029 | |
| 6030 | dev->netdev_ops = &rtl8192_netdev_ops; |
| 6031 | #if 0 |
| 6032 | dev->open = rtl8192_open; |
| 6033 | dev->stop = rtl8192_close; |
| 6034 | //dev->hard_start_xmit = rtl8192_8023_hard_start_xmit; |
| 6035 | dev->tx_timeout = tx_timeout; |
| 6036 | //dev->wireless_handlers = &r8192_wx_handlers_def; |
| 6037 | dev->do_ioctl = rtl8192_ioctl; |
| 6038 | dev->set_multicast_list = r8192_set_multicast; |
| 6039 | dev->set_mac_address = r8192_set_mac_adr; |
| 6040 | #endif |
| 6041 | |
| 6042 | //DMESG("Oops: i'm coming\n"); |
| 6043 | #if WIRELESS_EXT >= 12 |
| 6044 | #if WIRELESS_EXT < 17 |
| 6045 | dev->get_wireless_stats = r8192_get_wireless_stats; |
| 6046 | #endif |
| 6047 | dev->wireless_handlers = (struct iw_handler_def *) &r8192_wx_handlers_def; |
| 6048 | #endif |
| 6049 | //dev->get_wireless_stats = r8192_get_wireless_stats; |
| 6050 | dev->type=ARPHRD_ETHER; |
| 6051 | |
| 6052 | dev->watchdog_timeo = HZ*3; //modified by john, 0805 |
| 6053 | |
| 6054 | if (dev_alloc_name(dev, ifname) < 0){ |
| 6055 | RT_TRACE(COMP_INIT, "Oops: devname already taken! Trying wlan%%d...\n"); |
Rusty Russell | dca4130 | 2010-08-11 23:04:21 -0600 | [diff] [blame] | 6056 | strcpy(ifname, "wlan%d"); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6057 | dev_alloc_name(dev, ifname); |
| 6058 | } |
| 6059 | |
| 6060 | RT_TRACE(COMP_INIT, "Driver probe completed1\n"); |
| 6061 | if(rtl8192_init(dev)!=0){ |
| 6062 | RT_TRACE(COMP_ERR, "Initialization failed"); |
| 6063 | goto fail; |
| 6064 | } |
| 6065 | |
| 6066 | netif_carrier_off(dev); |
| 6067 | netif_stop_queue(dev); |
| 6068 | |
| 6069 | register_netdev(dev); |
| 6070 | RT_TRACE(COMP_INIT, "dev name=======> %s\n",dev->name); |
| 6071 | rtl8192_proc_init_one(dev); |
| 6072 | |
| 6073 | |
| 6074 | RT_TRACE(COMP_INIT, "Driver probe completed\n"); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6075 | return 0; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6076 | |
| 6077 | fail1: |
| 6078 | |
| 6079 | #ifdef CONFIG_RTL8180_IO_MAP |
| 6080 | |
| 6081 | if( dev->base_addr != 0 ){ |
| 6082 | |
| 6083 | release_region(dev->base_addr, |
| 6084 | pci_resource_len(pdev, 0) ); |
| 6085 | } |
| 6086 | #else |
| 6087 | if( dev->mem_start != (unsigned long)NULL ){ |
| 6088 | iounmap( (void *)dev->mem_start ); |
| 6089 | release_mem_region( pci_resource_start(pdev, 1), |
| 6090 | pci_resource_len(pdev, 1) ); |
| 6091 | } |
| 6092 | #endif //end #ifdef RTL_IO_MAP |
| 6093 | |
| 6094 | fail: |
| 6095 | if(dev){ |
| 6096 | |
| 6097 | if (priv->irq) { |
| 6098 | free_irq(dev->irq, dev); |
| 6099 | dev->irq=0; |
| 6100 | } |
| 6101 | free_ieee80211(dev); |
| 6102 | } |
| 6103 | |
Kulikov Vasiliy | 3a8f2d3 | 2010-08-09 23:51:59 +0400 | [diff] [blame] | 6104 | fail_free: |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6105 | pci_disable_device(pdev); |
| 6106 | |
| 6107 | DMESG("wlan driver load failed\n"); |
| 6108 | pci_set_drvdata(pdev, NULL); |
Kulikov Vasiliy | 3a8f2d3 | 2010-08-09 23:51:59 +0400 | [diff] [blame] | 6109 | return ret; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6110 | |
| 6111 | } |
| 6112 | |
| 6113 | /* detach all the work and timer structure declared or inititialized |
| 6114 | * in r8192_init function. |
| 6115 | * */ |
Mike McCormack | 5b3b1a7 | 2010-08-10 23:44:36 +0900 | [diff] [blame] | 6116 | static void rtl8192_cancel_deferred_work(struct r8192_priv* priv) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6117 | { |
| 6118 | /* call cancel_work_sync instead of cancel_delayed_work if and only if Linux_version_code |
| 6119 | * is or is newer than 2.6.20 and work structure is defined to be struct work_struct. |
| 6120 | * Otherwise call cancel_delayed_work is enough. |
Adam Buchbinder | 39cfb97 | 2009-12-18 15:43:51 -0500 | [diff] [blame] | 6121 | * FIXME (2.6.20 should 2.6.22, work_struct should not cancel) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6122 | * */ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6123 | cancel_delayed_work(&priv->watch_dog_wq); |
| 6124 | cancel_delayed_work(&priv->update_beacon_wq); |
| 6125 | cancel_delayed_work(&priv->ieee80211->hw_wakeup_wq); |
| 6126 | cancel_delayed_work(&priv->ieee80211->hw_sleep_wq); |
| 6127 | #ifdef RTL8192E |
| 6128 | cancel_delayed_work(&priv->gpio_change_rf_wq); |
| 6129 | #endif |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6130 | cancel_work_sync(&priv->reset_wq); |
| 6131 | cancel_work_sync(&priv->qos_activate); |
| 6132 | //cancel_work_sync(&priv->SetBWModeWorkItem); |
| 6133 | //cancel_work_sync(&priv->SwChnlWorkItem); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6134 | |
| 6135 | } |
| 6136 | |
| 6137 | |
| 6138 | static void __devexit rtl8192_pci_disconnect(struct pci_dev *pdev) |
| 6139 | { |
| 6140 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6141 | struct r8192_priv *priv ; |
| 6142 | |
| 6143 | if(dev){ |
| 6144 | |
| 6145 | unregister_netdev(dev); |
| 6146 | |
| 6147 | priv=ieee80211_priv(dev); |
| 6148 | |
| 6149 | rtl8192_proc_remove_one(dev); |
| 6150 | |
| 6151 | rtl8192_down(dev); |
| 6152 | if (priv->pFirmware) |
| 6153 | { |
| 6154 | vfree(priv->pFirmware); |
| 6155 | priv->pFirmware = NULL; |
| 6156 | } |
| 6157 | // priv->rf_close(dev); |
| 6158 | // rtl8192_usb_deleteendpoints(dev); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6159 | destroy_workqueue(priv->priv_wq); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6160 | /* redundant with rtl8192_down */ |
| 6161 | // rtl8192_irq_disable(dev); |
| 6162 | // rtl8192_reset(dev); |
| 6163 | // mdelay(10); |
| 6164 | { |
| 6165 | u32 i; |
| 6166 | /* free tx/rx rings */ |
| 6167 | rtl8192_free_rx_ring(dev); |
| 6168 | for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) { |
| 6169 | rtl8192_free_tx_ring(dev, i); |
| 6170 | } |
| 6171 | } |
| 6172 | if(priv->irq){ |
| 6173 | |
| 6174 | printk("Freeing irq %d\n",dev->irq); |
| 6175 | free_irq(dev->irq, dev); |
| 6176 | priv->irq=0; |
| 6177 | |
| 6178 | } |
| 6179 | |
| 6180 | |
| 6181 | |
| 6182 | // free_beacon_desc_ring(dev,priv->txbeaconcount); |
| 6183 | |
| 6184 | #ifdef CONFIG_RTL8180_IO_MAP |
| 6185 | |
| 6186 | if( dev->base_addr != 0 ){ |
| 6187 | |
| 6188 | release_region(dev->base_addr, |
| 6189 | pci_resource_len(pdev, 0) ); |
| 6190 | } |
| 6191 | #else |
| 6192 | if( dev->mem_start != (unsigned long)NULL ){ |
| 6193 | iounmap( (void *)dev->mem_start ); |
| 6194 | release_mem_region( pci_resource_start(pdev, 1), |
| 6195 | pci_resource_len(pdev, 1) ); |
| 6196 | } |
| 6197 | #endif /*end #ifdef RTL_IO_MAP*/ |
| 6198 | free_ieee80211(dev); |
| 6199 | |
| 6200 | } |
| 6201 | |
| 6202 | pci_disable_device(pdev); |
| 6203 | RT_TRACE(COMP_DOWN, "wlan driver removed\n"); |
| 6204 | } |
| 6205 | |
George Kadianakis | fb5fe27 | 2009-12-17 01:18:08 +0200 | [diff] [blame] | 6206 | extern int ieee80211_rtl_init(void); |
| 6207 | extern void ieee80211_rtl_exit(void); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6208 | |
| 6209 | static int __init rtl8192_pci_module_init(void) |
| 6210 | { |
| 6211 | int retval; |
| 6212 | |
George Kadianakis | fb5fe27 | 2009-12-17 01:18:08 +0200 | [diff] [blame] | 6213 | retval = ieee80211_rtl_init(); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6214 | if (retval) |
| 6215 | return retval; |
| 6216 | |
| 6217 | printk(KERN_INFO "\nLinux kernel driver for RTL8192 based WLAN cards\n"); |
| 6218 | printk(KERN_INFO "Copyright (c) 2007-2008, Realsil Wlan\n"); |
| 6219 | RT_TRACE(COMP_INIT, "Initializing module"); |
| 6220 | RT_TRACE(COMP_INIT, "Wireless extensions version %d", WIRELESS_EXT); |
| 6221 | rtl8192_proc_module_init(); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6222 | if(0!=pci_register_driver(&rtl8192_pci_driver)) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6223 | { |
| 6224 | DMESG("No device found"); |
| 6225 | /*pci_unregister_driver (&rtl8192_pci_driver);*/ |
| 6226 | return -ENODEV; |
| 6227 | } |
| 6228 | return 0; |
| 6229 | } |
| 6230 | |
| 6231 | |
| 6232 | static void __exit rtl8192_pci_module_exit(void) |
| 6233 | { |
| 6234 | pci_unregister_driver(&rtl8192_pci_driver); |
| 6235 | |
| 6236 | RT_TRACE(COMP_DOWN, "Exiting"); |
| 6237 | rtl8192_proc_module_remove(); |
George Kadianakis | fb5fe27 | 2009-12-17 01:18:08 +0200 | [diff] [blame] | 6238 | ieee80211_rtl_exit(); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6239 | } |
| 6240 | |
| 6241 | //warning message WB |
Mike McCormack | 559fba5 | 2010-07-26 22:57:52 +0900 | [diff] [blame] | 6242 | static irqreturn_t rtl8192_interrupt(int irq, void *netdev) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6243 | { |
| 6244 | struct net_device *dev = (struct net_device *) netdev; |
| 6245 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 6246 | unsigned long flags; |
| 6247 | u32 inta; |
| 6248 | /* We should return IRQ_NONE, but for now let me keep this */ |
| 6249 | if(priv->irq_enabled == 0){ |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6250 | return IRQ_HANDLED; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6251 | } |
| 6252 | |
| 6253 | spin_lock_irqsave(&priv->irq_th_lock,flags); |
| 6254 | |
| 6255 | //ISR: 4bytes |
| 6256 | |
| 6257 | inta = read_nic_dword(dev, ISR);// & priv->IntrMask; |
| 6258 | write_nic_dword(dev,ISR,inta); // reset int situation |
| 6259 | |
| 6260 | priv->stats.shints++; |
| 6261 | //DMESG("Enter interrupt, ISR value = 0x%08x", inta); |
| 6262 | if(!inta){ |
| 6263 | spin_unlock_irqrestore(&priv->irq_th_lock,flags); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6264 | return IRQ_HANDLED; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6265 | /* |
| 6266 | most probably we can safely return IRQ_NONE, |
| 6267 | but for now is better to avoid problems |
| 6268 | */ |
| 6269 | } |
| 6270 | |
| 6271 | if(inta == 0xffff){ |
| 6272 | /* HW disappared */ |
| 6273 | spin_unlock_irqrestore(&priv->irq_th_lock,flags); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6274 | return IRQ_HANDLED; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6275 | } |
| 6276 | |
| 6277 | priv->stats.ints++; |
| 6278 | #ifdef DEBUG_IRQ |
| 6279 | DMESG("NIC irq %x",inta); |
| 6280 | #endif |
| 6281 | //priv->irqpending = inta; |
| 6282 | |
| 6283 | |
| 6284 | if(!netif_running(dev)) { |
| 6285 | spin_unlock_irqrestore(&priv->irq_th_lock,flags); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6286 | return IRQ_HANDLED; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6287 | } |
| 6288 | |
| 6289 | if(inta & IMR_TIMEOUT0){ |
| 6290 | // write_nic_dword(dev, TimerInt, 0); |
| 6291 | //DMESG("=================>waking up"); |
| 6292 | // rtl8180_hw_wakeup(dev); |
| 6293 | } |
| 6294 | |
| 6295 | if(inta & IMR_TBDOK){ |
| 6296 | RT_TRACE(COMP_INTR, "beacon ok interrupt!\n"); |
| 6297 | rtl8192_tx_isr(dev, BEACON_QUEUE); |
| 6298 | priv->stats.txbeaconokint++; |
| 6299 | } |
| 6300 | |
| 6301 | if(inta & IMR_TBDER){ |
| 6302 | RT_TRACE(COMP_INTR, "beacon ok interrupt!\n"); |
| 6303 | rtl8192_tx_isr(dev, BEACON_QUEUE); |
| 6304 | priv->stats.txbeaconerr++; |
| 6305 | } |
| 6306 | |
| 6307 | if(inta & IMR_MGNTDOK ) { |
| 6308 | RT_TRACE(COMP_INTR, "Manage ok interrupt!\n"); |
| 6309 | priv->stats.txmanageokint++; |
| 6310 | rtl8192_tx_isr(dev,MGNT_QUEUE); |
| 6311 | |
| 6312 | } |
| 6313 | |
| 6314 | if(inta & IMR_COMDOK) |
| 6315 | { |
| 6316 | priv->stats.txcmdpktokint++; |
| 6317 | rtl8192_tx_isr(dev,TXCMD_QUEUE); |
| 6318 | } |
| 6319 | |
| 6320 | if(inta & IMR_ROK){ |
| 6321 | #ifdef DEBUG_RX |
| 6322 | DMESG("Frame arrived !"); |
| 6323 | #endif |
| 6324 | priv->stats.rxint++; |
| 6325 | tasklet_schedule(&priv->irq_rx_tasklet); |
| 6326 | } |
| 6327 | |
| 6328 | if(inta & IMR_BcnInt) { |
| 6329 | RT_TRACE(COMP_INTR, "prepare beacon for interrupt!\n"); |
| 6330 | tasklet_schedule(&priv->irq_prepare_beacon_tasklet); |
| 6331 | } |
| 6332 | |
| 6333 | if(inta & IMR_RDU){ |
| 6334 | RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n"); |
| 6335 | priv->stats.rxrdu++; |
| 6336 | /* reset int situation */ |
| 6337 | write_nic_dword(dev,INTA_MASK,read_nic_dword(dev, INTA_MASK) & ~IMR_RDU); |
| 6338 | tasklet_schedule(&priv->irq_rx_tasklet); |
| 6339 | } |
| 6340 | |
| 6341 | if(inta & IMR_RXFOVW){ |
| 6342 | RT_TRACE(COMP_INTR, "rx overflow !\n"); |
| 6343 | priv->stats.rxoverflow++; |
| 6344 | tasklet_schedule(&priv->irq_rx_tasklet); |
| 6345 | } |
| 6346 | |
| 6347 | if(inta & IMR_TXFOVW) priv->stats.txoverflow++; |
| 6348 | |
| 6349 | if(inta & IMR_BKDOK){ |
| 6350 | RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n"); |
| 6351 | priv->stats.txbkokint++; |
| 6352 | priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++; |
| 6353 | rtl8192_tx_isr(dev,BK_QUEUE); |
| 6354 | rtl8192_try_wake_queue(dev, BK_QUEUE); |
| 6355 | } |
| 6356 | |
| 6357 | if(inta & IMR_BEDOK){ |
| 6358 | RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n"); |
| 6359 | priv->stats.txbeokint++; |
| 6360 | priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++; |
| 6361 | rtl8192_tx_isr(dev,BE_QUEUE); |
| 6362 | rtl8192_try_wake_queue(dev, BE_QUEUE); |
| 6363 | } |
| 6364 | |
| 6365 | if(inta & IMR_VIDOK){ |
| 6366 | RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n"); |
| 6367 | priv->stats.txviokint++; |
| 6368 | priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++; |
| 6369 | rtl8192_tx_isr(dev,VI_QUEUE); |
| 6370 | rtl8192_try_wake_queue(dev, VI_QUEUE); |
| 6371 | } |
| 6372 | |
| 6373 | if(inta & IMR_VODOK){ |
| 6374 | priv->stats.txvookint++; |
| 6375 | priv->ieee80211->LinkDetectInfo.NumTxOkInPeriod++; |
| 6376 | rtl8192_tx_isr(dev,VO_QUEUE); |
| 6377 | rtl8192_try_wake_queue(dev, VO_QUEUE); |
| 6378 | } |
| 6379 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6380 | spin_unlock_irqrestore(&priv->irq_th_lock,flags); |
| 6381 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6382 | return IRQ_HANDLED; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6383 | } |
| 6384 | |
Mike McCormack | 559fba5 | 2010-07-26 22:57:52 +0900 | [diff] [blame] | 6385 | static void rtl8192_try_wake_queue(struct net_device *dev, int pri) |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6386 | { |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6387 | } |
| 6388 | |
| 6389 | |
| 6390 | void EnableHWSecurityConfig8192(struct net_device *dev) |
| 6391 | { |
| 6392 | u8 SECR_value = 0x0; |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6393 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
Mike McCormack | 16d74da | 2010-09-20 23:11:14 +0900 | [diff] [blame] | 6394 | struct ieee80211_device* ieee = priv->ieee80211; |
| 6395 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6396 | SECR_value = SCR_TxEncEnable | SCR_RxDecEnable; |
| 6397 | #if 1 |
| 6398 | if (((KEY_TYPE_WEP40 == ieee->pairwise_key_type) || (KEY_TYPE_WEP104 == ieee->pairwise_key_type)) && (priv->ieee80211->auth_mode != 2)) |
| 6399 | { |
| 6400 | SECR_value |= SCR_RxUseDK; |
| 6401 | SECR_value |= SCR_TxUseDK; |
| 6402 | } |
| 6403 | else if ((ieee->iw_mode == IW_MODE_ADHOC) && (ieee->pairwise_key_type & (KEY_TYPE_CCMP | KEY_TYPE_TKIP))) |
| 6404 | { |
| 6405 | SECR_value |= SCR_RxUseDK; |
| 6406 | SECR_value |= SCR_TxUseDK; |
| 6407 | } |
| 6408 | |
| 6409 | #endif |
| 6410 | |
| 6411 | //add HWSec active enable here. |
| 6412 | //default using hwsec. when peer AP is in N mode only and pairwise_key_type is none_aes(which HT_IOT_ACT_PURE_N_MODE indicates it), use software security. when peer AP is in b,g,n mode mixed and pairwise_key_type is none_aes, use g mode hw security. WB on 2008.7.4 |
| 6413 | ieee->hwsec_active = 1; |
| 6414 | |
| 6415 | if ((ieee->pHTInfo->IOTAction&HT_IOT_ACT_PURE_N_MODE) || !hwwep)//!ieee->hwsec_support) //add hwsec_support flag to totol control hw_sec on/off |
| 6416 | { |
| 6417 | ieee->hwsec_active = 0; |
| 6418 | SECR_value &= ~SCR_RxDecEnable; |
| 6419 | } |
| 6420 | |
Mike McCormack | 207b58f | 2010-08-10 23:44:26 +0900 | [diff] [blame] | 6421 | RT_TRACE(COMP_SEC,"%s:, hwsec:%d, pairwise_key:%d, SECR_value:%x\n", __FUNCTION__, |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6422 | ieee->hwsec_active, ieee->pairwise_key_type, SECR_value); |
| 6423 | { |
| 6424 | write_nic_byte(dev, SECR, SECR_value);//SECR_value | SCR_UseDK ); |
| 6425 | } |
| 6426 | |
| 6427 | } |
| 6428 | #define TOTAL_CAM_ENTRY 32 |
| 6429 | //#define CAM_CONTENT_COUNT 8 |
| 6430 | void setKey( struct net_device *dev, |
| 6431 | u8 EntryNo, |
| 6432 | u8 KeyIndex, |
| 6433 | u16 KeyType, |
Mike McCormack | 881a975 | 2010-07-26 22:58:03 +0900 | [diff] [blame] | 6434 | const u8 *MacAddr, |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6435 | u8 DefaultKey, |
| 6436 | u32 *KeyContent ) |
| 6437 | { |
| 6438 | u32 TargetCommand = 0; |
| 6439 | u32 TargetContent = 0; |
| 6440 | u16 usConfig = 0; |
| 6441 | u8 i; |
| 6442 | #ifdef ENABLE_IPS |
| 6443 | struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev); |
| 6444 | RT_RF_POWER_STATE rtState; |
| 6445 | rtState = priv->ieee80211->eRFPowerState; |
| 6446 | if(priv->ieee80211->PowerSaveControl.bInactivePs){ |
| 6447 | if(rtState == eRfOff){ |
| 6448 | if(priv->ieee80211->RfOffReason > RF_CHANGE_BY_IPS) |
| 6449 | { |
| 6450 | RT_TRACE(COMP_ERR, "%s(): RF is OFF.\n",__FUNCTION__); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 6451 | //up(&priv->wx_sem); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6452 | return ; |
| 6453 | } |
| 6454 | else{ |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 6455 | down(&priv->ieee80211->ips_sem); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6456 | IPSLeave(dev); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 6457 | up(&priv->ieee80211->ips_sem); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6458 | } |
| 6459 | } |
| 6460 | } |
| 6461 | priv->ieee80211->is_set_key = true; |
| 6462 | #endif |
| 6463 | if (EntryNo >= TOTAL_CAM_ENTRY) |
| 6464 | RT_TRACE(COMP_ERR, "cam entry exceeds in setKey()\n"); |
| 6465 | |
Joe Perches | 0ee9f67 | 2009-12-06 11:34:52 -0800 | [diff] [blame] | 6466 | RT_TRACE(COMP_SEC, "====>to setKey(), dev:%p, EntryNo:%d, KeyIndex:%d, KeyType:%d, MacAddr%pM\n", dev,EntryNo, KeyIndex, KeyType, MacAddr); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6467 | |
| 6468 | if (DefaultKey) |
| 6469 | usConfig |= BIT15 | (KeyType<<2); |
| 6470 | else |
| 6471 | usConfig |= BIT15 | (KeyType<<2) | KeyIndex; |
| 6472 | // usConfig |= BIT15 | (KeyType<<2) | (DefaultKey<<5) | KeyIndex; |
| 6473 | |
| 6474 | |
| 6475 | for(i=0 ; i<CAM_CONTENT_COUNT; i++){ |
| 6476 | TargetCommand = i+CAM_CONTENT_COUNT*EntryNo; |
| 6477 | TargetCommand |= BIT31|BIT16; |
| 6478 | |
| 6479 | if(i==0){//MAC|Config |
| 6480 | TargetContent = (u32)(*(MacAddr+0)) << 16| |
| 6481 | (u32)(*(MacAddr+1)) << 24| |
| 6482 | (u32)usConfig; |
| 6483 | |
| 6484 | write_nic_dword(dev, WCAMI, TargetContent); |
| 6485 | write_nic_dword(dev, RWCAM, TargetCommand); |
| 6486 | // printk("setkey cam =%8x\n", read_cam(dev, i+6*EntryNo)); |
| 6487 | } |
| 6488 | else if(i==1){//MAC |
| 6489 | TargetContent = (u32)(*(MacAddr+2)) | |
| 6490 | (u32)(*(MacAddr+3)) << 8| |
| 6491 | (u32)(*(MacAddr+4)) << 16| |
| 6492 | (u32)(*(MacAddr+5)) << 24; |
| 6493 | write_nic_dword(dev, WCAMI, TargetContent); |
| 6494 | write_nic_dword(dev, RWCAM, TargetCommand); |
| 6495 | } |
| 6496 | else { //Key Material |
| 6497 | if(KeyContent != NULL) |
| 6498 | { |
| 6499 | write_nic_dword(dev, WCAMI, (u32)(*(KeyContent+i-2)) ); |
| 6500 | write_nic_dword(dev, RWCAM, TargetCommand); |
| 6501 | } |
| 6502 | } |
| 6503 | } |
| 6504 | RT_TRACE(COMP_SEC,"=========>after set key, usconfig:%x\n", usConfig); |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6505 | } |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6506 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 6507 | bool NicIFEnableNIC(struct net_device* dev) |
| 6508 | { |
| 6509 | RT_STATUS init_status = RT_STATUS_SUCCESS; |
| 6510 | struct r8192_priv* priv = ieee80211_priv(dev); |
| 6511 | PRT_POWER_SAVE_CONTROL pPSC = (PRT_POWER_SAVE_CONTROL)(&(priv->ieee80211->PowerSaveControl)); |
| 6512 | |
| 6513 | //YJ,add,091109 |
| 6514 | if (priv->up == 0){ |
| 6515 | RT_TRACE(COMP_ERR, "ERR!!! %s(): Driver is already down!\n",__FUNCTION__); |
| 6516 | priv->bdisable_nic = false; //YJ,add,091111 |
| 6517 | return false; |
| 6518 | } |
| 6519 | // <1> Reset memory: descriptor, buffer,.. |
| 6520 | //NicIFResetMemory(Adapter); |
| 6521 | |
| 6522 | // <2> Enable Adapter |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 6523 | //priv->bfirst_init = true; |
| 6524 | init_status = rtl8192_adapter_start(dev); |
| 6525 | if (init_status != RT_STATUS_SUCCESS) { |
| 6526 | RT_TRACE(COMP_ERR,"ERR!!! %s(): initialization is failed!\n",__FUNCTION__); |
| 6527 | priv->bdisable_nic = false; //YJ,add,091111 |
| 6528 | return -1; |
| 6529 | } |
| 6530 | //printk("start adapter finished\n"); |
| 6531 | RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC); |
| 6532 | //priv->bfirst_init = false; |
| 6533 | |
| 6534 | // <3> Enable Interrupt |
| 6535 | rtl8192_irq_enable(dev); |
| 6536 | priv->bdisable_nic = false; |
Mike McCormack | 16d74da | 2010-09-20 23:11:14 +0900 | [diff] [blame] | 6537 | |
Mike McCormack | c6eae67 | 2010-08-10 23:45:23 +0900 | [diff] [blame] | 6538 | return (init_status == RT_STATUS_SUCCESS); |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 6539 | } |
Mike McCormack | 214985a | 2010-09-20 23:11:29 +0900 | [diff] [blame] | 6540 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 6541 | bool NicIFDisableNIC(struct net_device* dev) |
| 6542 | { |
| 6543 | bool status = true; |
| 6544 | struct r8192_priv* priv = ieee80211_priv(dev); |
| 6545 | u8 tmp_state = 0; |
| 6546 | // <1> Disable Interrupt |
Mike McCormack | 16d74da | 2010-09-20 23:11:14 +0900 | [diff] [blame] | 6547 | |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 6548 | priv->bdisable_nic = true; //YJ,move,091109 |
| 6549 | tmp_state = priv->ieee80211->state; |
| 6550 | |
| 6551 | ieee80211_softmac_stop_protocol(priv->ieee80211, false); |
| 6552 | |
| 6553 | priv->ieee80211->state = tmp_state; |
| 6554 | rtl8192_cancel_deferred_work(priv); |
| 6555 | rtl8192_irq_disable(dev); |
| 6556 | // <2> Stop all timer |
| 6557 | |
| 6558 | // <3> Disable Adapter |
| 6559 | rtl8192_halt_adapter(dev, false); |
| 6560 | // priv->bdisable_nic = true; |
david woo | 65a4378 | 2009-12-22 09:40:36 -0800 | [diff] [blame] | 6561 | |
| 6562 | return status; |
| 6563 | } |
| 6564 | |
Greg Kroah-Hartman | ecdfa44 | 2009-08-04 15:57:55 -0700 | [diff] [blame] | 6565 | module_init(rtl8192_pci_module_init); |
| 6566 | module_exit(rtl8192_pci_module_exit); |