Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2009-2010 Realtek Corporation. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., |
| 16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called LICENSE. |
| 20 | * |
| 21 | * Contact Information: |
| 22 | * wlanfae <wlanfae@realtek.com> |
| 23 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, |
| 24 | * Hsinchu 300, Taiwan. |
| 25 | * |
| 26 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | #include "core.h" |
| 31 | #include "wifi.h" |
| 32 | #include "pci.h" |
| 33 | #include "base.h" |
| 34 | #include "ps.h" |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 35 | #include "efuse.h" |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 36 | |
| 37 | static const u16 pcibridge_vendors[PCI_BRIDGE_VENDOR_MAX] = { |
| 38 | INTEL_VENDOR_ID, |
| 39 | ATI_VENDOR_ID, |
| 40 | AMD_VENDOR_ID, |
| 41 | SIS_VENDOR_ID |
| 42 | }; |
| 43 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 44 | static const u8 ac_to_hwq[] = { |
| 45 | VO_QUEUE, |
| 46 | VI_QUEUE, |
| 47 | BE_QUEUE, |
| 48 | BK_QUEUE |
| 49 | }; |
| 50 | |
| 51 | u8 _rtl_mac_to_hwqueue(struct ieee80211_hw *hw, |
| 52 | struct sk_buff *skb) |
| 53 | { |
| 54 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 55 | u16 fc = rtl_get_fc(skb); |
| 56 | u8 queue_index = skb_get_queue_mapping(skb); |
| 57 | |
| 58 | if (unlikely(ieee80211_is_beacon(fc))) |
| 59 | return BEACON_QUEUE; |
| 60 | if (ieee80211_is_mgmt(fc)) |
| 61 | return MGNT_QUEUE; |
| 62 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) |
| 63 | if (ieee80211_is_nullfunc(fc)) |
| 64 | return HIGH_QUEUE; |
| 65 | |
| 66 | return ac_to_hwq[queue_index]; |
| 67 | } |
| 68 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 69 | /* Update PCI dependent default settings*/ |
| 70 | static void _rtl_pci_update_default_setting(struct ieee80211_hw *hw) |
| 71 | { |
| 72 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 73 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 74 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 75 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 76 | u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 77 | u8 init_aspm; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 78 | |
| 79 | ppsc->reg_rfps_level = 0; |
Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 80 | ppsc->support_aspm = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 81 | |
| 82 | /*Update PCI ASPM setting */ |
| 83 | ppsc->const_amdpci_aspm = rtlpci->const_amdpci_aspm; |
| 84 | switch (rtlpci->const_pci_aspm) { |
| 85 | case 0: |
| 86 | /*No ASPM */ |
| 87 | break; |
| 88 | |
| 89 | case 1: |
| 90 | /*ASPM dynamically enabled/disable. */ |
| 91 | ppsc->reg_rfps_level |= RT_RF_LPS_LEVEL_ASPM; |
| 92 | break; |
| 93 | |
| 94 | case 2: |
| 95 | /*ASPM with Clock Req dynamically enabled/disable. */ |
| 96 | ppsc->reg_rfps_level |= (RT_RF_LPS_LEVEL_ASPM | |
| 97 | RT_RF_OFF_LEVL_CLK_REQ); |
| 98 | break; |
| 99 | |
| 100 | case 3: |
| 101 | /* |
| 102 | * Always enable ASPM and Clock Req |
| 103 | * from initialization to halt. |
| 104 | * */ |
| 105 | ppsc->reg_rfps_level &= ~(RT_RF_LPS_LEVEL_ASPM); |
| 106 | ppsc->reg_rfps_level |= (RT_RF_PS_LEVEL_ALWAYS_ASPM | |
| 107 | RT_RF_OFF_LEVL_CLK_REQ); |
| 108 | break; |
| 109 | |
| 110 | case 4: |
| 111 | /* |
| 112 | * Always enable ASPM without Clock Req |
| 113 | * from initialization to halt. |
| 114 | * */ |
| 115 | ppsc->reg_rfps_level &= ~(RT_RF_LPS_LEVEL_ASPM | |
| 116 | RT_RF_OFF_LEVL_CLK_REQ); |
| 117 | ppsc->reg_rfps_level |= RT_RF_PS_LEVEL_ALWAYS_ASPM; |
| 118 | break; |
| 119 | } |
| 120 | |
| 121 | ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_HALT_NIC; |
| 122 | |
| 123 | /*Update Radio OFF setting */ |
| 124 | switch (rtlpci->const_hwsw_rfoff_d3) { |
| 125 | case 1: |
| 126 | if (ppsc->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM) |
| 127 | ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_ASPM; |
| 128 | break; |
| 129 | |
| 130 | case 2: |
| 131 | if (ppsc->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM) |
| 132 | ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_ASPM; |
| 133 | ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_HALT_NIC; |
| 134 | break; |
| 135 | |
| 136 | case 3: |
| 137 | ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_PCI_D3; |
| 138 | break; |
| 139 | } |
| 140 | |
| 141 | /*Set HW definition to determine if it supports ASPM. */ |
| 142 | switch (rtlpci->const_support_pciaspm) { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 143 | case 0:{ |
| 144 | /*Not support ASPM. */ |
| 145 | bool support_aspm = false; |
| 146 | ppsc->support_aspm = support_aspm; |
| 147 | break; |
| 148 | } |
| 149 | case 1:{ |
| 150 | /*Support ASPM. */ |
| 151 | bool support_aspm = true; |
| 152 | bool support_backdoor = true; |
| 153 | ppsc->support_aspm = support_aspm; |
| 154 | |
| 155 | /*if (priv->oem_id == RT_CID_TOSHIBA && |
| 156 | !priv->ndis_adapter.amd_l1_patch) |
| 157 | support_backdoor = false; */ |
| 158 | |
| 159 | ppsc->support_backdoor = support_backdoor; |
| 160 | |
| 161 | break; |
| 162 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 163 | case 2: |
| 164 | /*ASPM value set by chipset. */ |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 165 | if (pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL) { |
| 166 | bool support_aspm = true; |
| 167 | ppsc->support_aspm = support_aspm; |
| 168 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 169 | break; |
| 170 | default: |
| 171 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 172 | ("switch case not process\n")); |
| 173 | break; |
| 174 | } |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 175 | |
| 176 | /* toshiba aspm issue, toshiba will set aspm selfly |
| 177 | * so we should not set aspm in driver */ |
| 178 | pci_read_config_byte(rtlpci->pdev, 0x80, &init_aspm); |
| 179 | if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8192SE && |
| 180 | init_aspm == 0x43) |
| 181 | ppsc->support_aspm = false; |
| 182 | } |
| 183 | |
| 184 | /*Disable L0s dirtectly. We will disable host L0s by default. */ |
| 185 | void rtl_pci_disable_host_l0s(struct ieee80211_hw *hw) |
| 186 | { |
| 187 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 188 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 189 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 190 | u8 pcibridge_busnum = pcipriv->ndis_adapter.pcibridge_busnum; |
| 191 | u8 pcibridge_devnum = pcipriv->ndis_adapter.pcibridge_devnum; |
| 192 | u8 pcibridge_funcnum = pcipriv->ndis_adapter.pcibridge_funcnum; |
| 193 | u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport; |
| 194 | u8 num4bytes = pcipriv->ndis_adapter.num4bytes; |
| 195 | u8 u_pcibridge_aspmsetting = 0; |
| 196 | |
| 197 | /*Read Link Control Register */ |
| 198 | rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS, |
| 199 | pcicfg_addrport + (num4bytes << 2)); |
| 200 | rtl_pci_raw_read_port_uchar(PCI_CONF_DATA, &u_pcibridge_aspmsetting); |
| 201 | |
| 202 | if (u_pcibridge_aspmsetting & BIT(0)) |
| 203 | u_pcibridge_aspmsetting &= ~(BIT(0)); |
| 204 | |
| 205 | rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS, |
| 206 | pcicfg_addrport + (num4bytes << 2)); |
| 207 | rtl_pci_raw_write_port_uchar(PCI_CONF_DATA, u_pcibridge_aspmsetting); |
| 208 | |
| 209 | udelay(50); |
| 210 | |
| 211 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, |
| 212 | ("PciBridge busnumber[%x], DevNumbe[%x], " |
| 213 | "funcnumber[%x], Write reg[%x] = %lx\n", |
| 214 | pcibridge_busnum, pcibridge_devnum, pcibridge_funcnum, |
| 215 | (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10), |
| 216 | (pcipriv->ndis_adapter.pcibridge_linkctrlreg | |
| 217 | (rtlpci->const_devicepci_aspm_setting & ~BIT(0))))); |
| 218 | } |
| 219 | |
| 220 | /*Enable rtl8192ce backdoor to control ASPM and clock request.*/ |
| 221 | bool rtl_pci_enable_back_door(struct ieee80211_hw *hw) |
| 222 | { |
| 223 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 224 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 225 | u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor; |
| 226 | bool bresult = true; |
| 227 | u8 value; |
| 228 | |
| 229 | pci_read_config_byte(rtlpci->pdev, 0x70f, &value); |
| 230 | |
| 231 | /*0x70f BIT(7) is used to control L0S */ |
| 232 | if (pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL) { |
| 233 | value |= BIT(7); |
| 234 | } else { |
| 235 | /*Set 0x70f to 0x23 when non-Intel platform. */ |
| 236 | value = 0x23; |
| 237 | } |
| 238 | |
| 239 | pci_write_config_byte(rtlpci->pdev, 0x70f, value); |
| 240 | |
| 241 | pci_read_config_byte(rtlpci->pdev, 0x719, &value); |
| 242 | /*0x719 BIT(3) is for L1 BIT(4) is for clock request */ |
| 243 | value |= (BIT(3) | BIT(4)); |
| 244 | pci_write_config_byte(rtlpci->pdev, 0x719, value); |
| 245 | |
| 246 | return bresult; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static bool _rtl_pci_platform_switch_device_pci_aspm( |
| 250 | struct ieee80211_hw *hw, |
| 251 | u8 value) |
| 252 | { |
| 253 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 254 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 255 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 256 | if (rtlhal->hw_type != HARDWARE_TYPE_RTL8192SE) |
| 257 | value |= 0x40; |
| 258 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 259 | pci_write_config_byte(rtlpci->pdev, 0x80, value); |
| 260 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 261 | return false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /*When we set 0x01 to enable clk request. Set 0x0 to disable clk req.*/ |
| 265 | static bool _rtl_pci_switch_clk_req(struct ieee80211_hw *hw, u8 value) |
| 266 | { |
| 267 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 268 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 269 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 270 | pci_write_config_byte(rtlpci->pdev, 0x81, value); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 271 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 272 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) |
| 273 | udelay(100); |
| 274 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 275 | return true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /*Disable RTL8192SE ASPM & Disable Pci Bridge ASPM*/ |
| 279 | static void rtl_pci_disable_aspm(struct ieee80211_hw *hw) |
| 280 | { |
| 281 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 282 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 283 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 284 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 285 | u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor; |
| 286 | u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport; |
| 287 | u8 num4bytes = pcipriv->ndis_adapter.num4bytes; |
| 288 | /*Retrieve original configuration settings. */ |
| 289 | u8 linkctrl_reg = pcipriv->ndis_adapter.linkctrl_reg; |
| 290 | u16 pcibridge_linkctrlreg = pcipriv->ndis_adapter. |
| 291 | pcibridge_linkctrlreg; |
| 292 | u16 aspmlevel = 0; |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 293 | u8 tmp_u1b = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 294 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 295 | if (!ppsc->support_aspm) |
| 296 | return; |
| 297 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 298 | if (pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) { |
| 299 | RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, |
| 300 | ("PCI(Bridge) UNKNOWN.\n")); |
| 301 | |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) { |
| 306 | RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_CLK_REQ); |
| 307 | _rtl_pci_switch_clk_req(hw, 0x0); |
| 308 | } |
| 309 | |
Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 310 | /*for promising device will in L0 state after an I/O. */ |
| 311 | pci_read_config_byte(rtlpci->pdev, 0x80, &tmp_u1b); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 312 | |
| 313 | /*Set corresponding value. */ |
| 314 | aspmlevel |= BIT(0) | BIT(1); |
| 315 | linkctrl_reg &= ~aspmlevel; |
| 316 | pcibridge_linkctrlreg &= ~(BIT(0) | BIT(1)); |
| 317 | |
| 318 | _rtl_pci_platform_switch_device_pci_aspm(hw, linkctrl_reg); |
| 319 | udelay(50); |
| 320 | |
| 321 | /*4 Disable Pci Bridge ASPM */ |
| 322 | rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS, |
| 323 | pcicfg_addrport + (num4bytes << 2)); |
| 324 | rtl_pci_raw_write_port_uchar(PCI_CONF_DATA, pcibridge_linkctrlreg); |
| 325 | |
| 326 | udelay(50); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* |
| 330 | *Enable RTL8192SE ASPM & Enable Pci Bridge ASPM for |
| 331 | *power saving We should follow the sequence to enable |
| 332 | *RTL8192SE first then enable Pci Bridge ASPM |
| 333 | *or the system will show bluescreen. |
| 334 | */ |
| 335 | static void rtl_pci_enable_aspm(struct ieee80211_hw *hw) |
| 336 | { |
| 337 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 338 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 339 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 340 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 341 | u8 pcibridge_busnum = pcipriv->ndis_adapter.pcibridge_busnum; |
| 342 | u8 pcibridge_devnum = pcipriv->ndis_adapter.pcibridge_devnum; |
| 343 | u8 pcibridge_funcnum = pcipriv->ndis_adapter.pcibridge_funcnum; |
| 344 | u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor; |
| 345 | u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport; |
| 346 | u8 num4bytes = pcipriv->ndis_adapter.num4bytes; |
| 347 | u16 aspmlevel; |
| 348 | u8 u_pcibridge_aspmsetting; |
| 349 | u8 u_device_aspmsetting; |
| 350 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 351 | if (!ppsc->support_aspm) |
| 352 | return; |
| 353 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 354 | if (pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) { |
| 355 | RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, |
| 356 | ("PCI(Bridge) UNKNOWN.\n")); |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | /*4 Enable Pci Bridge ASPM */ |
| 361 | rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS, |
| 362 | pcicfg_addrport + (num4bytes << 2)); |
| 363 | |
| 364 | u_pcibridge_aspmsetting = |
| 365 | pcipriv->ndis_adapter.pcibridge_linkctrlreg | |
| 366 | rtlpci->const_hostpci_aspm_setting; |
| 367 | |
| 368 | if (pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL) |
| 369 | u_pcibridge_aspmsetting &= ~BIT(0); |
| 370 | |
| 371 | rtl_pci_raw_write_port_uchar(PCI_CONF_DATA, u_pcibridge_aspmsetting); |
| 372 | |
| 373 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, |
| 374 | ("PlatformEnableASPM():PciBridge busnumber[%x], " |
| 375 | "DevNumbe[%x], funcnumber[%x], Write reg[%x] = %x\n", |
| 376 | pcibridge_busnum, pcibridge_devnum, pcibridge_funcnum, |
| 377 | (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10), |
| 378 | u_pcibridge_aspmsetting)); |
| 379 | |
| 380 | udelay(50); |
| 381 | |
| 382 | /*Get ASPM level (with/without Clock Req) */ |
| 383 | aspmlevel = rtlpci->const_devicepci_aspm_setting; |
| 384 | u_device_aspmsetting = pcipriv->ndis_adapter.linkctrl_reg; |
| 385 | |
| 386 | /*_rtl_pci_platform_switch_device_pci_aspm(dev,*/ |
| 387 | /*(priv->ndis_adapter.linkctrl_reg | ASPMLevel)); */ |
| 388 | |
| 389 | u_device_aspmsetting |= aspmlevel; |
| 390 | |
| 391 | _rtl_pci_platform_switch_device_pci_aspm(hw, u_device_aspmsetting); |
| 392 | |
| 393 | if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) { |
| 394 | _rtl_pci_switch_clk_req(hw, (ppsc->reg_rfps_level & |
| 395 | RT_RF_OFF_LEVL_CLK_REQ) ? 1 : 0); |
| 396 | RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_CLK_REQ); |
| 397 | } |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 398 | udelay(100); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | static bool rtl_pci_get_amd_l1_patch(struct ieee80211_hw *hw) |
| 402 | { |
| 403 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 404 | u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport; |
| 405 | |
| 406 | bool status = false; |
| 407 | u8 offset_e0; |
| 408 | unsigned offset_e4; |
| 409 | |
| 410 | rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS, |
| 411 | pcicfg_addrport + 0xE0); |
| 412 | rtl_pci_raw_write_port_uchar(PCI_CONF_DATA, 0xA0); |
| 413 | |
| 414 | rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS, |
| 415 | pcicfg_addrport + 0xE0); |
| 416 | rtl_pci_raw_read_port_uchar(PCI_CONF_DATA, &offset_e0); |
| 417 | |
| 418 | if (offset_e0 == 0xA0) { |
| 419 | rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS, |
| 420 | pcicfg_addrport + 0xE4); |
| 421 | rtl_pci_raw_read_port_ulong(PCI_CONF_DATA, &offset_e4); |
| 422 | if (offset_e4 & BIT(23)) |
| 423 | status = true; |
| 424 | } |
| 425 | |
| 426 | return status; |
| 427 | } |
| 428 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 429 | void rtl_pci_get_linkcontrol_field(struct ieee80211_hw *hw) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 430 | { |
| 431 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 432 | u8 capabilityoffset = pcipriv->ndis_adapter.pcibridge_pciehdr_offset; |
| 433 | u32 pcicfg_addrport = pcipriv->ndis_adapter.pcicfg_addrport; |
| 434 | u8 linkctrl_reg; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 435 | u8 num4bbytes; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 436 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 437 | num4bbytes = (capabilityoffset + 0x10) / 4; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 438 | |
| 439 | /*Read Link Control Register */ |
| 440 | rtl_pci_raw_write_port_ulong(PCI_CONF_ADDRESS, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 441 | pcicfg_addrport + (num4bbytes << 2)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 442 | rtl_pci_raw_read_port_uchar(PCI_CONF_DATA, &linkctrl_reg); |
| 443 | |
| 444 | pcipriv->ndis_adapter.pcibridge_linkctrlreg = linkctrl_reg; |
| 445 | } |
| 446 | |
| 447 | static void rtl_pci_parse_configuration(struct pci_dev *pdev, |
| 448 | struct ieee80211_hw *hw) |
| 449 | { |
| 450 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 451 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 452 | |
| 453 | u8 tmp; |
| 454 | int pos; |
| 455 | u8 linkctrl_reg; |
| 456 | |
| 457 | /*Link Control Register */ |
| 458 | pos = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
| 459 | pci_read_config_byte(pdev, pos + PCI_EXP_LNKCTL, &linkctrl_reg); |
| 460 | pcipriv->ndis_adapter.linkctrl_reg = linkctrl_reg; |
| 461 | |
| 462 | RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, |
| 463 | ("Link Control Register =%x\n", |
| 464 | pcipriv->ndis_adapter.linkctrl_reg)); |
| 465 | |
| 466 | pci_read_config_byte(pdev, 0x98, &tmp); |
| 467 | tmp |= BIT(4); |
| 468 | pci_write_config_byte(pdev, 0x98, tmp); |
| 469 | |
| 470 | tmp = 0x17; |
| 471 | pci_write_config_byte(pdev, 0x70f, tmp); |
| 472 | } |
| 473 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 474 | static void rtl_pci_init_aspm(struct ieee80211_hw *hw) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 475 | { |
| 476 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 477 | |
| 478 | _rtl_pci_update_default_setting(hw); |
| 479 | |
| 480 | if (ppsc->reg_rfps_level & RT_RF_PS_LEVEL_ALWAYS_ASPM) { |
| 481 | /*Always enable ASPM & Clock Req. */ |
| 482 | rtl_pci_enable_aspm(hw); |
| 483 | RT_SET_PS_LEVEL(ppsc, RT_RF_PS_LEVEL_ALWAYS_ASPM); |
| 484 | } |
| 485 | |
| 486 | } |
| 487 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 488 | static void _rtl_pci_io_handler_init(struct device *dev, |
| 489 | struct ieee80211_hw *hw) |
| 490 | { |
| 491 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 492 | |
| 493 | rtlpriv->io.dev = dev; |
| 494 | |
| 495 | rtlpriv->io.write8_async = pci_write8_async; |
| 496 | rtlpriv->io.write16_async = pci_write16_async; |
| 497 | rtlpriv->io.write32_async = pci_write32_async; |
| 498 | |
| 499 | rtlpriv->io.read8_sync = pci_read8_sync; |
| 500 | rtlpriv->io.read16_sync = pci_read16_sync; |
| 501 | rtlpriv->io.read32_sync = pci_read32_sync; |
| 502 | |
| 503 | } |
| 504 | |
| 505 | static void _rtl_pci_io_handler_release(struct ieee80211_hw *hw) |
| 506 | { |
| 507 | } |
| 508 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 509 | static bool _rtl_update_earlymode_info(struct ieee80211_hw *hw, |
| 510 | struct sk_buff *skb, struct rtl_tcb_desc *tcb_desc, u8 tid) |
| 511 | { |
| 512 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 513 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 514 | u8 additionlen = FCS_LEN; |
| 515 | struct sk_buff *next_skb; |
| 516 | |
| 517 | /* here open is 4, wep/tkip is 8, aes is 12*/ |
| 518 | if (info->control.hw_key) |
| 519 | additionlen += info->control.hw_key->icv_len; |
| 520 | |
| 521 | /* The most skb num is 6 */ |
| 522 | tcb_desc->empkt_num = 0; |
| 523 | spin_lock_bh(&rtlpriv->locks.waitq_lock); |
| 524 | skb_queue_walk(&rtlpriv->mac80211.skb_waitq[tid], next_skb) { |
| 525 | struct ieee80211_tx_info *next_info; |
| 526 | |
| 527 | next_info = IEEE80211_SKB_CB(next_skb); |
| 528 | if (next_info->flags & IEEE80211_TX_CTL_AMPDU) { |
| 529 | tcb_desc->empkt_len[tcb_desc->empkt_num] = |
| 530 | next_skb->len + additionlen; |
| 531 | tcb_desc->empkt_num++; |
| 532 | } else { |
| 533 | break; |
| 534 | } |
| 535 | |
| 536 | if (skb_queue_is_last(&rtlpriv->mac80211.skb_waitq[tid], |
| 537 | next_skb)) |
| 538 | break; |
| 539 | |
| 540 | if (tcb_desc->empkt_num >= 5) |
| 541 | break; |
| 542 | } |
| 543 | spin_unlock_bh(&rtlpriv->locks.waitq_lock); |
| 544 | |
| 545 | return true; |
| 546 | } |
| 547 | |
| 548 | /* just for early mode now */ |
| 549 | static void _rtl_pci_tx_chk_waitq(struct ieee80211_hw *hw) |
| 550 | { |
| 551 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 552 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 553 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 554 | struct sk_buff *skb = NULL; |
| 555 | struct ieee80211_tx_info *info = NULL; |
| 556 | int tid; /* should be int */ |
| 557 | |
| 558 | if (!rtlpriv->rtlhal.earlymode_enable) |
| 559 | return; |
| 560 | |
| 561 | /* we juse use em for BE/BK/VI/VO */ |
| 562 | for (tid = 7; tid >= 0; tid--) { |
| 563 | u8 hw_queue = ac_to_hwq[rtl_tid_to_ac(hw, tid)]; |
| 564 | struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue]; |
| 565 | while (!mac->act_scanning && |
| 566 | rtlpriv->psc.rfpwr_state == ERFON) { |
| 567 | struct rtl_tcb_desc tcb_desc; |
| 568 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); |
| 569 | |
| 570 | spin_lock_bh(&rtlpriv->locks.waitq_lock); |
| 571 | if (!skb_queue_empty(&mac->skb_waitq[tid]) && |
| 572 | (ring->entries - skb_queue_len(&ring->queue) > 5)) { |
| 573 | skb = skb_dequeue(&mac->skb_waitq[tid]); |
| 574 | } else { |
| 575 | spin_unlock_bh(&rtlpriv->locks.waitq_lock); |
| 576 | break; |
| 577 | } |
| 578 | spin_unlock_bh(&rtlpriv->locks.waitq_lock); |
| 579 | |
| 580 | /* Some macaddr can't do early mode. like |
| 581 | * multicast/broadcast/no_qos data */ |
| 582 | info = IEEE80211_SKB_CB(skb); |
| 583 | if (info->flags & IEEE80211_TX_CTL_AMPDU) |
| 584 | _rtl_update_earlymode_info(hw, skb, |
| 585 | &tcb_desc, tid); |
| 586 | |
| 587 | #if 0 /* temporary */ |
| 588 | rtlpriv->intf_ops->adapter_tx(hw, skb, &tcb_desc); |
| 589 | #endif |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 595 | static void _rtl_pci_tx_isr(struct ieee80211_hw *hw, int prio) |
| 596 | { |
| 597 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 598 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 599 | |
| 600 | struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[prio]; |
| 601 | |
| 602 | while (skb_queue_len(&ring->queue)) { |
| 603 | struct rtl_tx_desc *entry = &ring->desc[ring->idx]; |
| 604 | struct sk_buff *skb; |
| 605 | struct ieee80211_tx_info *info; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 606 | __le16 fc; |
| 607 | u8 tid; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 608 | |
| 609 | u8 own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) entry, true, |
| 610 | HW_DESC_OWN); |
| 611 | |
| 612 | /* |
| 613 | *beacon packet will only use the first |
| 614 | *descriptor defautly,and the own may not |
| 615 | *be cleared by the hardware |
| 616 | */ |
| 617 | if (own) |
| 618 | return; |
| 619 | ring->idx = (ring->idx + 1) % ring->entries; |
| 620 | |
| 621 | skb = __skb_dequeue(&ring->queue); |
| 622 | pci_unmap_single(rtlpci->pdev, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 623 | le32_to_cpu(rtlpriv->cfg->ops-> |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 624 | get_desc((u8 *) entry, true, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 625 | HW_DESC_TXBUFF_ADDR)), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 626 | skb->len, PCI_DMA_TODEVICE); |
| 627 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 628 | /* remove early mode header */ |
| 629 | if (rtlpriv->rtlhal.earlymode_enable) |
| 630 | skb_pull(skb, EM_HDR_LEN); |
| 631 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 632 | RT_TRACE(rtlpriv, (COMP_INTR | COMP_SEND), DBG_TRACE, |
| 633 | ("new ring->idx:%d, " |
| 634 | "free: skb_queue_len:%d, free: seq:%x\n", |
| 635 | ring->idx, |
| 636 | skb_queue_len(&ring->queue), |
| 637 | *(u16 *) (skb->data + 22))); |
| 638 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 639 | if (prio == TXCMD_QUEUE) { |
| 640 | dev_kfree_skb(skb); |
| 641 | goto tx_status_ok; |
| 642 | |
| 643 | } |
| 644 | |
| 645 | /* for sw LPS, just after NULL skb send out, we can |
| 646 | * sure AP kown we are sleeped, our we should not let |
| 647 | * rf to sleep*/ |
| 648 | fc = rtl_get_fc(skb); |
| 649 | if (ieee80211_is_nullfunc(fc)) { |
| 650 | if (ieee80211_has_pm(fc)) { |
| 651 | rtlpriv->mac80211.offchan_deley = true; |
| 652 | rtlpriv->psc.state_inap = 1; |
| 653 | } else { |
| 654 | rtlpriv->psc.state_inap = 0; |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | /* update tid tx pkt num */ |
| 659 | tid = rtl_get_tid(skb); |
| 660 | if (tid <= 7) |
| 661 | rtlpriv->link_info.tidtx_inperiod[tid]++; |
| 662 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 663 | info = IEEE80211_SKB_CB(skb); |
| 664 | ieee80211_tx_info_clear_status(info); |
| 665 | |
| 666 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 667 | /*info->status.rates[0].count = 1; */ |
| 668 | |
| 669 | ieee80211_tx_status_irqsafe(hw, skb); |
| 670 | |
| 671 | if ((ring->entries - skb_queue_len(&ring->queue)) |
| 672 | == 2) { |
| 673 | |
| 674 | RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD, |
| 675 | ("more desc left, wake" |
| 676 | "skb_queue@%d,ring->idx = %d," |
| 677 | "skb_queue_len = 0x%d\n", |
| 678 | prio, ring->idx, |
| 679 | skb_queue_len(&ring->queue))); |
| 680 | |
| 681 | ieee80211_wake_queue(hw, |
| 682 | skb_get_queue_mapping |
| 683 | (skb)); |
| 684 | } |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 685 | tx_status_ok: |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 686 | skb = NULL; |
| 687 | } |
| 688 | |
| 689 | if (((rtlpriv->link_info.num_rx_inperiod + |
| 690 | rtlpriv->link_info.num_tx_inperiod) > 8) || |
| 691 | (rtlpriv->link_info.num_rx_inperiod > 2)) { |
| 692 | rtl_lps_leave(hw); |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw) |
| 697 | { |
| 698 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 699 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 700 | int rx_queue_idx = RTL_PCI_RX_MPDU_QUEUE; |
| 701 | |
| 702 | struct ieee80211_rx_status rx_status = { 0 }; |
| 703 | unsigned int count = rtlpci->rxringcount; |
| 704 | u8 own; |
| 705 | u8 tmp_one; |
| 706 | u32 bufferaddress; |
| 707 | bool unicast = false; |
| 708 | |
| 709 | struct rtl_stats stats = { |
| 710 | .signal = 0, |
| 711 | .noise = -98, |
| 712 | .rate = 0, |
| 713 | }; |
| 714 | |
| 715 | /*RX NORMAL PKT */ |
| 716 | while (count--) { |
| 717 | /*rx descriptor */ |
| 718 | struct rtl_rx_desc *pdesc = &rtlpci->rx_ring[rx_queue_idx].desc[ |
| 719 | rtlpci->rx_ring[rx_queue_idx].idx]; |
| 720 | /*rx pkt */ |
| 721 | struct sk_buff *skb = rtlpci->rx_ring[rx_queue_idx].rx_buf[ |
| 722 | rtlpci->rx_ring[rx_queue_idx].idx]; |
| 723 | |
| 724 | own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) pdesc, |
| 725 | false, HW_DESC_OWN); |
| 726 | |
| 727 | if (own) { |
| 728 | /*wait data to be filled by hardware */ |
| 729 | return; |
| 730 | } else { |
| 731 | struct ieee80211_hdr *hdr; |
Larry Finger | 17c9ac6 | 2011-02-19 16:29:57 -0600 | [diff] [blame] | 732 | __le16 fc; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 733 | struct sk_buff *new_skb = NULL; |
| 734 | |
| 735 | rtlpriv->cfg->ops->query_rx_desc(hw, &stats, |
| 736 | &rx_status, |
| 737 | (u8 *) pdesc, skb); |
| 738 | |
| 739 | pci_unmap_single(rtlpci->pdev, |
| 740 | *((dma_addr_t *) skb->cb), |
| 741 | rtlpci->rxbuffersize, |
| 742 | PCI_DMA_FROMDEVICE); |
| 743 | |
| 744 | skb_put(skb, rtlpriv->cfg->ops->get_desc((u8 *) pdesc, |
| 745 | false, |
| 746 | HW_DESC_RXPKT_LEN)); |
| 747 | skb_reserve(skb, |
| 748 | stats.rx_drvinfo_size + stats.rx_bufshift); |
| 749 | |
| 750 | /* |
| 751 | *NOTICE This can not be use for mac80211, |
| 752 | *this is done in mac80211 code, |
| 753 | *if you done here sec DHCP will fail |
| 754 | *skb_trim(skb, skb->len - 4); |
| 755 | */ |
| 756 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 757 | hdr = rtl_get_hdr(skb); |
| 758 | fc = rtl_get_fc(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 759 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 760 | if (!stats.crc || !stats.hwerror) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 761 | memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, |
| 762 | sizeof(rx_status)); |
| 763 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 764 | if (is_broadcast_ether_addr(hdr->addr1)) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 765 | ;/*TODO*/ |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 766 | } else if (is_multicast_ether_addr(hdr->addr1)) { |
| 767 | ;/*TODO*/ |
| 768 | } else { |
| 769 | unicast = true; |
| 770 | rtlpriv->stats.rxbytesunicast += |
| 771 | skb->len; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | rtl_is_special_data(hw, skb, false); |
| 775 | |
| 776 | if (ieee80211_is_data(fc)) { |
| 777 | rtlpriv->cfg->ops->led_control(hw, |
| 778 | LED_CTL_RX); |
| 779 | |
| 780 | if (unicast) |
| 781 | rtlpriv->link_info. |
| 782 | num_rx_inperiod++; |
| 783 | } |
| 784 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 785 | /* for sw lps */ |
| 786 | rtl_swlps_beacon(hw, (void *)skb->data, |
| 787 | skb->len); |
| 788 | rtl_recognize_peer(hw, (void *)skb->data, |
| 789 | skb->len); |
| 790 | if ((rtlpriv->mac80211.opmode == |
| 791 | NL80211_IFTYPE_AP) && |
| 792 | (rtlpriv->rtlhal.current_bandtype == |
| 793 | BAND_ON_2_4G) && |
| 794 | (ieee80211_is_beacon(fc) || |
| 795 | ieee80211_is_probe_resp(fc))) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 796 | dev_kfree_skb_any(skb); |
Chaoming Li | 5c4bc1c | 2010-12-22 10:56:02 -0600 | [diff] [blame] | 797 | } else { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 798 | if (unlikely(!rtl_action_proc(hw, skb, |
| 799 | false))) { |
| 800 | dev_kfree_skb_any(skb); |
| 801 | } else { |
| 802 | struct sk_buff *uskb = NULL; |
| 803 | u8 *pdata; |
| 804 | uskb = dev_alloc_skb(skb->len |
| 805 | + 128); |
| 806 | memcpy(IEEE80211_SKB_RXCB(uskb), |
| 807 | &rx_status, |
| 808 | sizeof(rx_status)); |
| 809 | pdata = (u8 *)skb_put(uskb, |
| 810 | skb->len); |
| 811 | memcpy(pdata, skb->data, |
| 812 | skb->len); |
| 813 | dev_kfree_skb_any(skb); |
Chaoming Li | 5c4bc1c | 2010-12-22 10:56:02 -0600 | [diff] [blame] | 814 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 815 | ieee80211_rx_irqsafe(hw, uskb); |
| 816 | } |
Chaoming Li | 5c4bc1c | 2010-12-22 10:56:02 -0600 | [diff] [blame] | 817 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 818 | } else { |
| 819 | dev_kfree_skb_any(skb); |
| 820 | } |
| 821 | |
| 822 | if (((rtlpriv->link_info.num_rx_inperiod + |
| 823 | rtlpriv->link_info.num_tx_inperiod) > 8) || |
| 824 | (rtlpriv->link_info.num_rx_inperiod > 2)) { |
| 825 | rtl_lps_leave(hw); |
| 826 | } |
| 827 | |
| 828 | new_skb = dev_alloc_skb(rtlpci->rxbuffersize); |
| 829 | if (unlikely(!new_skb)) { |
| 830 | RT_TRACE(rtlpriv, (COMP_INTR | COMP_RECV), |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 831 | DBG_DMESG, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 832 | ("can't alloc skb for rx\n")); |
| 833 | goto done; |
| 834 | } |
| 835 | skb = new_skb; |
| 836 | /*skb->dev = dev; */ |
| 837 | |
| 838 | rtlpci->rx_ring[rx_queue_idx].rx_buf[rtlpci-> |
| 839 | rx_ring |
| 840 | [rx_queue_idx]. |
| 841 | idx] = skb; |
| 842 | *((dma_addr_t *) skb->cb) = |
| 843 | pci_map_single(rtlpci->pdev, skb_tail_pointer(skb), |
| 844 | rtlpci->rxbuffersize, |
| 845 | PCI_DMA_FROMDEVICE); |
| 846 | |
| 847 | } |
| 848 | done: |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 849 | bufferaddress = cpu_to_le32(*((dma_addr_t *)skb->cb)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 850 | tmp_one = 1; |
| 851 | rtlpriv->cfg->ops->set_desc((u8 *) pdesc, false, |
| 852 | HW_DESC_RXBUFF_ADDR, |
| 853 | (u8 *)&bufferaddress); |
| 854 | rtlpriv->cfg->ops->set_desc((u8 *)pdesc, false, HW_DESC_RXOWN, |
| 855 | (u8 *)&tmp_one); |
| 856 | rtlpriv->cfg->ops->set_desc((u8 *)pdesc, false, |
| 857 | HW_DESC_RXPKT_LEN, |
| 858 | (u8 *)&rtlpci->rxbuffersize); |
| 859 | |
| 860 | if (rtlpci->rx_ring[rx_queue_idx].idx == |
| 861 | rtlpci->rxringcount - 1) |
| 862 | rtlpriv->cfg->ops->set_desc((u8 *)pdesc, false, |
| 863 | HW_DESC_RXERO, |
| 864 | (u8 *)&tmp_one); |
| 865 | |
| 866 | rtlpci->rx_ring[rx_queue_idx].idx = |
| 867 | (rtlpci->rx_ring[rx_queue_idx].idx + 1) % |
| 868 | rtlpci->rxringcount; |
| 869 | } |
| 870 | |
| 871 | } |
| 872 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 873 | void _rtl_pci_tx_interrupt(struct ieee80211_hw *hw) |
| 874 | { |
| 875 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 876 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 877 | int prio; |
| 878 | |
| 879 | for (prio = 0; prio < RTL_PCI_MAX_TX_QUEUE_COUNT; prio++) { |
| 880 | struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[prio]; |
| 881 | |
| 882 | while (skb_queue_len(&ring->queue)) { |
| 883 | struct rtl_tx_desc *entry = &ring->desc[ring->idx]; |
| 884 | struct sk_buff *skb; |
| 885 | struct ieee80211_tx_info *info; |
| 886 | u8 own; |
| 887 | |
| 888 | /* |
| 889 | *beacon packet will only use the first |
| 890 | *descriptor defautly, and the own may not |
| 891 | *be cleared by the hardware, and |
| 892 | *beacon will free in prepare beacon |
| 893 | */ |
| 894 | if (prio == BEACON_QUEUE || prio == TXCMD_QUEUE || |
| 895 | prio == HCCA_QUEUE) |
| 896 | break; |
| 897 | |
| 898 | own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) entry, |
| 899 | true, |
| 900 | HW_DESC_OWN); |
| 901 | |
| 902 | if (own) |
| 903 | break; |
| 904 | |
| 905 | skb = __skb_dequeue(&ring->queue); |
| 906 | pci_unmap_single(rtlpci->pdev, |
| 907 | le32_to_cpu(rtlpriv->cfg->ops-> |
| 908 | get_desc((u8 *) entry, |
| 909 | true, |
| 910 | HW_DESC_TXBUFF_ADDR)), |
| 911 | skb->len, PCI_DMA_TODEVICE); |
| 912 | |
| 913 | ring->idx = (ring->idx + 1) % ring->entries; |
| 914 | |
| 915 | info = IEEE80211_SKB_CB(skb); |
| 916 | ieee80211_tx_info_clear_status(info); |
| 917 | |
| 918 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 919 | /*info->status.rates[0].count = 1; */ |
| 920 | |
| 921 | ieee80211_tx_status_irqsafe(hw, skb); |
| 922 | |
| 923 | if ((ring->entries - skb_queue_len(&ring->queue)) |
| 924 | == 2 && prio != BEACON_QUEUE) { |
| 925 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 926 | ("more desc left, wake " |
| 927 | "skb_queue@%d,ring->idx = %d," |
| 928 | "skb_queue_len = 0x%d\n", |
| 929 | prio, ring->idx, |
| 930 | skb_queue_len(&ring->queue))); |
| 931 | |
| 932 | ieee80211_wake_queue(hw, |
| 933 | skb_get_queue_mapping |
| 934 | (skb)); |
| 935 | } |
| 936 | |
| 937 | skb = NULL; |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 942 | static irqreturn_t _rtl_pci_interrupt(int irq, void *dev_id) |
| 943 | { |
| 944 | struct ieee80211_hw *hw = dev_id; |
| 945 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 946 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 947 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 948 | unsigned long flags; |
| 949 | u32 inta = 0; |
| 950 | u32 intb = 0; |
| 951 | |
| 952 | if (rtlpci->irq_enabled == 0) |
| 953 | return IRQ_HANDLED; |
| 954 | |
| 955 | spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags); |
| 956 | |
| 957 | /*read ISR: 4/8bytes */ |
| 958 | rtlpriv->cfg->ops->interrupt_recognized(hw, &inta, &intb); |
| 959 | |
| 960 | /*Shared IRQ or HW disappared */ |
| 961 | if (!inta || inta == 0xffff) |
| 962 | goto done; |
| 963 | |
| 964 | /*<1> beacon related */ |
| 965 | if (inta & rtlpriv->cfg->maps[RTL_IMR_TBDOK]) { |
| 966 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 967 | ("beacon ok interrupt!\n")); |
| 968 | } |
| 969 | |
| 970 | if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_TBDER])) { |
| 971 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 972 | ("beacon err interrupt!\n")); |
| 973 | } |
| 974 | |
| 975 | if (inta & rtlpriv->cfg->maps[RTL_IMR_BDOK]) { |
| 976 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 977 | ("beacon interrupt!\n")); |
| 978 | } |
| 979 | |
| 980 | if (inta & rtlpriv->cfg->maps[RTL_IMR_BcnInt]) { |
| 981 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 982 | ("prepare beacon for interrupt!\n")); |
| 983 | tasklet_schedule(&rtlpriv->works.irq_prepare_bcn_tasklet); |
| 984 | } |
| 985 | |
| 986 | /*<3> Tx related */ |
| 987 | if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_TXFOVW])) |
| 988 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, ("IMR_TXFOVW!\n")); |
| 989 | |
| 990 | if (inta & rtlpriv->cfg->maps[RTL_IMR_MGNTDOK]) { |
| 991 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 992 | ("Manage ok interrupt!\n")); |
| 993 | _rtl_pci_tx_isr(hw, MGNT_QUEUE); |
| 994 | } |
| 995 | |
| 996 | if (inta & rtlpriv->cfg->maps[RTL_IMR_HIGHDOK]) { |
| 997 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 998 | ("HIGH_QUEUE ok interrupt!\n")); |
| 999 | _rtl_pci_tx_isr(hw, HIGH_QUEUE); |
| 1000 | } |
| 1001 | |
| 1002 | if (inta & rtlpriv->cfg->maps[RTL_IMR_BKDOK]) { |
| 1003 | rtlpriv->link_info.num_tx_inperiod++; |
| 1004 | |
| 1005 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 1006 | ("BK Tx OK interrupt!\n")); |
| 1007 | _rtl_pci_tx_isr(hw, BK_QUEUE); |
| 1008 | } |
| 1009 | |
| 1010 | if (inta & rtlpriv->cfg->maps[RTL_IMR_BEDOK]) { |
| 1011 | rtlpriv->link_info.num_tx_inperiod++; |
| 1012 | |
| 1013 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 1014 | ("BE TX OK interrupt!\n")); |
| 1015 | _rtl_pci_tx_isr(hw, BE_QUEUE); |
| 1016 | } |
| 1017 | |
| 1018 | if (inta & rtlpriv->cfg->maps[RTL_IMR_VIDOK]) { |
| 1019 | rtlpriv->link_info.num_tx_inperiod++; |
| 1020 | |
| 1021 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 1022 | ("VI TX OK interrupt!\n")); |
| 1023 | _rtl_pci_tx_isr(hw, VI_QUEUE); |
| 1024 | } |
| 1025 | |
| 1026 | if (inta & rtlpriv->cfg->maps[RTL_IMR_VODOK]) { |
| 1027 | rtlpriv->link_info.num_tx_inperiod++; |
| 1028 | |
| 1029 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 1030 | ("Vo TX OK interrupt!\n")); |
| 1031 | _rtl_pci_tx_isr(hw, VO_QUEUE); |
| 1032 | } |
| 1033 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1034 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) { |
| 1035 | if (inta & rtlpriv->cfg->maps[RTL_IMR_COMDOK]) { |
| 1036 | rtlpriv->link_info.num_tx_inperiod++; |
| 1037 | |
| 1038 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 1039 | ("CMD TX OK interrupt!\n")); |
| 1040 | _rtl_pci_tx_isr(hw, TXCMD_QUEUE); |
| 1041 | } |
| 1042 | } |
| 1043 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1044 | /*<2> Rx related */ |
| 1045 | if (inta & rtlpriv->cfg->maps[RTL_IMR_ROK]) { |
| 1046 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, ("Rx ok interrupt!\n")); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1047 | _rtl_pci_rx_interrupt(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_RDU])) { |
| 1051 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
| 1052 | ("rx descriptor unavailable!\n")); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1053 | _rtl_pci_rx_interrupt(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_RXFOVW])) { |
| 1057 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, ("rx overflow !\n")); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1058 | _rtl_pci_rx_interrupt(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1059 | } |
| 1060 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1061 | if (rtlpriv->rtlhal.earlymode_enable) |
| 1062 | tasklet_schedule(&rtlpriv->works.irq_tasklet); |
| 1063 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1064 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); |
| 1065 | return IRQ_HANDLED; |
| 1066 | |
| 1067 | done: |
| 1068 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); |
| 1069 | return IRQ_HANDLED; |
| 1070 | } |
| 1071 | |
| 1072 | static void _rtl_pci_irq_tasklet(struct ieee80211_hw *hw) |
| 1073 | { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1074 | _rtl_pci_tx_chk_waitq(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw *hw) |
| 1078 | { |
| 1079 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1080 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1081 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1082 | struct rtl8192_tx_ring *ring = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1083 | struct ieee80211_hdr *hdr = NULL; |
| 1084 | struct ieee80211_tx_info *info = NULL; |
| 1085 | struct sk_buff *pskb = NULL; |
| 1086 | struct rtl_tx_desc *pdesc = NULL; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1087 | struct rtl_tcb_desc tcb_desc; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1088 | u8 temp_one = 1; |
| 1089 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1090 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1091 | ring = &rtlpci->tx_ring[BEACON_QUEUE]; |
| 1092 | pskb = __skb_dequeue(&ring->queue); |
| 1093 | if (pskb) |
| 1094 | kfree_skb(pskb); |
| 1095 | |
| 1096 | /*NB: the beacon data buffer must be 32-bit aligned. */ |
| 1097 | pskb = ieee80211_beacon_get(hw, mac->vif); |
| 1098 | if (pskb == NULL) |
| 1099 | return; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1100 | hdr = rtl_get_hdr(pskb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1101 | info = IEEE80211_SKB_CB(pskb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1102 | pdesc = &ring->desc[0]; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1103 | #if 0 /* temporary */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1104 | rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *) pdesc, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1105 | info, pskb, BEACON_QUEUE, &tcb_desc); |
| 1106 | #endif |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1107 | |
| 1108 | __skb_queue_tail(&ring->queue, pskb); |
| 1109 | |
| 1110 | rtlpriv->cfg->ops->set_desc((u8 *) pdesc, true, HW_DESC_OWN, |
| 1111 | (u8 *)&temp_one); |
| 1112 | |
| 1113 | return; |
| 1114 | } |
| 1115 | |
| 1116 | static void _rtl_pci_init_trx_var(struct ieee80211_hw *hw) |
| 1117 | { |
| 1118 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1119 | u8 i; |
| 1120 | |
| 1121 | for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) |
| 1122 | rtlpci->txringcount[i] = RT_TXDESC_NUM; |
| 1123 | |
| 1124 | /* |
| 1125 | *we just alloc 2 desc for beacon queue, |
| 1126 | *because we just need first desc in hw beacon. |
| 1127 | */ |
| 1128 | rtlpci->txringcount[BEACON_QUEUE] = 2; |
| 1129 | |
| 1130 | /* |
| 1131 | *BE queue need more descriptor for performance |
| 1132 | *consideration or, No more tx desc will happen, |
| 1133 | *and may cause mac80211 mem leakage. |
| 1134 | */ |
| 1135 | rtlpci->txringcount[BE_QUEUE] = RT_TXDESC_NUM_BE_QUEUE; |
| 1136 | |
| 1137 | rtlpci->rxbuffersize = 9100; /*2048/1024; */ |
| 1138 | rtlpci->rxringcount = RTL_PCI_MAX_RX_COUNT; /*64; */ |
| 1139 | } |
| 1140 | |
| 1141 | static void _rtl_pci_init_struct(struct ieee80211_hw *hw, |
| 1142 | struct pci_dev *pdev) |
| 1143 | { |
| 1144 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1145 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1146 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1147 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1148 | |
| 1149 | rtlpci->up_first_time = true; |
| 1150 | rtlpci->being_init_adapter = false; |
| 1151 | |
| 1152 | rtlhal->hw = hw; |
| 1153 | rtlpci->pdev = pdev; |
| 1154 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1155 | /*Tx/Rx related var */ |
| 1156 | _rtl_pci_init_trx_var(hw); |
| 1157 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1158 | /*IBSS*/ mac->beacon_interval = 100; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1159 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1160 | /*AMPDU*/ |
| 1161 | mac->min_space_cfg = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1162 | mac->max_mss_density = 0; |
| 1163 | /*set sane AMPDU defaults */ |
| 1164 | mac->current_ampdu_density = 7; |
| 1165 | mac->current_ampdu_factor = 3; |
| 1166 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1167 | /*QOS*/ |
| 1168 | rtlpci->acm_method = eAcmWay2_SW; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1169 | |
| 1170 | /*task */ |
| 1171 | tasklet_init(&rtlpriv->works.irq_tasklet, |
| 1172 | (void (*)(unsigned long))_rtl_pci_irq_tasklet, |
| 1173 | (unsigned long)hw); |
| 1174 | tasklet_init(&rtlpriv->works.irq_prepare_bcn_tasklet, |
| 1175 | (void (*)(unsigned long))_rtl_pci_prepare_bcn_tasklet, |
| 1176 | (unsigned long)hw); |
| 1177 | } |
| 1178 | |
| 1179 | static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw, |
| 1180 | unsigned int prio, unsigned int entries) |
| 1181 | { |
| 1182 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1183 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1184 | struct rtl_tx_desc *ring; |
| 1185 | dma_addr_t dma; |
| 1186 | u32 nextdescaddress; |
| 1187 | int i; |
| 1188 | |
| 1189 | ring = pci_alloc_consistent(rtlpci->pdev, |
| 1190 | sizeof(*ring) * entries, &dma); |
| 1191 | |
| 1192 | if (!ring || (unsigned long)ring & 0xFF) { |
| 1193 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 1194 | ("Cannot allocate TX ring (prio = %d)\n", prio)); |
| 1195 | return -ENOMEM; |
| 1196 | } |
| 1197 | |
| 1198 | memset(ring, 0, sizeof(*ring) * entries); |
| 1199 | rtlpci->tx_ring[prio].desc = ring; |
| 1200 | rtlpci->tx_ring[prio].dma = dma; |
| 1201 | rtlpci->tx_ring[prio].idx = 0; |
| 1202 | rtlpci->tx_ring[prio].entries = entries; |
| 1203 | skb_queue_head_init(&rtlpci->tx_ring[prio].queue); |
| 1204 | |
| 1205 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, |
| 1206 | ("queue:%d, ring_addr:%p\n", prio, ring)); |
| 1207 | |
| 1208 | for (i = 0; i < entries; i++) { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1209 | nextdescaddress = cpu_to_le32((u32) dma + |
| 1210 | ((i + 11) % entries) * |
| 1211 | sizeof(*ring)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1212 | |
| 1213 | rtlpriv->cfg->ops->set_desc((u8 *)&(ring[i]), |
| 1214 | true, HW_DESC_TX_NEXTDESC_ADDR, |
| 1215 | (u8 *)&nextdescaddress); |
| 1216 | } |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
| 1220 | |
| 1221 | static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw) |
| 1222 | { |
| 1223 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1224 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1225 | struct rtl_rx_desc *entry = NULL; |
| 1226 | int i, rx_queue_idx; |
| 1227 | u8 tmp_one = 1; |
| 1228 | |
| 1229 | /* |
| 1230 | *rx_queue_idx 0:RX_MPDU_QUEUE |
| 1231 | *rx_queue_idx 1:RX_CMD_QUEUE |
| 1232 | */ |
| 1233 | for (rx_queue_idx = 0; rx_queue_idx < RTL_PCI_MAX_RX_QUEUE; |
| 1234 | rx_queue_idx++) { |
| 1235 | rtlpci->rx_ring[rx_queue_idx].desc = |
| 1236 | pci_alloc_consistent(rtlpci->pdev, |
| 1237 | sizeof(*rtlpci->rx_ring[rx_queue_idx]. |
| 1238 | desc) * rtlpci->rxringcount, |
| 1239 | &rtlpci->rx_ring[rx_queue_idx].dma); |
| 1240 | |
| 1241 | if (!rtlpci->rx_ring[rx_queue_idx].desc || |
| 1242 | (unsigned long)rtlpci->rx_ring[rx_queue_idx].desc & 0xFF) { |
| 1243 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 1244 | ("Cannot allocate RX ring\n")); |
| 1245 | return -ENOMEM; |
| 1246 | } |
| 1247 | |
| 1248 | memset(rtlpci->rx_ring[rx_queue_idx].desc, 0, |
| 1249 | sizeof(*rtlpci->rx_ring[rx_queue_idx].desc) * |
| 1250 | rtlpci->rxringcount); |
| 1251 | |
| 1252 | rtlpci->rx_ring[rx_queue_idx].idx = 0; |
| 1253 | |
| 1254 | for (i = 0; i < rtlpci->rxringcount; i++) { |
| 1255 | struct sk_buff *skb = |
| 1256 | dev_alloc_skb(rtlpci->rxbuffersize); |
| 1257 | u32 bufferaddress; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1258 | if (!skb) |
| 1259 | return 0; |
Jesper Juhl | bdc4bf65 | 2011-01-21 13:40:54 -0600 | [diff] [blame] | 1260 | entry = &rtlpci->rx_ring[rx_queue_idx].desc[i]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1261 | |
| 1262 | /*skb->dev = dev; */ |
| 1263 | |
| 1264 | rtlpci->rx_ring[rx_queue_idx].rx_buf[i] = skb; |
| 1265 | |
| 1266 | /* |
| 1267 | *just set skb->cb to mapping addr |
| 1268 | *for pci_unmap_single use |
| 1269 | */ |
| 1270 | *((dma_addr_t *) skb->cb) = |
| 1271 | pci_map_single(rtlpci->pdev, skb_tail_pointer(skb), |
| 1272 | rtlpci->rxbuffersize, |
| 1273 | PCI_DMA_FROMDEVICE); |
| 1274 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1275 | bufferaddress = cpu_to_le32(*((dma_addr_t *)skb->cb)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1276 | rtlpriv->cfg->ops->set_desc((u8 *)entry, false, |
| 1277 | HW_DESC_RXBUFF_ADDR, |
| 1278 | (u8 *)&bufferaddress); |
| 1279 | rtlpriv->cfg->ops->set_desc((u8 *)entry, false, |
| 1280 | HW_DESC_RXPKT_LEN, |
| 1281 | (u8 *)&rtlpci-> |
| 1282 | rxbuffersize); |
| 1283 | rtlpriv->cfg->ops->set_desc((u8 *) entry, false, |
| 1284 | HW_DESC_RXOWN, |
| 1285 | (u8 *)&tmp_one); |
| 1286 | } |
| 1287 | |
| 1288 | rtlpriv->cfg->ops->set_desc((u8 *) entry, false, |
| 1289 | HW_DESC_RXERO, (u8 *)&tmp_one); |
| 1290 | } |
| 1291 | return 0; |
| 1292 | } |
| 1293 | |
| 1294 | static void _rtl_pci_free_tx_ring(struct ieee80211_hw *hw, |
| 1295 | unsigned int prio) |
| 1296 | { |
| 1297 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1298 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1299 | struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[prio]; |
| 1300 | |
| 1301 | while (skb_queue_len(&ring->queue)) { |
| 1302 | struct rtl_tx_desc *entry = &ring->desc[ring->idx]; |
| 1303 | struct sk_buff *skb = __skb_dequeue(&ring->queue); |
| 1304 | |
| 1305 | pci_unmap_single(rtlpci->pdev, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1306 | le32_to_cpu(rtlpriv->cfg-> |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1307 | ops->get_desc((u8 *) entry, true, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1308 | HW_DESC_TXBUFF_ADDR)), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1309 | skb->len, PCI_DMA_TODEVICE); |
| 1310 | kfree_skb(skb); |
| 1311 | ring->idx = (ring->idx + 1) % ring->entries; |
| 1312 | } |
| 1313 | |
| 1314 | pci_free_consistent(rtlpci->pdev, |
| 1315 | sizeof(*ring->desc) * ring->entries, |
| 1316 | ring->desc, ring->dma); |
| 1317 | ring->desc = NULL; |
| 1318 | } |
| 1319 | |
| 1320 | static void _rtl_pci_free_rx_ring(struct rtl_pci *rtlpci) |
| 1321 | { |
| 1322 | int i, rx_queue_idx; |
| 1323 | |
| 1324 | /*rx_queue_idx 0:RX_MPDU_QUEUE */ |
| 1325 | /*rx_queue_idx 1:RX_CMD_QUEUE */ |
| 1326 | for (rx_queue_idx = 0; rx_queue_idx < RTL_PCI_MAX_RX_QUEUE; |
| 1327 | rx_queue_idx++) { |
| 1328 | for (i = 0; i < rtlpci->rxringcount; i++) { |
| 1329 | struct sk_buff *skb = |
| 1330 | rtlpci->rx_ring[rx_queue_idx].rx_buf[i]; |
| 1331 | if (!skb) |
| 1332 | continue; |
| 1333 | |
| 1334 | pci_unmap_single(rtlpci->pdev, |
| 1335 | *((dma_addr_t *) skb->cb), |
| 1336 | rtlpci->rxbuffersize, |
| 1337 | PCI_DMA_FROMDEVICE); |
| 1338 | kfree_skb(skb); |
| 1339 | } |
| 1340 | |
| 1341 | pci_free_consistent(rtlpci->pdev, |
| 1342 | sizeof(*rtlpci->rx_ring[rx_queue_idx]. |
| 1343 | desc) * rtlpci->rxringcount, |
| 1344 | rtlpci->rx_ring[rx_queue_idx].desc, |
| 1345 | rtlpci->rx_ring[rx_queue_idx].dma); |
| 1346 | rtlpci->rx_ring[rx_queue_idx].desc = NULL; |
| 1347 | } |
| 1348 | } |
| 1349 | |
| 1350 | static int _rtl_pci_init_trx_ring(struct ieee80211_hw *hw) |
| 1351 | { |
| 1352 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1353 | int ret; |
| 1354 | int i; |
| 1355 | |
| 1356 | ret = _rtl_pci_init_rx_ring(hw); |
| 1357 | if (ret) |
| 1358 | return ret; |
| 1359 | |
| 1360 | for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) { |
| 1361 | ret = _rtl_pci_init_tx_ring(hw, i, |
| 1362 | rtlpci->txringcount[i]); |
| 1363 | if (ret) |
| 1364 | goto err_free_rings; |
| 1365 | } |
| 1366 | |
| 1367 | return 0; |
| 1368 | |
| 1369 | err_free_rings: |
| 1370 | _rtl_pci_free_rx_ring(rtlpci); |
| 1371 | |
| 1372 | for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) |
| 1373 | if (rtlpci->tx_ring[i].desc) |
| 1374 | _rtl_pci_free_tx_ring(hw, i); |
| 1375 | |
| 1376 | return 1; |
| 1377 | } |
| 1378 | |
| 1379 | static int _rtl_pci_deinit_trx_ring(struct ieee80211_hw *hw) |
| 1380 | { |
| 1381 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1382 | u32 i; |
| 1383 | |
| 1384 | /*free rx rings */ |
| 1385 | _rtl_pci_free_rx_ring(rtlpci); |
| 1386 | |
| 1387 | /*free tx rings */ |
| 1388 | for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) |
| 1389 | _rtl_pci_free_tx_ring(hw, i); |
| 1390 | |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
| 1394 | int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw) |
| 1395 | { |
| 1396 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1397 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1398 | int i, rx_queue_idx; |
| 1399 | unsigned long flags; |
| 1400 | u8 tmp_one = 1; |
| 1401 | |
| 1402 | /*rx_queue_idx 0:RX_MPDU_QUEUE */ |
| 1403 | /*rx_queue_idx 1:RX_CMD_QUEUE */ |
| 1404 | for (rx_queue_idx = 0; rx_queue_idx < RTL_PCI_MAX_RX_QUEUE; |
| 1405 | rx_queue_idx++) { |
| 1406 | /* |
| 1407 | *force the rx_ring[RX_MPDU_QUEUE/ |
| 1408 | *RX_CMD_QUEUE].idx to the first one |
| 1409 | */ |
| 1410 | if (rtlpci->rx_ring[rx_queue_idx].desc) { |
| 1411 | struct rtl_rx_desc *entry = NULL; |
| 1412 | |
| 1413 | for (i = 0; i < rtlpci->rxringcount; i++) { |
| 1414 | entry = &rtlpci->rx_ring[rx_queue_idx].desc[i]; |
| 1415 | rtlpriv->cfg->ops->set_desc((u8 *) entry, |
| 1416 | false, |
| 1417 | HW_DESC_RXOWN, |
| 1418 | (u8 *)&tmp_one); |
| 1419 | } |
| 1420 | rtlpci->rx_ring[rx_queue_idx].idx = 0; |
| 1421 | } |
| 1422 | } |
| 1423 | |
| 1424 | /* |
| 1425 | *after reset, release previous pending packet, |
| 1426 | *and force the tx idx to the first one |
| 1427 | */ |
| 1428 | spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags); |
| 1429 | for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) { |
| 1430 | if (rtlpci->tx_ring[i].desc) { |
| 1431 | struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[i]; |
| 1432 | |
| 1433 | while (skb_queue_len(&ring->queue)) { |
| 1434 | struct rtl_tx_desc *entry = |
| 1435 | &ring->desc[ring->idx]; |
| 1436 | struct sk_buff *skb = |
| 1437 | __skb_dequeue(&ring->queue); |
| 1438 | |
| 1439 | pci_unmap_single(rtlpci->pdev, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1440 | le32_to_cpu(rtlpriv->cfg->ops-> |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1441 | get_desc((u8 *) |
| 1442 | entry, |
| 1443 | true, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1444 | HW_DESC_TXBUFF_ADDR)), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1445 | skb->len, PCI_DMA_TODEVICE); |
| 1446 | kfree_skb(skb); |
| 1447 | ring->idx = (ring->idx + 1) % ring->entries; |
| 1448 | } |
| 1449 | ring->idx = 0; |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); |
| 1454 | |
| 1455 | return 0; |
| 1456 | } |
| 1457 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1458 | static bool rtl_pci_tx_chk_waitq_insert(struct ieee80211_hw *hw, |
| 1459 | struct sk_buff *skb) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1460 | { |
| 1461 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1462 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1463 | struct ieee80211_sta *sta = info->control.sta; |
| 1464 | struct rtl_sta_info *sta_entry = NULL; |
| 1465 | u8 tid = rtl_get_tid(skb); |
| 1466 | |
| 1467 | if (!sta) |
| 1468 | return false; |
| 1469 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1470 | |
| 1471 | if (!rtlpriv->rtlhal.earlymode_enable) |
| 1472 | return false; |
| 1473 | if (sta_entry->tids[tid].agg.agg_state != RTL_AGG_OPERATIONAL) |
| 1474 | return false; |
| 1475 | if (_rtl_mac_to_hwqueue(hw, skb) > VO_QUEUE) |
| 1476 | return false; |
| 1477 | if (tid > 7) |
| 1478 | return false; |
| 1479 | |
| 1480 | /* maybe every tid should be checked */ |
| 1481 | if (!rtlpriv->link_info.higher_busytxtraffic[tid]) |
| 1482 | return false; |
| 1483 | |
| 1484 | spin_lock_bh(&rtlpriv->locks.waitq_lock); |
| 1485 | skb_queue_tail(&rtlpriv->mac80211.skb_waitq[tid], skb); |
| 1486 | spin_unlock_bh(&rtlpriv->locks.waitq_lock); |
| 1487 | |
| 1488 | return true; |
| 1489 | } |
| 1490 | |
| 1491 | int rtl_pci_tx(struct ieee80211_hw *hw, struct sk_buff *skb, |
| 1492 | struct rtl_tcb_desc *ptcb_desc) |
| 1493 | { |
| 1494 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1495 | struct rtl_sta_info *sta_entry = NULL; |
| 1496 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1497 | struct ieee80211_sta *sta = info->control.sta; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1498 | struct rtl8192_tx_ring *ring; |
| 1499 | struct rtl_tx_desc *pdesc; |
| 1500 | u8 idx; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1501 | u8 hw_queue = _rtl_mac_to_hwqueue(hw, skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1502 | unsigned long flags; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1503 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
| 1504 | __le16 fc = rtl_get_fc(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1505 | u8 *pda_addr = hdr->addr1; |
| 1506 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1507 | /*ssn */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1508 | u8 tid = 0; |
| 1509 | u16 seq_number = 0; |
| 1510 | u8 own; |
| 1511 | u8 temp_one = 1; |
| 1512 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1513 | if (ieee80211_is_auth(fc)) { |
| 1514 | RT_TRACE(rtlpriv, COMP_SEND, DBG_DMESG, ("MAC80211_LINKING\n")); |
| 1515 | rtl_ips_nic_on(hw); |
| 1516 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1517 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1518 | if (rtlpriv->psc.sw_ps_enabled) { |
| 1519 | if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) && |
| 1520 | !ieee80211_has_pm(fc)) |
| 1521 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
| 1522 | } |
| 1523 | |
| 1524 | rtl_action_proc(hw, skb, true); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1525 | |
| 1526 | if (is_multicast_ether_addr(pda_addr)) |
| 1527 | rtlpriv->stats.txbytesmulticast += skb->len; |
| 1528 | else if (is_broadcast_ether_addr(pda_addr)) |
| 1529 | rtlpriv->stats.txbytesbroadcast += skb->len; |
| 1530 | else |
| 1531 | rtlpriv->stats.txbytesunicast += skb->len; |
| 1532 | |
| 1533 | spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1534 | ring = &rtlpci->tx_ring[hw_queue]; |
| 1535 | if (hw_queue != BEACON_QUEUE) |
| 1536 | idx = (ring->idx + skb_queue_len(&ring->queue)) % |
| 1537 | ring->entries; |
| 1538 | else |
| 1539 | idx = 0; |
| 1540 | |
| 1541 | pdesc = &ring->desc[idx]; |
| 1542 | own = (u8) rtlpriv->cfg->ops->get_desc((u8 *) pdesc, |
| 1543 | true, HW_DESC_OWN); |
| 1544 | |
| 1545 | if ((own == 1) && (hw_queue != BEACON_QUEUE)) { |
| 1546 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
| 1547 | ("No more TX desc@%d, ring->idx = %d," |
| 1548 | "idx = %d, skb_queue_len = 0x%d\n", |
| 1549 | hw_queue, ring->idx, idx, |
| 1550 | skb_queue_len(&ring->queue))); |
| 1551 | |
| 1552 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); |
| 1553 | return skb->len; |
| 1554 | } |
| 1555 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1556 | if (ieee80211_is_data_qos(fc)) { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1557 | tid = rtl_get_tid(skb); |
| 1558 | if (sta) { |
| 1559 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1560 | seq_number = (le16_to_cpu(hdr->seq_ctrl) & |
| 1561 | IEEE80211_SCTL_SEQ) >> 4; |
| 1562 | seq_number += 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1563 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1564 | if (!ieee80211_has_morefrags(hdr->frame_control)) |
| 1565 | sta_entry->tids[tid].seq_number = seq_number; |
| 1566 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | if (ieee80211_is_data(fc)) |
| 1570 | rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX); |
| 1571 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1572 | #if 0 /* temporary */ |
| 1573 | rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, |
| 1574 | info, skb, hw_queue, ptcb_desc); |
| 1575 | #endif |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1576 | |
| 1577 | __skb_queue_tail(&ring->queue, skb); |
| 1578 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1579 | rtlpriv->cfg->ops->set_desc((u8 *)pdesc, true, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1580 | HW_DESC_OWN, (u8 *)&temp_one); |
| 1581 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1582 | |
| 1583 | if ((ring->entries - skb_queue_len(&ring->queue)) < 2 && |
| 1584 | hw_queue != BEACON_QUEUE) { |
| 1585 | |
| 1586 | RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD, |
| 1587 | ("less desc left, stop skb_queue@%d, " |
| 1588 | "ring->idx = %d," |
| 1589 | "idx = %d, skb_queue_len = 0x%d\n", |
| 1590 | hw_queue, ring->idx, idx, |
| 1591 | skb_queue_len(&ring->queue))); |
| 1592 | |
| 1593 | ieee80211_stop_queue(hw, skb_get_queue_mapping(skb)); |
| 1594 | } |
| 1595 | |
| 1596 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); |
| 1597 | |
| 1598 | rtlpriv->cfg->ops->tx_polling(hw, hw_queue); |
| 1599 | |
| 1600 | return 0; |
| 1601 | } |
| 1602 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1603 | static void rtl_pci_flush(struct ieee80211_hw *hw, bool drop) |
| 1604 | { |
| 1605 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1606 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 1607 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1608 | u16 i = 0; |
| 1609 | int queue_id; |
| 1610 | struct rtl8192_tx_ring *ring; |
| 1611 | |
| 1612 | for (queue_id = RTL_PCI_MAX_TX_QUEUE_COUNT - 1; queue_id >= 0;) { |
| 1613 | u32 queue_len; |
| 1614 | ring = &pcipriv->dev.tx_ring[queue_id]; |
| 1615 | queue_len = skb_queue_len(&ring->queue); |
| 1616 | if (queue_len == 0 || queue_id == BEACON_QUEUE || |
| 1617 | queue_id == TXCMD_QUEUE) { |
| 1618 | queue_id--; |
| 1619 | continue; |
| 1620 | } else { |
| 1621 | msleep(20); |
| 1622 | i++; |
| 1623 | } |
| 1624 | |
| 1625 | /* we just wait 1s for all queues */ |
| 1626 | if (rtlpriv->psc.rfpwr_state == ERFOFF || |
| 1627 | is_hal_stop(rtlhal) || i >= 200) |
| 1628 | return; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | void rtl_pci_deinit(struct ieee80211_hw *hw) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1633 | { |
| 1634 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1635 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1636 | |
| 1637 | _rtl_pci_deinit_trx_ring(hw); |
| 1638 | |
| 1639 | synchronize_irq(rtlpci->pdev->irq); |
| 1640 | tasklet_kill(&rtlpriv->works.irq_tasklet); |
| 1641 | |
| 1642 | flush_workqueue(rtlpriv->works.rtl_wq); |
| 1643 | destroy_workqueue(rtlpriv->works.rtl_wq); |
| 1644 | |
| 1645 | } |
| 1646 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1647 | int rtl_pci_init(struct ieee80211_hw *hw, struct pci_dev *pdev) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1648 | { |
| 1649 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1650 | int err; |
| 1651 | |
| 1652 | _rtl_pci_init_struct(hw, pdev); |
| 1653 | |
| 1654 | err = _rtl_pci_init_trx_ring(hw); |
| 1655 | if (err) { |
| 1656 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 1657 | ("tx ring initialization failed")); |
| 1658 | return err; |
| 1659 | } |
| 1660 | |
| 1661 | return 1; |
| 1662 | } |
| 1663 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1664 | int rtl_pci_start(struct ieee80211_hw *hw) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1665 | { |
| 1666 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1667 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1668 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1669 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 1670 | |
| 1671 | int err; |
| 1672 | |
| 1673 | rtl_pci_reset_trx_ring(hw); |
| 1674 | |
| 1675 | rtlpci->driver_is_goingto_unload = false; |
| 1676 | err = rtlpriv->cfg->ops->hw_init(hw); |
| 1677 | if (err) { |
| 1678 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1679 | ("Failed to config hardware!\n")); |
| 1680 | return err; |
| 1681 | } |
| 1682 | |
| 1683 | rtlpriv->cfg->ops->enable_interrupt(hw); |
| 1684 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, ("enable_interrupt OK\n")); |
| 1685 | |
| 1686 | rtl_init_rx_config(hw); |
| 1687 | |
| 1688 | /*should after adapter start and interrupt enable. */ |
| 1689 | set_hal_start(rtlhal); |
| 1690 | |
| 1691 | RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); |
| 1692 | |
| 1693 | rtlpci->up_first_time = false; |
| 1694 | |
| 1695 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, ("OK\n")); |
| 1696 | return 0; |
| 1697 | } |
| 1698 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1699 | void rtl_pci_stop(struct ieee80211_hw *hw) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1700 | { |
| 1701 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1702 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1703 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 1704 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1705 | unsigned long flags; |
| 1706 | u8 RFInProgressTimeOut = 0; |
| 1707 | |
| 1708 | /* |
| 1709 | *should before disable interrrupt&adapter |
| 1710 | *and will do it immediately. |
| 1711 | */ |
| 1712 | set_hal_stop(rtlhal); |
| 1713 | |
| 1714 | rtlpriv->cfg->ops->disable_interrupt(hw); |
| 1715 | |
| 1716 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags); |
| 1717 | while (ppsc->rfchange_inprogress) { |
| 1718 | spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags); |
| 1719 | if (RFInProgressTimeOut > 100) { |
| 1720 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags); |
| 1721 | break; |
| 1722 | } |
| 1723 | mdelay(1); |
| 1724 | RFInProgressTimeOut++; |
| 1725 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags); |
| 1726 | } |
| 1727 | ppsc->rfchange_inprogress = true; |
| 1728 | spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags); |
| 1729 | |
| 1730 | rtlpci->driver_is_goingto_unload = true; |
| 1731 | rtlpriv->cfg->ops->hw_disable(hw); |
| 1732 | rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF); |
| 1733 | |
| 1734 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags); |
| 1735 | ppsc->rfchange_inprogress = false; |
| 1736 | spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags); |
| 1737 | |
| 1738 | rtl_pci_enable_aspm(hw); |
| 1739 | } |
| 1740 | |
| 1741 | static bool _rtl_pci_find_adapter(struct pci_dev *pdev, |
| 1742 | struct ieee80211_hw *hw) |
| 1743 | { |
| 1744 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1745 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 1746 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1747 | struct pci_dev *bridge_pdev = pdev->bus->self; |
| 1748 | u16 venderid; |
| 1749 | u16 deviceid; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1750 | u8 revisionid; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1751 | u16 irqline; |
| 1752 | u8 tmp; |
| 1753 | |
| 1754 | venderid = pdev->vendor; |
| 1755 | deviceid = pdev->device; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1756 | pci_read_config_byte(pdev, 0x8, &revisionid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1757 | pci_read_config_word(pdev, 0x3C, &irqline); |
| 1758 | |
| 1759 | if (deviceid == RTL_PCI_8192_DID || |
| 1760 | deviceid == RTL_PCI_0044_DID || |
| 1761 | deviceid == RTL_PCI_0047_DID || |
| 1762 | deviceid == RTL_PCI_8192SE_DID || |
| 1763 | deviceid == RTL_PCI_8174_DID || |
| 1764 | deviceid == RTL_PCI_8173_DID || |
| 1765 | deviceid == RTL_PCI_8172_DID || |
| 1766 | deviceid == RTL_PCI_8171_DID) { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1767 | switch (revisionid) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1768 | case RTL_PCI_REVISION_ID_8192PCIE: |
| 1769 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1770 | ("8192 PCI-E is found - " |
| 1771 | "vid/did=%x/%x\n", venderid, deviceid)); |
| 1772 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192E; |
| 1773 | break; |
| 1774 | case RTL_PCI_REVISION_ID_8192SE: |
| 1775 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1776 | ("8192SE is found - " |
| 1777 | "vid/did=%x/%x\n", venderid, deviceid)); |
| 1778 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192SE; |
| 1779 | break; |
| 1780 | default: |
| 1781 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
| 1782 | ("Err: Unknown device - " |
| 1783 | "vid/did=%x/%x\n", venderid, deviceid)); |
| 1784 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192SE; |
| 1785 | break; |
| 1786 | |
| 1787 | } |
| 1788 | } else if (deviceid == RTL_PCI_8192CET_DID || |
| 1789 | deviceid == RTL_PCI_8192CE_DID || |
| 1790 | deviceid == RTL_PCI_8191CE_DID || |
| 1791 | deviceid == RTL_PCI_8188CE_DID) { |
| 1792 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192CE; |
| 1793 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1794 | ("8192C PCI-E is found - " |
| 1795 | "vid/did=%x/%x\n", venderid, deviceid)); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1796 | } else if (deviceid == RTL_PCI_8192DE_DID || |
| 1797 | deviceid == RTL_PCI_8192DE_DID2) { |
| 1798 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192DE; |
| 1799 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1800 | ("8192D PCI-E is found - " |
| 1801 | "vid/did=%x/%x\n", venderid, deviceid)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1802 | } else { |
| 1803 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
| 1804 | ("Err: Unknown device -" |
| 1805 | " vid/did=%x/%x\n", venderid, deviceid)); |
| 1806 | |
| 1807 | rtlhal->hw_type = RTL_DEFAULT_HARDWARE_TYPE; |
| 1808 | } |
| 1809 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1810 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE) { |
| 1811 | if (revisionid == 0 || revisionid == 1) { |
| 1812 | if (revisionid == 0) { |
| 1813 | RT_TRACE(rtlpriv, COMP_INIT, |
| 1814 | DBG_LOUD, ("Find 92DE MAC0.\n")); |
| 1815 | rtlhal->interfaceindex = 0; |
| 1816 | } else if (revisionid == 1) { |
| 1817 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, |
| 1818 | ("Find 92DE MAC1.\n")); |
| 1819 | rtlhal->interfaceindex = 1; |
| 1820 | } |
| 1821 | } else { |
| 1822 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, |
| 1823 | ("Unknown device - " |
| 1824 | "VendorID/DeviceID=%x/%x, Revision=%x\n", |
| 1825 | venderid, deviceid, revisionid)); |
| 1826 | rtlhal->interfaceindex = 0; |
| 1827 | } |
| 1828 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1829 | /*find bus info */ |
| 1830 | pcipriv->ndis_adapter.busnumber = pdev->bus->number; |
| 1831 | pcipriv->ndis_adapter.devnumber = PCI_SLOT(pdev->devfn); |
| 1832 | pcipriv->ndis_adapter.funcnumber = PCI_FUNC(pdev->devfn); |
| 1833 | |
| 1834 | /*find bridge info */ |
| 1835 | pcipriv->ndis_adapter.pcibridge_vendorid = bridge_pdev->vendor; |
| 1836 | for (tmp = 0; tmp < PCI_BRIDGE_VENDOR_MAX; tmp++) { |
| 1837 | if (bridge_pdev->vendor == pcibridge_vendors[tmp]) { |
| 1838 | pcipriv->ndis_adapter.pcibridge_vendor = tmp; |
| 1839 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1840 | ("Pci Bridge Vendor is found index: %d\n", |
| 1841 | tmp)); |
| 1842 | break; |
| 1843 | } |
| 1844 | } |
| 1845 | |
| 1846 | if (pcipriv->ndis_adapter.pcibridge_vendor != |
| 1847 | PCI_BRIDGE_VENDOR_UNKNOWN) { |
| 1848 | pcipriv->ndis_adapter.pcibridge_busnum = |
| 1849 | bridge_pdev->bus->number; |
| 1850 | pcipriv->ndis_adapter.pcibridge_devnum = |
| 1851 | PCI_SLOT(bridge_pdev->devfn); |
| 1852 | pcipriv->ndis_adapter.pcibridge_funcnum = |
| 1853 | PCI_FUNC(bridge_pdev->devfn); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1854 | pcipriv->ndis_adapter.pcicfg_addrport = |
| 1855 | (pcipriv->ndis_adapter.pcibridge_busnum << 16) | |
| 1856 | (pcipriv->ndis_adapter.pcibridge_devnum << 11) | |
| 1857 | (pcipriv->ndis_adapter.pcibridge_funcnum << 8) | (1 << 31); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1858 | pcipriv->ndis_adapter.pcibridge_pciehdr_offset = |
| 1859 | pci_pcie_cap(bridge_pdev); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1860 | pcipriv->ndis_adapter.num4bytes = |
| 1861 | (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10) / 4; |
| 1862 | |
| 1863 | rtl_pci_get_linkcontrol_field(hw); |
| 1864 | |
| 1865 | if (pcipriv->ndis_adapter.pcibridge_vendor == |
| 1866 | PCI_BRIDGE_VENDOR_AMD) { |
| 1867 | pcipriv->ndis_adapter.amd_l1_patch = |
| 1868 | rtl_pci_get_amd_l1_patch(hw); |
| 1869 | } |
| 1870 | } |
| 1871 | |
| 1872 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1873 | ("pcidev busnumber:devnumber:funcnumber:" |
| 1874 | "vendor:link_ctl %d:%d:%d:%x:%x\n", |
| 1875 | pcipriv->ndis_adapter.busnumber, |
| 1876 | pcipriv->ndis_adapter.devnumber, |
| 1877 | pcipriv->ndis_adapter.funcnumber, |
| 1878 | pdev->vendor, pcipriv->ndis_adapter.linkctrl_reg)); |
| 1879 | |
| 1880 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1881 | ("pci_bridge busnumber:devnumber:funcnumber:vendor:" |
| 1882 | "pcie_cap:link_ctl_reg:amd %d:%d:%d:%x:%x:%x:%x\n", |
| 1883 | pcipriv->ndis_adapter.pcibridge_busnum, |
| 1884 | pcipriv->ndis_adapter.pcibridge_devnum, |
| 1885 | pcipriv->ndis_adapter.pcibridge_funcnum, |
| 1886 | pcibridge_vendors[pcipriv->ndis_adapter.pcibridge_vendor], |
| 1887 | pcipriv->ndis_adapter.pcibridge_pciehdr_offset, |
| 1888 | pcipriv->ndis_adapter.pcibridge_linkctrlreg, |
| 1889 | pcipriv->ndis_adapter.amd_l1_patch)); |
| 1890 | |
| 1891 | rtl_pci_parse_configuration(pdev, hw); |
| 1892 | |
| 1893 | return true; |
| 1894 | } |
| 1895 | |
| 1896 | int __devinit rtl_pci_probe(struct pci_dev *pdev, |
| 1897 | const struct pci_device_id *id) |
| 1898 | { |
| 1899 | struct ieee80211_hw *hw = NULL; |
| 1900 | |
| 1901 | struct rtl_priv *rtlpriv = NULL; |
| 1902 | struct rtl_pci_priv *pcipriv = NULL; |
| 1903 | struct rtl_pci *rtlpci; |
| 1904 | unsigned long pmem_start, pmem_len, pmem_flags; |
| 1905 | int err; |
| 1906 | |
| 1907 | err = pci_enable_device(pdev); |
| 1908 | if (err) { |
| 1909 | RT_ASSERT(false, |
| 1910 | ("%s : Cannot enable new PCI device\n", |
| 1911 | pci_name(pdev))); |
| 1912 | return err; |
| 1913 | } |
| 1914 | |
| 1915 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { |
| 1916 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) { |
| 1917 | RT_ASSERT(false, ("Unable to obtain 32bit DMA " |
| 1918 | "for consistent allocations\n")); |
| 1919 | pci_disable_device(pdev); |
| 1920 | return -ENOMEM; |
| 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | pci_set_master(pdev); |
| 1925 | |
| 1926 | hw = ieee80211_alloc_hw(sizeof(struct rtl_pci_priv) + |
| 1927 | sizeof(struct rtl_priv), &rtl_ops); |
| 1928 | if (!hw) { |
| 1929 | RT_ASSERT(false, |
| 1930 | ("%s : ieee80211 alloc failed\n", pci_name(pdev))); |
| 1931 | err = -ENOMEM; |
| 1932 | goto fail1; |
| 1933 | } |
| 1934 | |
| 1935 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 1936 | pci_set_drvdata(pdev, hw); |
| 1937 | |
| 1938 | rtlpriv = hw->priv; |
| 1939 | pcipriv = (void *)rtlpriv->priv; |
| 1940 | pcipriv->dev.pdev = pdev; |
| 1941 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1942 | /* init cfg & intf_ops */ |
| 1943 | rtlpriv->rtlhal.interface = INTF_PCI; |
| 1944 | rtlpriv->cfg = (struct rtl_hal_cfg *)(id->driver_data); |
| 1945 | rtlpriv->intf_ops = &rtl_pci_ops; |
| 1946 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1947 | /* |
| 1948 | *init dbgp flags before all |
| 1949 | *other functions, because we will |
| 1950 | *use it in other funtions like |
| 1951 | *RT_TRACE/RT_PRINT/RTL_PRINT_DATA |
| 1952 | *you can not use these macro |
| 1953 | *before this |
| 1954 | */ |
| 1955 | rtl_dbgp_flag_init(hw); |
| 1956 | |
| 1957 | /* MEM map */ |
| 1958 | err = pci_request_regions(pdev, KBUILD_MODNAME); |
| 1959 | if (err) { |
| 1960 | RT_ASSERT(false, ("Can't obtain PCI resources\n")); |
| 1961 | return err; |
| 1962 | } |
| 1963 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1964 | pmem_start = pci_resource_start(pdev, rtlpriv->cfg->bar_id); |
| 1965 | pmem_len = pci_resource_len(pdev, rtlpriv->cfg->bar_id); |
| 1966 | pmem_flags = pci_resource_flags(pdev, rtlpriv->cfg->bar_id); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1967 | |
| 1968 | /*shared mem start */ |
| 1969 | rtlpriv->io.pci_mem_start = |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 1970 | (unsigned long)pci_iomap(pdev, |
| 1971 | rtlpriv->cfg->bar_id, pmem_len); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1972 | if (rtlpriv->io.pci_mem_start == 0) { |
| 1973 | RT_ASSERT(false, ("Can't map PCI mem\n")); |
| 1974 | goto fail2; |
| 1975 | } |
| 1976 | |
| 1977 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1978 | ("mem mapped space: start: 0x%08lx len:%08lx " |
| 1979 | "flags:%08lx, after map:0x%08lx\n", |
| 1980 | pmem_start, pmem_len, pmem_flags, |
| 1981 | rtlpriv->io.pci_mem_start)); |
| 1982 | |
| 1983 | /* Disable Clk Request */ |
| 1984 | pci_write_config_byte(pdev, 0x81, 0); |
| 1985 | /* leave D3 mode */ |
| 1986 | pci_write_config_byte(pdev, 0x44, 0); |
| 1987 | pci_write_config_byte(pdev, 0x04, 0x06); |
| 1988 | pci_write_config_byte(pdev, 0x04, 0x07); |
| 1989 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1990 | /* find adapter */ |
| 1991 | _rtl_pci_find_adapter(pdev, hw); |
| 1992 | |
| 1993 | /* Init IO handler */ |
| 1994 | _rtl_pci_io_handler_init(&pdev->dev, hw); |
| 1995 | |
| 1996 | /*like read eeprom and so on */ |
| 1997 | rtlpriv->cfg->ops->read_eeprom_info(hw); |
| 1998 | |
| 1999 | if (rtlpriv->cfg->ops->init_sw_vars(hw)) { |
| 2000 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 2001 | ("Can't init_sw_vars.\n")); |
| 2002 | goto fail3; |
| 2003 | } |
| 2004 | |
| 2005 | rtlpriv->cfg->ops->init_sw_leds(hw); |
| 2006 | |
| 2007 | /*aspm */ |
| 2008 | rtl_pci_init_aspm(hw); |
| 2009 | |
| 2010 | /* Init mac80211 sw */ |
| 2011 | err = rtl_init_core(hw); |
| 2012 | if (err) { |
| 2013 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 2014 | ("Can't allocate sw for mac80211.\n")); |
| 2015 | goto fail3; |
| 2016 | } |
| 2017 | |
| 2018 | /* Init PCI sw */ |
| 2019 | err = !rtl_pci_init(hw, pdev); |
| 2020 | if (err) { |
| 2021 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 2022 | ("Failed to init PCI.\n")); |
| 2023 | goto fail3; |
| 2024 | } |
| 2025 | |
| 2026 | err = ieee80211_register_hw(hw); |
| 2027 | if (err) { |
| 2028 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 2029 | ("Can't register mac80211 hw.\n")); |
| 2030 | goto fail3; |
| 2031 | } else { |
| 2032 | rtlpriv->mac80211.mac80211_registered = 1; |
| 2033 | } |
| 2034 | |
| 2035 | err = sysfs_create_group(&pdev->dev.kobj, &rtl_attribute_group); |
| 2036 | if (err) { |
| 2037 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 2038 | ("failed to create sysfs device attributes\n")); |
| 2039 | goto fail3; |
| 2040 | } |
| 2041 | |
| 2042 | /*init rfkill */ |
| 2043 | rtl_init_rfkill(hw); |
| 2044 | |
| 2045 | rtlpci = rtl_pcidev(pcipriv); |
| 2046 | err = request_irq(rtlpci->pdev->irq, &_rtl_pci_interrupt, |
| 2047 | IRQF_SHARED, KBUILD_MODNAME, hw); |
| 2048 | if (err) { |
| 2049 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 2050 | ("%s: failed to register IRQ handler\n", |
| 2051 | wiphy_name(hw->wiphy))); |
| 2052 | goto fail3; |
| 2053 | } else { |
| 2054 | rtlpci->irq_alloc = 1; |
| 2055 | } |
| 2056 | |
| 2057 | set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status); |
| 2058 | return 0; |
| 2059 | |
| 2060 | fail3: |
| 2061 | pci_set_drvdata(pdev, NULL); |
| 2062 | rtl_deinit_core(hw); |
| 2063 | _rtl_pci_io_handler_release(hw); |
| 2064 | ieee80211_free_hw(hw); |
| 2065 | |
| 2066 | if (rtlpriv->io.pci_mem_start != 0) |
Larry Finger | 62e6397 | 2011-02-11 14:27:46 -0600 | [diff] [blame] | 2067 | pci_iounmap(pdev, (void __iomem *)rtlpriv->io.pci_mem_start); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2068 | |
| 2069 | fail2: |
| 2070 | pci_release_regions(pdev); |
| 2071 | |
| 2072 | fail1: |
| 2073 | |
| 2074 | pci_disable_device(pdev); |
| 2075 | |
| 2076 | return -ENODEV; |
| 2077 | |
| 2078 | } |
| 2079 | EXPORT_SYMBOL(rtl_pci_probe); |
| 2080 | |
| 2081 | void rtl_pci_disconnect(struct pci_dev *pdev) |
| 2082 | { |
| 2083 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 2084 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 2085 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2086 | struct rtl_pci *rtlpci = rtl_pcidev(pcipriv); |
| 2087 | struct rtl_mac *rtlmac = rtl_mac(rtlpriv); |
| 2088 | |
| 2089 | clear_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status); |
| 2090 | |
| 2091 | sysfs_remove_group(&pdev->dev.kobj, &rtl_attribute_group); |
| 2092 | |
| 2093 | /*ieee80211_unregister_hw will call ops_stop */ |
| 2094 | if (rtlmac->mac80211_registered == 1) { |
| 2095 | ieee80211_unregister_hw(hw); |
| 2096 | rtlmac->mac80211_registered = 0; |
| 2097 | } else { |
| 2098 | rtl_deinit_deferred_work(hw); |
| 2099 | rtlpriv->intf_ops->adapter_stop(hw); |
| 2100 | } |
| 2101 | |
| 2102 | /*deinit rfkill */ |
| 2103 | rtl_deinit_rfkill(hw); |
| 2104 | |
| 2105 | rtl_pci_deinit(hw); |
| 2106 | rtl_deinit_core(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2107 | _rtl_pci_io_handler_release(hw); |
| 2108 | rtlpriv->cfg->ops->deinit_sw_vars(hw); |
| 2109 | |
| 2110 | if (rtlpci->irq_alloc) { |
| 2111 | free_irq(rtlpci->pdev->irq, hw); |
| 2112 | rtlpci->irq_alloc = 0; |
| 2113 | } |
| 2114 | |
| 2115 | if (rtlpriv->io.pci_mem_start != 0) { |
Larry Finger | 62e6397 | 2011-02-11 14:27:46 -0600 | [diff] [blame] | 2116 | pci_iounmap(pdev, (void __iomem *)rtlpriv->io.pci_mem_start); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2117 | pci_release_regions(pdev); |
| 2118 | } |
| 2119 | |
| 2120 | pci_disable_device(pdev); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 2121 | |
| 2122 | rtl_pci_disable_aspm(hw); |
| 2123 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2124 | pci_set_drvdata(pdev, NULL); |
| 2125 | |
| 2126 | ieee80211_free_hw(hw); |
| 2127 | } |
| 2128 | EXPORT_SYMBOL(rtl_pci_disconnect); |
| 2129 | |
| 2130 | /*************************************** |
| 2131 | kernel pci power state define: |
| 2132 | PCI_D0 ((pci_power_t __force) 0) |
| 2133 | PCI_D1 ((pci_power_t __force) 1) |
| 2134 | PCI_D2 ((pci_power_t __force) 2) |
| 2135 | PCI_D3hot ((pci_power_t __force) 3) |
| 2136 | PCI_D3cold ((pci_power_t __force) 4) |
| 2137 | PCI_UNKNOWN ((pci_power_t __force) 5) |
| 2138 | |
| 2139 | This function is called when system |
| 2140 | goes into suspend state mac80211 will |
| 2141 | call rtl_mac_stop() from the mac80211 |
| 2142 | suspend function first, So there is |
| 2143 | no need to call hw_disable here. |
| 2144 | ****************************************/ |
| 2145 | int rtl_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
| 2146 | { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 2147 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 2148 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2149 | |
| 2150 | rtlpriv->cfg->ops->hw_suspend(hw); |
| 2151 | rtl_deinit_rfkill(hw); |
| 2152 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2153 | pci_save_state(pdev); |
| 2154 | pci_disable_device(pdev); |
| 2155 | pci_set_power_state(pdev, PCI_D3hot); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2156 | return 0; |
| 2157 | } |
| 2158 | EXPORT_SYMBOL(rtl_pci_suspend); |
| 2159 | |
| 2160 | int rtl_pci_resume(struct pci_dev *pdev) |
| 2161 | { |
| 2162 | int ret; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 2163 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 2164 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2165 | |
| 2166 | pci_set_power_state(pdev, PCI_D0); |
| 2167 | ret = pci_enable_device(pdev); |
| 2168 | if (ret) { |
| 2169 | RT_ASSERT(false, ("ERR: <======\n")); |
| 2170 | return ret; |
| 2171 | } |
| 2172 | |
| 2173 | pci_restore_state(pdev); |
| 2174 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 2175 | rtlpriv->cfg->ops->hw_resume(hw); |
| 2176 | rtl_init_rfkill(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2177 | return 0; |
| 2178 | } |
| 2179 | EXPORT_SYMBOL(rtl_pci_resume); |
| 2180 | |
| 2181 | struct rtl_intf_ops rtl_pci_ops = { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 2182 | .read_efuse_byte = read_efuse_byte, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2183 | .adapter_start = rtl_pci_start, |
| 2184 | .adapter_stop = rtl_pci_stop, |
| 2185 | .adapter_tx = rtl_pci_tx, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 2186 | .flush = rtl_pci_flush, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2187 | .reset_trx_ring = rtl_pci_reset_trx_ring, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame^] | 2188 | .waitq_insert = rtl_pci_tx_chk_waitq_insert, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2189 | |
| 2190 | .disable_aspm = rtl_pci_disable_aspm, |
| 2191 | .enable_aspm = rtl_pci_enable_aspm, |
| 2192 | }; |