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