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 | |
Troy Tan | d031131 | 2015-02-03 11:15:17 -0600 | [diff] [blame] | 581 | if (rtlpriv->cfg->ops->get_available_desc && |
| 582 | rtlpriv->cfg->ops->get_available_desc(hw, prio) <= 1) { |
| 583 | RT_TRACE(rtlpriv, (COMP_INTR | COMP_SEND), DBG_DMESG, |
| 584 | "no available desc!\n"); |
| 585 | return; |
| 586 | } |
| 587 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 588 | if (!rtlpriv->cfg->ops->is_tx_desc_closed(hw, prio, ring->idx)) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 589 | return; |
| 590 | ring->idx = (ring->idx + 1) % ring->entries; |
| 591 | |
| 592 | skb = __skb_dequeue(&ring->queue); |
| 593 | pci_unmap_single(rtlpci->pdev, |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 594 | rtlpriv->cfg->ops-> |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 595 | get_desc((u8 *)entry, true, |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 596 | HW_DESC_TXBUFF_ADDR), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 597 | skb->len, PCI_DMA_TODEVICE); |
| 598 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 599 | /* remove early mode header */ |
| 600 | if (rtlpriv->rtlhal.earlymode_enable) |
| 601 | skb_pull(skb, EM_HDR_LEN); |
| 602 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 603 | RT_TRACE(rtlpriv, (COMP_INTR | COMP_SEND), DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 604 | "new ring->idx:%d, free: skb_queue_len:%d, free: seq:%x\n", |
| 605 | ring->idx, |
| 606 | skb_queue_len(&ring->queue), |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 607 | *(u16 *)(skb->data + 22)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 608 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 609 | if (prio == TXCMD_QUEUE) { |
| 610 | dev_kfree_skb(skb); |
| 611 | goto tx_status_ok; |
| 612 | |
| 613 | } |
| 614 | |
| 615 | /* for sw LPS, just after NULL skb send out, we can |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 616 | * sure AP knows we are sleeping, we should not let |
| 617 | * rf sleep |
| 618 | */ |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 619 | fc = rtl_get_fc(skb); |
| 620 | if (ieee80211_is_nullfunc(fc)) { |
| 621 | if (ieee80211_has_pm(fc)) { |
Mike McCormack | 9c05044 | 2011-06-20 10:44:58 +0900 | [diff] [blame] | 622 | rtlpriv->mac80211.offchan_delay = true; |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 623 | rtlpriv->psc.state_inap = true; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 624 | } else { |
Rusty Russell | 3db1cd5 | 2011-12-19 13:56:45 +0000 | [diff] [blame] | 625 | rtlpriv->psc.state_inap = false; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 626 | } |
| 627 | } |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 628 | if (ieee80211_is_action(fc)) { |
| 629 | struct ieee80211_mgmt *action_frame = |
| 630 | (struct ieee80211_mgmt *)skb->data; |
| 631 | if (action_frame->u.action.u.ht_smps.action == |
| 632 | WLAN_HT_ACTION_SMPS) { |
| 633 | dev_kfree_skb(skb); |
| 634 | goto tx_status_ok; |
| 635 | } |
| 636 | } |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 637 | |
| 638 | /* update tid tx pkt num */ |
| 639 | tid = rtl_get_tid(skb); |
| 640 | if (tid <= 7) |
| 641 | rtlpriv->link_info.tidtx_inperiod[tid]++; |
| 642 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 643 | info = IEEE80211_SKB_CB(skb); |
| 644 | ieee80211_tx_info_clear_status(info); |
| 645 | |
| 646 | info->flags |= IEEE80211_TX_STAT_ACK; |
| 647 | /*info->status.rates[0].count = 1; */ |
| 648 | |
| 649 | ieee80211_tx_status_irqsafe(hw, skb); |
| 650 | |
Troy Tan | d031131 | 2015-02-03 11:15:17 -0600 | [diff] [blame] | 651 | if ((ring->entries - skb_queue_len(&ring->queue)) <= 4) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 652 | |
Troy Tan | d031131 | 2015-02-03 11:15:17 -0600 | [diff] [blame] | 653 | RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG, |
Hans Wennborg | 4f4378d | 2014-09-05 20:19:50 -0700 | [diff] [blame] | 654 | "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] | 655 | prio, ring->idx, |
| 656 | skb_queue_len(&ring->queue)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 657 | |
| 658 | ieee80211_wake_queue(hw, |
| 659 | skb_get_queue_mapping |
| 660 | (skb)); |
| 661 | } |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 662 | tx_status_ok: |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 663 | skb = NULL; |
| 664 | } |
| 665 | |
| 666 | if (((rtlpriv->link_info.num_rx_inperiod + |
| 667 | rtlpriv->link_info.num_tx_inperiod) > 8) || |
| 668 | (rtlpriv->link_info.num_rx_inperiod > 2)) { |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 669 | rtlpriv->enter_ps = false; |
| 670 | schedule_work(&rtlpriv->works.lps_change_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 671 | } |
| 672 | } |
| 673 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 674 | static int _rtl_pci_init_one_rxdesc(struct ieee80211_hw *hw, |
| 675 | u8 *entry, int rxring_idx, int desc_idx) |
Mike McCormack | fd85477 | 2011-06-06 23:13:06 +0900 | [diff] [blame] | 676 | { |
| 677 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 678 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 679 | u32 bufferaddress; |
| 680 | u8 tmp_one = 1; |
| 681 | struct sk_buff *skb; |
Mike McCormack | fd85477 | 2011-06-06 23:13:06 +0900 | [diff] [blame] | 682 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 683 | skb = dev_alloc_skb(rtlpci->rxbuffersize); |
| 684 | if (!skb) |
| 685 | return 0; |
| 686 | rtlpci->rx_ring[rxring_idx].rx_buf[desc_idx] = skb; |
Mike McCormack | fd85477 | 2011-06-06 23:13:06 +0900 | [diff] [blame] | 687 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 688 | /* just set skb->cb to mapping addr for pci_unmap_single use */ |
| 689 | *((dma_addr_t *)skb->cb) = |
| 690 | pci_map_single(rtlpci->pdev, skb_tail_pointer(skb), |
| 691 | rtlpci->rxbuffersize, PCI_DMA_FROMDEVICE); |
| 692 | bufferaddress = *((dma_addr_t *)skb->cb); |
| 693 | if (pci_dma_mapping_error(rtlpci->pdev, bufferaddress)) |
| 694 | return 0; |
| 695 | if (rtlpriv->use_new_trx_flow) { |
| 696 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false, |
| 697 | HW_DESC_RX_PREPARE, |
| 698 | (u8 *)&bufferaddress); |
Mike McCormack | fd85477 | 2011-06-06 23:13:06 +0900 | [diff] [blame] | 699 | } else { |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 700 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false, |
| 701 | HW_DESC_RXBUFF_ADDR, |
| 702 | (u8 *)&bufferaddress); |
| 703 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false, |
| 704 | HW_DESC_RXPKT_LEN, |
| 705 | (u8 *)&rtlpci->rxbuffersize); |
| 706 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false, |
| 707 | HW_DESC_RXOWN, |
| 708 | (u8 *)&tmp_one); |
Mike McCormack | fd85477 | 2011-06-06 23:13:06 +0900 | [diff] [blame] | 709 | } |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 710 | return 1; |
| 711 | } |
Mike McCormack | fd85477 | 2011-06-06 23:13:06 +0900 | [diff] [blame] | 712 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 713 | /* inorder to receive 8K AMSDU we have set skb to |
| 714 | * 9100bytes in init rx ring, but if this packet is |
| 715 | * not a AMSDU, this large packet will be sent to |
| 716 | * TCP/IP directly, this cause big packet ping fail |
| 717 | * like: "ping -s 65507", so here we will realloc skb |
| 718 | * based on the true size of packet, Mac80211 |
| 719 | * Probably will do it better, but does not yet. |
| 720 | * |
| 721 | * Some platform will fail when alloc skb sometimes. |
| 722 | * in this condition, we will send the old skb to |
| 723 | * mac80211 directly, this will not cause any other |
| 724 | * issues, but only this packet will be lost by TCP/IP |
| 725 | */ |
| 726 | static void _rtl_pci_rx_to_mac80211(struct ieee80211_hw *hw, |
| 727 | struct sk_buff *skb, |
| 728 | struct ieee80211_rx_status rx_status) |
| 729 | { |
| 730 | if (unlikely(!rtl_action_proc(hw, skb, false))) { |
| 731 | dev_kfree_skb_any(skb); |
| 732 | } else { |
| 733 | struct sk_buff *uskb = NULL; |
| 734 | u8 *pdata; |
Mike McCormack | fd85477 | 2011-06-06 23:13:06 +0900 | [diff] [blame] | 735 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 736 | uskb = dev_alloc_skb(skb->len + 128); |
| 737 | if (likely(uskb)) { |
| 738 | memcpy(IEEE80211_SKB_RXCB(uskb), &rx_status, |
| 739 | sizeof(rx_status)); |
| 740 | pdata = (u8 *)skb_put(uskb, skb->len); |
| 741 | memcpy(pdata, skb->data, skb->len); |
| 742 | dev_kfree_skb_any(skb); |
| 743 | ieee80211_rx_irqsafe(hw, uskb); |
| 744 | } else { |
| 745 | ieee80211_rx_irqsafe(hw, skb); |
| 746 | } |
Mike McCormack | fd85477 | 2011-06-06 23:13:06 +0900 | [diff] [blame] | 747 | } |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 748 | } |
Mike McCormack | fd85477 | 2011-06-06 23:13:06 +0900 | [diff] [blame] | 749 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 750 | /*hsisr interrupt handler*/ |
| 751 | static void _rtl_pci_hs_interrupt(struct ieee80211_hw *hw) |
| 752 | { |
| 753 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 754 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 755 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 756 | rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[MAC_HSISR], |
| 757 | rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[MAC_HSISR]) | |
| 758 | rtlpci->sys_irq_mask); |
Mike McCormack | fd85477 | 2011-06-06 23:13:06 +0900 | [diff] [blame] | 759 | } |
| 760 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 761 | static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw) |
| 762 | { |
| 763 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 764 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 765 | int rxring_idx = RTL_PCI_RX_MPDU_QUEUE; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 766 | struct ieee80211_rx_status rx_status = { 0 }; |
| 767 | unsigned int count = rtlpci->rxringcount; |
| 768 | u8 own; |
| 769 | u8 tmp_one; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 770 | bool unicast = false; |
| 771 | u8 hw_queue = 0; |
| 772 | unsigned int rx_remained_cnt; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 773 | struct rtl_stats stats = { |
| 774 | .signal = 0, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 775 | .rate = 0, |
| 776 | }; |
| 777 | |
| 778 | /*RX NORMAL PKT */ |
| 779 | while (count--) { |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 780 | struct ieee80211_hdr *hdr; |
| 781 | __le16 fc; |
| 782 | u16 len; |
| 783 | /*rx buffer descriptor */ |
| 784 | struct rtl_rx_buffer_desc *buffer_desc = NULL; |
| 785 | /*if use new trx flow, it means wifi info */ |
| 786 | struct rtl_rx_desc *pdesc = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 787 | /*rx pkt */ |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 788 | struct sk_buff *skb = rtlpci->rx_ring[rxring_idx].rx_buf[ |
| 789 | rtlpci->rx_ring[rxring_idx].idx]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 790 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 791 | if (rtlpriv->use_new_trx_flow) { |
| 792 | rx_remained_cnt = |
| 793 | rtlpriv->cfg->ops->rx_desc_buff_remained_cnt(hw, |
| 794 | hw_queue); |
Troy Tan | d031131 | 2015-02-03 11:15:17 -0600 | [diff] [blame] | 795 | if (rx_remained_cnt == 0) |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 796 | return; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 797 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 798 | } else { /* rx descriptor */ |
| 799 | pdesc = &rtlpci->rx_ring[rxring_idx].desc[ |
| 800 | rtlpci->rx_ring[rxring_idx].idx]; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 801 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 802 | own = (u8)rtlpriv->cfg->ops->get_desc((u8 *)pdesc, |
| 803 | false, |
| 804 | HW_DESC_OWN); |
| 805 | if (own) /* wait data to be filled by hardware */ |
| 806 | return; |
Mike McCormack | 2c33336 | 2011-06-06 23:12:08 +0900 | [diff] [blame] | 807 | } |
Mike McCormack | 6633d64 | 2011-06-07 08:58:31 +0900 | [diff] [blame] | 808 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 809 | /* Reaching this point means: data is filled already |
| 810 | * AAAAAAttention !!! |
| 811 | * We can NOT access 'skb' before 'pci_unmap_single' |
| 812 | */ |
| 813 | pci_unmap_single(rtlpci->pdev, *((dma_addr_t *)skb->cb), |
| 814 | rtlpci->rxbuffersize, PCI_DMA_FROMDEVICE); |
Mike McCormack | 6633d64 | 2011-06-07 08:58:31 +0900 | [diff] [blame] | 815 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 816 | if (rtlpriv->use_new_trx_flow) { |
| 817 | buffer_desc = |
| 818 | &rtlpci->rx_ring[rxring_idx].buffer_desc |
| 819 | [rtlpci->rx_ring[rxring_idx].idx]; |
| 820 | /*means rx wifi info*/ |
| 821 | pdesc = (struct rtl_rx_desc *)skb->data; |
| 822 | } |
| 823 | memset(&rx_status , 0 , sizeof(rx_status)); |
| 824 | rtlpriv->cfg->ops->query_rx_desc(hw, &stats, |
| 825 | &rx_status, (u8 *)pdesc, skb); |
| 826 | |
| 827 | if (rtlpriv->use_new_trx_flow) |
| 828 | rtlpriv->cfg->ops->rx_check_dma_ok(hw, |
| 829 | (u8 *)buffer_desc, |
| 830 | hw_queue); |
| 831 | |
| 832 | len = rtlpriv->cfg->ops->get_desc((u8 *)pdesc, false, |
| 833 | HW_DESC_RXPKT_LEN); |
| 834 | |
| 835 | if (skb->end - skb->tail > len) { |
| 836 | skb_put(skb, len); |
| 837 | if (rtlpriv->use_new_trx_flow) |
| 838 | skb_reserve(skb, stats.rx_drvinfo_size + |
| 839 | stats.rx_bufshift + 24); |
| 840 | else |
| 841 | skb_reserve(skb, stats.rx_drvinfo_size + |
| 842 | stats.rx_bufshift); |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 843 | } else { |
| 844 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
| 845 | "skb->end - skb->tail = %d, len is %d\n", |
| 846 | skb->end - skb->tail, len); |
Troy Tan | d031131 | 2015-02-03 11:15:17 -0600 | [diff] [blame] | 847 | dev_kfree_skb_any(skb); |
| 848 | goto new_trx_end; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 849 | } |
| 850 | /* handle command packet here */ |
Larry Finger | d1cd5ba | 2014-11-07 10:05:12 -0600 | [diff] [blame] | 851 | if (rtlpriv->cfg->ops->rx_command_packet && |
| 852 | rtlpriv->cfg->ops->rx_command_packet(hw, stats, skb)) { |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 853 | dev_kfree_skb_any(skb); |
Troy Tan | d031131 | 2015-02-03 11:15:17 -0600 | [diff] [blame] | 854 | goto new_trx_end; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 855 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 856 | |
Mike McCormack | 2c33336 | 2011-06-06 23:12:08 +0900 | [diff] [blame] | 857 | /* |
| 858 | * NOTICE This can not be use for mac80211, |
| 859 | * this is done in mac80211 code, |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 860 | * if done here sec DHCP will fail |
Mike McCormack | 2c33336 | 2011-06-06 23:12:08 +0900 | [diff] [blame] | 861 | * skb_trim(skb, skb->len - 4); |
| 862 | */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 863 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 864 | hdr = rtl_get_hdr(skb); |
| 865 | fc = rtl_get_fc(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 866 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 867 | if (!stats.crc && !stats.hwerror) { |
| 868 | memcpy(IEEE80211_SKB_RXCB(skb), &rx_status, |
| 869 | sizeof(rx_status)); |
| 870 | |
| 871 | if (is_broadcast_ether_addr(hdr->addr1)) { |
| 872 | ;/*TODO*/ |
| 873 | } else if (is_multicast_ether_addr(hdr->addr1)) { |
| 874 | ;/*TODO*/ |
| 875 | } else { |
| 876 | unicast = true; |
| 877 | rtlpriv->stats.rxbytesunicast += skb->len; |
| 878 | } |
| 879 | rtl_is_special_data(hw, skb, false); |
| 880 | |
| 881 | if (ieee80211_is_data(fc)) { |
| 882 | rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX); |
| 883 | if (unicast) |
| 884 | rtlpriv->link_info.num_rx_inperiod++; |
| 885 | } |
| 886 | /* static bcn for roaming */ |
| 887 | rtl_beacon_statistic(hw, skb); |
| 888 | rtl_p2p_info(hw, (void *)skb->data, skb->len); |
| 889 | /* for sw lps */ |
| 890 | rtl_swlps_beacon(hw, (void *)skb->data, skb->len); |
| 891 | rtl_recognize_peer(hw, (void *)skb->data, skb->len); |
| 892 | if ((rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP) && |
| 893 | (rtlpriv->rtlhal.current_bandtype == |
| 894 | BAND_ON_2_4G) && |
| 895 | (ieee80211_is_beacon(fc) || |
| 896 | ieee80211_is_probe_resp(fc))) { |
| 897 | dev_kfree_skb_any(skb); |
| 898 | } else { |
| 899 | _rtl_pci_rx_to_mac80211(hw, skb, rx_status); |
| 900 | } |
| 901 | } else { |
| 902 | dev_kfree_skb_any(skb); |
| 903 | } |
Troy Tan | d031131 | 2015-02-03 11:15:17 -0600 | [diff] [blame] | 904 | new_trx_end: |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 905 | if (rtlpriv->use_new_trx_flow) { |
| 906 | rtlpci->rx_ring[hw_queue].next_rx_rp += 1; |
| 907 | rtlpci->rx_ring[hw_queue].next_rx_rp %= |
| 908 | RTL_PCI_MAX_RX_COUNT; |
| 909 | |
| 910 | rx_remained_cnt--; |
| 911 | rtl_write_word(rtlpriv, 0x3B4, |
| 912 | rtlpci->rx_ring[hw_queue].next_rx_rp); |
| 913 | } |
Mike McCormack | 2c33336 | 2011-06-06 23:12:08 +0900 | [diff] [blame] | 914 | if (((rtlpriv->link_info.num_rx_inperiod + |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 915 | rtlpriv->link_info.num_tx_inperiod) > 8) || |
| 916 | (rtlpriv->link_info.num_rx_inperiod > 2)) { |
| 917 | rtlpriv->enter_ps = false; |
| 918 | schedule_work(&rtlpriv->works.lps_change_work); |
Mike McCormack | 2c33336 | 2011-06-06 23:12:08 +0900 | [diff] [blame] | 919 | } |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 920 | if (rtlpriv->use_new_trx_flow) { |
| 921 | _rtl_pci_init_one_rxdesc(hw, (u8 *)buffer_desc, |
| 922 | rxring_idx, |
| 923 | rtlpci->rx_ring[rxring_idx].idx); |
| 924 | } else { |
| 925 | _rtl_pci_init_one_rxdesc(hw, (u8 *)pdesc, rxring_idx, |
| 926 | rtlpci->rx_ring[rxring_idx].idx); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 927 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 928 | if (rtlpci->rx_ring[rxring_idx].idx == |
| 929 | rtlpci->rxringcount - 1) |
| 930 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, |
| 931 | false, |
| 932 | HW_DESC_RXERO, |
| 933 | (u8 *)&tmp_one); |
| 934 | } |
| 935 | rtlpci->rx_ring[rxring_idx].idx = |
| 936 | (rtlpci->rx_ring[rxring_idx].idx + 1) % |
| 937 | rtlpci->rxringcount; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 938 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 939 | } |
| 940 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 941 | static irqreturn_t _rtl_pci_interrupt(int irq, void *dev_id) |
| 942 | { |
| 943 | struct ieee80211_hw *hw = dev_id; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 944 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 945 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 946 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 947 | unsigned long flags; |
| 948 | u32 inta = 0; |
| 949 | u32 intb = 0; |
Larry Finger | de2e56c | 2011-11-23 21:30:19 -0600 | [diff] [blame] | 950 | irqreturn_t ret = IRQ_HANDLED; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 951 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 952 | if (rtlpci->irq_enabled == 0) |
| 953 | return ret; |
| 954 | |
| 955 | spin_lock_irqsave(&rtlpriv->locks.irq_th_lock , flags); |
| 956 | rtlpriv->cfg->ops->disable_interrupt(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 957 | |
| 958 | /*read ISR: 4/8bytes */ |
| 959 | rtlpriv->cfg->ops->interrupt_recognized(hw, &inta, &intb); |
| 960 | |
| 961 | /*Shared IRQ or HW disappared */ |
Larry Finger | 0529c6b | 2014-09-26 16:40:24 -0500 | [diff] [blame] | 962 | if (!inta || inta == 0xffff) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 963 | goto done; |
| 964 | |
| 965 | /*<1> beacon related */ |
| 966 | if (inta & rtlpriv->cfg->maps[RTL_IMR_TBDOK]) { |
| 967 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 968 | "beacon ok interrupt!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_TBDER])) { |
| 972 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 973 | "beacon err interrupt!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | if (inta & rtlpriv->cfg->maps[RTL_IMR_BDOK]) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 977 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, "beacon interrupt!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 978 | } |
| 979 | |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 980 | if (inta & rtlpriv->cfg->maps[RTL_IMR_BCNINT]) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 981 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 982 | "prepare beacon for interrupt!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 983 | tasklet_schedule(&rtlpriv->works.irq_prepare_bcn_tasklet); |
| 984 | } |
| 985 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 986 | /*<2> Tx related */ |
| 987 | if (unlikely(intb & rtlpriv->cfg->maps[RTL_IMR_TXFOVW])) |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 988 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, "IMR_TXFOVW!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 989 | |
| 990 | if (inta & rtlpriv->cfg->maps[RTL_IMR_MGNTDOK]) { |
| 991 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 992 | "Manage ok interrupt!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 993 | _rtl_pci_tx_isr(hw, MGNT_QUEUE); |
| 994 | } |
| 995 | |
| 996 | if (inta & rtlpriv->cfg->maps[RTL_IMR_HIGHDOK]) { |
| 997 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 998 | "HIGH_QUEUE ok interrupt!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 999 | _rtl_pci_tx_isr(hw, HIGH_QUEUE); |
| 1000 | } |
| 1001 | |
| 1002 | if (inta & rtlpriv->cfg->maps[RTL_IMR_BKDOK]) { |
| 1003 | rtlpriv->link_info.num_tx_inperiod++; |
| 1004 | |
| 1005 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1006 | "BK Tx OK interrupt!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1007 | _rtl_pci_tx_isr(hw, BK_QUEUE); |
| 1008 | } |
| 1009 | |
| 1010 | if (inta & rtlpriv->cfg->maps[RTL_IMR_BEDOK]) { |
| 1011 | rtlpriv->link_info.num_tx_inperiod++; |
| 1012 | |
| 1013 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1014 | "BE TX OK interrupt!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1015 | _rtl_pci_tx_isr(hw, BE_QUEUE); |
| 1016 | } |
| 1017 | |
| 1018 | if (inta & rtlpriv->cfg->maps[RTL_IMR_VIDOK]) { |
| 1019 | rtlpriv->link_info.num_tx_inperiod++; |
| 1020 | |
| 1021 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1022 | "VI TX OK interrupt!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1023 | _rtl_pci_tx_isr(hw, VI_QUEUE); |
| 1024 | } |
| 1025 | |
| 1026 | if (inta & rtlpriv->cfg->maps[RTL_IMR_VODOK]) { |
| 1027 | rtlpriv->link_info.num_tx_inperiod++; |
| 1028 | |
| 1029 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1030 | "Vo TX OK interrupt!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1031 | _rtl_pci_tx_isr(hw, VO_QUEUE); |
| 1032 | } |
| 1033 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1034 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) { |
| 1035 | if (inta & rtlpriv->cfg->maps[RTL_IMR_COMDOK]) { |
| 1036 | rtlpriv->link_info.num_tx_inperiod++; |
| 1037 | |
| 1038 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1039 | "CMD TX OK interrupt!\n"); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1040 | _rtl_pci_tx_isr(hw, TXCMD_QUEUE); |
| 1041 | } |
| 1042 | } |
| 1043 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1044 | /*<3> Rx related */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1045 | if (inta & rtlpriv->cfg->maps[RTL_IMR_ROK]) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1046 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, "Rx ok interrupt!\n"); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1047 | _rtl_pci_rx_interrupt(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_RDU])) { |
| 1051 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1052 | "rx descriptor unavailable!\n"); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1053 | _rtl_pci_rx_interrupt(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1054 | } |
| 1055 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1056 | if (unlikely(intb & rtlpriv->cfg->maps[RTL_IMR_RXFOVW])) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1057 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, "rx overflow !\n"); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1058 | _rtl_pci_rx_interrupt(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1059 | } |
| 1060 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1061 | /*<4> fw related*/ |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1062 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723AE) { |
| 1063 | if (inta & rtlpriv->cfg->maps[RTL_IMR_C2HCMD]) { |
| 1064 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 1065 | "firmware interrupt!\n"); |
| 1066 | queue_delayed_work(rtlpriv->works.rtl_wq, |
| 1067 | &rtlpriv->works.fwevt_wq, 0); |
| 1068 | } |
| 1069 | } |
| 1070 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1071 | /*<5> hsisr related*/ |
| 1072 | /* Only 8188EE & 8723BE Supported. |
| 1073 | * If Other ICs Come in, System will corrupt, |
| 1074 | * because maps[RTL_IMR_HSISR_IND] & maps[MAC_HSISR] |
| 1075 | * are not initialized |
| 1076 | */ |
| 1077 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8188EE || |
| 1078 | rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) { |
| 1079 | if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_HSISR_IND])) { |
| 1080 | RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, |
| 1081 | "hsisr interrupt!\n"); |
| 1082 | _rtl_pci_hs_interrupt(hw); |
| 1083 | } |
| 1084 | } |
| 1085 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1086 | if (rtlpriv->rtlhal.earlymode_enable) |
| 1087 | tasklet_schedule(&rtlpriv->works.irq_tasklet); |
| 1088 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1089 | done: |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1090 | rtlpriv->cfg->ops->enable_interrupt(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1091 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); |
Larry Finger | de2e56c | 2011-11-23 21:30:19 -0600 | [diff] [blame] | 1092 | return ret; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | static void _rtl_pci_irq_tasklet(struct ieee80211_hw *hw) |
| 1096 | { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1097 | _rtl_pci_tx_chk_waitq(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw *hw) |
| 1101 | { |
| 1102 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1103 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1104 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1105 | struct rtl8192_tx_ring *ring = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1106 | struct ieee80211_hdr *hdr = NULL; |
| 1107 | struct ieee80211_tx_info *info = NULL; |
| 1108 | struct sk_buff *pskb = NULL; |
| 1109 | struct rtl_tx_desc *pdesc = NULL; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1110 | struct rtl_tcb_desc tcb_desc; |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame] | 1111 | /*This is for new trx flow*/ |
| 1112 | struct rtl_tx_buffer_desc *pbuffer_desc = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1113 | u8 temp_one = 1; |
| 1114 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1115 | memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1116 | ring = &rtlpci->tx_ring[BEACON_QUEUE]; |
| 1117 | pskb = __skb_dequeue(&ring->queue); |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1118 | if (pskb) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1119 | kfree_skb(pskb); |
| 1120 | |
| 1121 | /*NB: the beacon data buffer must be 32-bit aligned. */ |
| 1122 | pskb = ieee80211_beacon_get(hw, mac->vif); |
| 1123 | if (pskb == NULL) |
| 1124 | return; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1125 | hdr = rtl_get_hdr(pskb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1126 | info = IEEE80211_SKB_CB(pskb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1127 | pdesc = &ring->desc[0]; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1128 | if (rtlpriv->use_new_trx_flow) |
| 1129 | pbuffer_desc = &ring->buffer_desc[0]; |
| 1130 | |
| 1131 | rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame] | 1132 | (u8 *)pbuffer_desc, info, NULL, pskb, |
| 1133 | BEACON_QUEUE, &tcb_desc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1134 | |
| 1135 | __skb_queue_tail(&ring->queue, pskb); |
| 1136 | |
Larry Finger | fb6eaf2 | 2014-11-05 19:10:52 -0600 | [diff] [blame] | 1137 | if (rtlpriv->use_new_trx_flow) { |
| 1138 | temp_one = 4; |
| 1139 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)pbuffer_desc, true, |
| 1140 | HW_DESC_OWN, (u8 *)&temp_one); |
| 1141 | } else { |
| 1142 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, true, HW_DESC_OWN, |
| 1143 | &temp_one); |
| 1144 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1145 | return; |
| 1146 | } |
| 1147 | |
| 1148 | static void _rtl_pci_init_trx_var(struct ieee80211_hw *hw) |
| 1149 | { |
| 1150 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1151 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1152 | struct rtl_hal *rtlhal = rtl_hal(rtlpriv); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1153 | u8 i; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1154 | u16 desc_num; |
| 1155 | |
| 1156 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) |
| 1157 | desc_num = TX_DESC_NUM_92E; |
| 1158 | else |
| 1159 | desc_num = RT_TXDESC_NUM; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1160 | |
| 1161 | for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1162 | rtlpci->txringcount[i] = desc_num; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1163 | |
| 1164 | /* |
| 1165 | *we just alloc 2 desc for beacon queue, |
| 1166 | *because we just need first desc in hw beacon. |
| 1167 | */ |
| 1168 | rtlpci->txringcount[BEACON_QUEUE] = 2; |
| 1169 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1170 | /*BE queue need more descriptor for performance |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1171 | *consideration or, No more tx desc will happen, |
| 1172 | *and may cause mac80211 mem leakage. |
| 1173 | */ |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1174 | if (!rtl_priv(hw)->use_new_trx_flow) |
| 1175 | rtlpci->txringcount[BE_QUEUE] = RT_TXDESC_NUM_BE_QUEUE; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1176 | |
| 1177 | rtlpci->rxbuffersize = 9100; /*2048/1024; */ |
| 1178 | rtlpci->rxringcount = RTL_PCI_MAX_RX_COUNT; /*64; */ |
| 1179 | } |
| 1180 | |
| 1181 | static void _rtl_pci_init_struct(struct ieee80211_hw *hw, |
| 1182 | struct pci_dev *pdev) |
| 1183 | { |
| 1184 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1185 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 1186 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1187 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1188 | |
| 1189 | rtlpci->up_first_time = true; |
| 1190 | rtlpci->being_init_adapter = false; |
| 1191 | |
| 1192 | rtlhal->hw = hw; |
| 1193 | rtlpci->pdev = pdev; |
| 1194 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1195 | /*Tx/Rx related var */ |
| 1196 | _rtl_pci_init_trx_var(hw); |
| 1197 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1198 | /*IBSS*/ mac->beacon_interval = 100; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1199 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1200 | /*AMPDU*/ |
| 1201 | mac->min_space_cfg = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1202 | mac->max_mss_density = 0; |
| 1203 | /*set sane AMPDU defaults */ |
| 1204 | mac->current_ampdu_density = 7; |
| 1205 | mac->current_ampdu_factor = 3; |
| 1206 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1207 | /*QOS*/ |
Larry Finger | 2cddad3 | 2014-02-28 15:16:46 -0600 | [diff] [blame] | 1208 | rtlpci->acm_method = EACMWAY2_SW; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1209 | |
| 1210 | /*task */ |
| 1211 | tasklet_init(&rtlpriv->works.irq_tasklet, |
| 1212 | (void (*)(unsigned long))_rtl_pci_irq_tasklet, |
| 1213 | (unsigned long)hw); |
| 1214 | tasklet_init(&rtlpriv->works.irq_prepare_bcn_tasklet, |
| 1215 | (void (*)(unsigned long))_rtl_pci_prepare_bcn_tasklet, |
| 1216 | (unsigned long)hw); |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1217 | INIT_WORK(&rtlpriv->works.lps_change_work, |
| 1218 | rtl_lps_change_work_callback); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw, |
| 1222 | unsigned int prio, unsigned int entries) |
| 1223 | { |
| 1224 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1225 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1226 | struct rtl_tx_buffer_desc *buffer_desc; |
| 1227 | struct rtl_tx_desc *desc; |
| 1228 | dma_addr_t buffer_desc_dma, desc_dma; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1229 | u32 nextdescaddress; |
| 1230 | int i; |
| 1231 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1232 | /* alloc tx buffer desc for new trx flow*/ |
| 1233 | if (rtlpriv->use_new_trx_flow) { |
| 1234 | buffer_desc = |
| 1235 | pci_zalloc_consistent(rtlpci->pdev, |
| 1236 | sizeof(*buffer_desc) * entries, |
| 1237 | &buffer_desc_dma); |
| 1238 | |
| 1239 | if (!buffer_desc || (unsigned long)buffer_desc & 0xFF) { |
| 1240 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 1241 | "Cannot allocate TX ring (prio = %d)\n", |
| 1242 | prio); |
| 1243 | return -ENOMEM; |
| 1244 | } |
| 1245 | |
| 1246 | rtlpci->tx_ring[prio].buffer_desc = buffer_desc; |
| 1247 | rtlpci->tx_ring[prio].buffer_desc_dma = buffer_desc_dma; |
| 1248 | |
| 1249 | rtlpci->tx_ring[prio].cur_tx_rp = 0; |
| 1250 | rtlpci->tx_ring[prio].cur_tx_wp = 0; |
| 1251 | rtlpci->tx_ring[prio].avl_desc = entries; |
| 1252 | } |
| 1253 | |
| 1254 | /* alloc dma for this ring */ |
| 1255 | desc = pci_zalloc_consistent(rtlpci->pdev, |
| 1256 | sizeof(*desc) * entries, &desc_dma); |
| 1257 | |
| 1258 | if (!desc || (unsigned long)desc & 0xFF) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1259 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1260 | "Cannot allocate TX ring (prio = %d)\n", prio); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1261 | return -ENOMEM; |
| 1262 | } |
| 1263 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1264 | rtlpci->tx_ring[prio].desc = desc; |
| 1265 | rtlpci->tx_ring[prio].dma = desc_dma; |
| 1266 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1267 | rtlpci->tx_ring[prio].idx = 0; |
| 1268 | rtlpci->tx_ring[prio].entries = entries; |
| 1269 | skb_queue_head_init(&rtlpci->tx_ring[prio].queue); |
| 1270 | |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1271 | 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] | 1272 | prio, 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 | /* init every desc in this ring */ |
| 1275 | if (!rtlpriv->use_new_trx_flow) { |
| 1276 | for (i = 0; i < entries; i++) { |
| 1277 | nextdescaddress = (u32)desc_dma + |
| 1278 | ((i + 1) % entries) * |
| 1279 | sizeof(*desc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1280 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1281 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)&desc[i], |
| 1282 | true, |
| 1283 | HW_DESC_TX_NEXTDESC_ADDR, |
| 1284 | (u8 *)&nextdescaddress); |
| 1285 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1286 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1287 | return 0; |
| 1288 | } |
| 1289 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1290 | 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] | 1291 | { |
| 1292 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1293 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1294 | int i; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1295 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1296 | if (rtlpriv->use_new_trx_flow) { |
| 1297 | struct rtl_rx_buffer_desc *entry = NULL; |
| 1298 | /* alloc dma for this ring */ |
| 1299 | rtlpci->rx_ring[rxring_idx].buffer_desc = |
| 1300 | pci_zalloc_consistent(rtlpci->pdev, |
| 1301 | sizeof(*rtlpci->rx_ring[rxring_idx]. |
| 1302 | buffer_desc) * |
| 1303 | rtlpci->rxringcount, |
| 1304 | &rtlpci->rx_ring[rxring_idx].dma); |
| 1305 | if (!rtlpci->rx_ring[rxring_idx].buffer_desc || |
| 1306 | (ulong)rtlpci->rx_ring[rxring_idx].buffer_desc & 0xFF) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1307 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1308 | "Cannot allocate RX ring\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1309 | return -ENOMEM; |
| 1310 | } |
| 1311 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1312 | /* init every desc in this ring */ |
| 1313 | rtlpci->rx_ring[rxring_idx].idx = 0; |
| 1314 | for (i = 0; i < rtlpci->rxringcount; i++) { |
| 1315 | entry = &rtlpci->rx_ring[rxring_idx].buffer_desc[i]; |
| 1316 | if (!_rtl_pci_init_one_rxdesc(hw, (u8 *)entry, |
| 1317 | rxring_idx, i)) |
| 1318 | return -ENOMEM; |
| 1319 | } |
| 1320 | } else { |
| 1321 | struct rtl_rx_desc *entry = NULL; |
| 1322 | u8 tmp_one = 1; |
| 1323 | /* alloc dma for this ring */ |
| 1324 | rtlpci->rx_ring[rxring_idx].desc = |
| 1325 | pci_zalloc_consistent(rtlpci->pdev, |
| 1326 | sizeof(*rtlpci->rx_ring[rxring_idx]. |
| 1327 | desc) * rtlpci->rxringcount, |
| 1328 | &rtlpci->rx_ring[rxring_idx].dma); |
| 1329 | if (!rtlpci->rx_ring[rxring_idx].desc || |
| 1330 | (unsigned long)rtlpci->rx_ring[rxring_idx].desc & 0xFF) { |
| 1331 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 1332 | "Cannot allocate RX ring\n"); |
| 1333 | return -ENOMEM; |
| 1334 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1335 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1336 | /* init every desc in this ring */ |
| 1337 | rtlpci->rx_ring[rxring_idx].idx = 0; |
Larry Finger | 0019a2c | 2011-05-19 11:48:45 -0500 | [diff] [blame] | 1338 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1339 | for (i = 0; i < rtlpci->rxringcount; i++) { |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1340 | entry = &rtlpci->rx_ring[rxring_idx].desc[i]; |
| 1341 | if (!_rtl_pci_init_one_rxdesc(hw, (u8 *)entry, |
| 1342 | rxring_idx, i)) |
| 1343 | return -ENOMEM; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1344 | } |
| 1345 | |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame] | 1346 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false, |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 1347 | HW_DESC_RXERO, &tmp_one); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1348 | } |
| 1349 | return 0; |
| 1350 | } |
| 1351 | |
| 1352 | static void _rtl_pci_free_tx_ring(struct ieee80211_hw *hw, |
| 1353 | unsigned int prio) |
| 1354 | { |
| 1355 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1356 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1357 | struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[prio]; |
| 1358 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1359 | /* free every desc in this ring */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1360 | while (skb_queue_len(&ring->queue)) { |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1361 | u8 *entry; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1362 | struct sk_buff *skb = __skb_dequeue(&ring->queue); |
| 1363 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1364 | if (rtlpriv->use_new_trx_flow) |
| 1365 | entry = (u8 *)(&ring->buffer_desc[ring->idx]); |
| 1366 | else |
| 1367 | entry = (u8 *)(&ring->desc[ring->idx]); |
| 1368 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1369 | pci_unmap_single(rtlpci->pdev, |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1370 | rtlpriv->cfg-> |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1371 | ops->get_desc((u8 *)entry, true, |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1372 | HW_DESC_TXBUFF_ADDR), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1373 | skb->len, PCI_DMA_TODEVICE); |
| 1374 | kfree_skb(skb); |
| 1375 | ring->idx = (ring->idx + 1) % ring->entries; |
| 1376 | } |
| 1377 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1378 | /* free dma of this ring */ |
| 1379 | pci_free_consistent(rtlpci->pdev, |
| 1380 | sizeof(*ring->desc) * ring->entries, |
| 1381 | ring->desc, ring->dma); |
| 1382 | ring->desc = NULL; |
| 1383 | if (rtlpriv->use_new_trx_flow) { |
Simon Graham | 7f66c2f | 2012-02-07 18:07:38 -0600 | [diff] [blame] | 1384 | pci_free_consistent(rtlpci->pdev, |
Larry Finger | caea217 | 2014-11-05 19:10:53 -0600 | [diff] [blame] | 1385 | sizeof(*ring->buffer_desc) * ring->entries, |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1386 | ring->buffer_desc, ring->buffer_desc_dma); |
Larry Finger | caea217 | 2014-11-05 19:10:53 -0600 | [diff] [blame] | 1387 | ring->buffer_desc = NULL; |
Simon Graham | 7f66c2f | 2012-02-07 18:07:38 -0600 | [diff] [blame] | 1388 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1389 | } |
| 1390 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1391 | 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] | 1392 | { |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1393 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1394 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1395 | int i; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1396 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1397 | /* free every desc in this ring */ |
| 1398 | for (i = 0; i < rtlpci->rxringcount; i++) { |
| 1399 | struct sk_buff *skb = rtlpci->rx_ring[rxring_idx].rx_buf[i]; |
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 | if (!skb) |
| 1402 | continue; |
| 1403 | pci_unmap_single(rtlpci->pdev, *((dma_addr_t *)skb->cb), |
| 1404 | rtlpci->rxbuffersize, PCI_DMA_FROMDEVICE); |
| 1405 | kfree_skb(skb); |
| 1406 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1407 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1408 | /* free dma of this ring */ |
| 1409 | if (rtlpriv->use_new_trx_flow) { |
| 1410 | pci_free_consistent(rtlpci->pdev, |
| 1411 | sizeof(*rtlpci->rx_ring[rxring_idx]. |
| 1412 | buffer_desc) * rtlpci->rxringcount, |
| 1413 | rtlpci->rx_ring[rxring_idx].buffer_desc, |
| 1414 | rtlpci->rx_ring[rxring_idx].dma); |
| 1415 | rtlpci->rx_ring[rxring_idx].buffer_desc = NULL; |
| 1416 | } else { |
| 1417 | pci_free_consistent(rtlpci->pdev, |
| 1418 | sizeof(*rtlpci->rx_ring[rxring_idx].desc) * |
| 1419 | rtlpci->rxringcount, |
| 1420 | rtlpci->rx_ring[rxring_idx].desc, |
| 1421 | rtlpci->rx_ring[rxring_idx].dma); |
| 1422 | rtlpci->rx_ring[rxring_idx].desc = NULL; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1423 | } |
| 1424 | } |
| 1425 | |
| 1426 | static int _rtl_pci_init_trx_ring(struct ieee80211_hw *hw) |
| 1427 | { |
| 1428 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1429 | int ret; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1430 | int i, rxring_idx; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1431 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1432 | /* rxring_idx 0:RX_MPDU_QUEUE |
| 1433 | * rxring_idx 1:RX_CMD_QUEUE |
| 1434 | */ |
| 1435 | for (rxring_idx = 0; rxring_idx < RTL_PCI_MAX_RX_QUEUE; rxring_idx++) { |
| 1436 | ret = _rtl_pci_init_rx_ring(hw, rxring_idx); |
| 1437 | if (ret) |
| 1438 | return ret; |
| 1439 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1440 | |
| 1441 | for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) { |
| 1442 | ret = _rtl_pci_init_tx_ring(hw, i, |
| 1443 | rtlpci->txringcount[i]); |
| 1444 | if (ret) |
| 1445 | goto err_free_rings; |
| 1446 | } |
| 1447 | |
| 1448 | return 0; |
| 1449 | |
| 1450 | err_free_rings: |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1451 | for (rxring_idx = 0; rxring_idx < RTL_PCI_MAX_RX_QUEUE; rxring_idx++) |
| 1452 | _rtl_pci_free_rx_ring(hw, rxring_idx); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1453 | |
| 1454 | for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1455 | if (rtlpci->tx_ring[i].desc || |
| 1456 | rtlpci->tx_ring[i].buffer_desc) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1457 | _rtl_pci_free_tx_ring(hw, i); |
| 1458 | |
| 1459 | return 1; |
| 1460 | } |
| 1461 | |
| 1462 | static int _rtl_pci_deinit_trx_ring(struct ieee80211_hw *hw) |
| 1463 | { |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1464 | u32 i, rxring_idx; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1465 | |
| 1466 | /*free rx rings */ |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1467 | for (rxring_idx = 0; rxring_idx < RTL_PCI_MAX_RX_QUEUE; rxring_idx++) |
| 1468 | _rtl_pci_free_rx_ring(hw, rxring_idx); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1469 | |
| 1470 | /*free tx rings */ |
| 1471 | for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) |
| 1472 | _rtl_pci_free_tx_ring(hw, i); |
| 1473 | |
| 1474 | return 0; |
| 1475 | } |
| 1476 | |
| 1477 | int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw) |
| 1478 | { |
| 1479 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1480 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1481 | int i, rxring_idx; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1482 | unsigned long flags; |
| 1483 | u8 tmp_one = 1; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1484 | u32 bufferaddress; |
| 1485 | /* rxring_idx 0:RX_MPDU_QUEUE */ |
| 1486 | /* rxring_idx 1:RX_CMD_QUEUE */ |
| 1487 | for (rxring_idx = 0; rxring_idx < RTL_PCI_MAX_RX_QUEUE; rxring_idx++) { |
| 1488 | /* force the rx_ring[RX_MPDU_QUEUE/ |
| 1489 | * RX_CMD_QUEUE].idx to the first one |
| 1490 | *new trx flow, do nothing |
| 1491 | */ |
| 1492 | if (!rtlpriv->use_new_trx_flow && |
| 1493 | rtlpci->rx_ring[rxring_idx].desc) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1494 | struct rtl_rx_desc *entry = NULL; |
| 1495 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1496 | rtlpci->rx_ring[rxring_idx].idx = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1497 | for (i = 0; i < rtlpci->rxringcount; i++) { |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1498 | entry = &rtlpci->rx_ring[rxring_idx].desc[i]; |
| 1499 | bufferaddress = |
| 1500 | rtlpriv->cfg->ops->get_desc((u8 *)entry, |
| 1501 | false , HW_DESC_RXBUFF_ADDR); |
| 1502 | memset((u8 *)entry , 0 , |
| 1503 | sizeof(*rtlpci->rx_ring |
| 1504 | [rxring_idx].desc));/*clear one entry*/ |
| 1505 | if (rtlpriv->use_new_trx_flow) { |
| 1506 | rtlpriv->cfg->ops->set_desc(hw, |
| 1507 | (u8 *)entry, false, |
| 1508 | HW_DESC_RX_PREPARE, |
| 1509 | (u8 *)&bufferaddress); |
| 1510 | } else { |
| 1511 | rtlpriv->cfg->ops->set_desc(hw, |
| 1512 | (u8 *)entry, false, |
| 1513 | HW_DESC_RXBUFF_ADDR, |
| 1514 | (u8 *)&bufferaddress); |
| 1515 | rtlpriv->cfg->ops->set_desc(hw, |
| 1516 | (u8 *)entry, false, |
| 1517 | HW_DESC_RXPKT_LEN, |
| 1518 | (u8 *)&rtlpci->rxbuffersize); |
| 1519 | rtlpriv->cfg->ops->set_desc(hw, |
| 1520 | (u8 *)entry, false, |
| 1521 | HW_DESC_RXOWN, |
| 1522 | (u8 *)&tmp_one); |
| 1523 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1524 | } |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1525 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false, |
| 1526 | HW_DESC_RXERO, (u8 *)&tmp_one); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1527 | } |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1528 | rtlpci->rx_ring[rxring_idx].idx = 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1529 | } |
| 1530 | |
| 1531 | /* |
| 1532 | *after reset, release previous pending packet, |
| 1533 | *and force the tx idx to the first one |
| 1534 | */ |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1535 | spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1536 | for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) { |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1537 | if (rtlpci->tx_ring[i].desc || |
| 1538 | rtlpci->tx_ring[i].buffer_desc) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1539 | struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[i]; |
| 1540 | |
| 1541 | while (skb_queue_len(&ring->queue)) { |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1542 | u8 *entry; |
| 1543 | struct sk_buff *skb = |
| 1544 | __skb_dequeue(&ring->queue); |
| 1545 | if (rtlpriv->use_new_trx_flow) |
| 1546 | entry = (u8 *)(&ring->buffer_desc |
| 1547 | [ring->idx]); |
| 1548 | else |
| 1549 | entry = (u8 *)(&ring->desc[ring->idx]); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1550 | |
| 1551 | pci_unmap_single(rtlpci->pdev, |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1552 | rtlpriv->cfg->ops-> |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1553 | get_desc((u8 *) |
| 1554 | entry, |
| 1555 | true, |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1556 | HW_DESC_TXBUFF_ADDR), |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1557 | skb->len, PCI_DMA_TODEVICE); |
Larry Finger | 5a2766a | 2012-06-24 11:06:29 -0500 | [diff] [blame] | 1558 | kfree_skb(skb); |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1559 | ring->idx = (ring->idx + 1) % ring->entries; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1560 | } |
| 1561 | ring->idx = 0; |
| 1562 | } |
| 1563 | } |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1564 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1565 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1566 | return 0; |
| 1567 | } |
| 1568 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1569 | static bool rtl_pci_tx_chk_waitq_insert(struct ieee80211_hw *hw, |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 1570 | struct ieee80211_sta *sta, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1571 | struct sk_buff *skb) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1572 | { |
| 1573 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1574 | struct rtl_sta_info *sta_entry = NULL; |
| 1575 | u8 tid = rtl_get_tid(skb); |
Larry Finger | 0f01545 | 2012-10-25 13:46:46 -0500 | [diff] [blame] | 1576 | __le16 fc = rtl_get_fc(skb); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1577 | |
| 1578 | if (!sta) |
| 1579 | return false; |
| 1580 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1581 | |
| 1582 | if (!rtlpriv->rtlhal.earlymode_enable) |
| 1583 | return false; |
Larry Finger | 0f01545 | 2012-10-25 13:46:46 -0500 | [diff] [blame] | 1584 | if (ieee80211_is_nullfunc(fc)) |
| 1585 | return false; |
| 1586 | if (ieee80211_is_qos_nullfunc(fc)) |
| 1587 | return false; |
| 1588 | if (ieee80211_is_pspoll(fc)) |
| 1589 | return false; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1590 | if (sta_entry->tids[tid].agg.agg_state != RTL_AGG_OPERATIONAL) |
| 1591 | return false; |
| 1592 | if (_rtl_mac_to_hwqueue(hw, skb) > VO_QUEUE) |
| 1593 | return false; |
| 1594 | if (tid > 7) |
| 1595 | return false; |
| 1596 | |
| 1597 | /* maybe every tid should be checked */ |
| 1598 | if (!rtlpriv->link_info.higher_busytxtraffic[tid]) |
| 1599 | return false; |
| 1600 | |
| 1601 | spin_lock_bh(&rtlpriv->locks.waitq_lock); |
| 1602 | skb_queue_tail(&rtlpriv->mac80211.skb_waitq[tid], skb); |
| 1603 | spin_unlock_bh(&rtlpriv->locks.waitq_lock); |
| 1604 | |
| 1605 | return true; |
| 1606 | } |
| 1607 | |
Thomas Huehn | 36323f8 | 2012-07-23 21:33:42 +0200 | [diff] [blame] | 1608 | static int rtl_pci_tx(struct ieee80211_hw *hw, |
| 1609 | struct ieee80211_sta *sta, |
| 1610 | struct sk_buff *skb, |
| 1611 | struct rtl_tcb_desc *ptcb_desc) |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1612 | { |
| 1613 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1614 | struct rtl_sta_info *sta_entry = NULL; |
| 1615 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1616 | struct rtl8192_tx_ring *ring; |
| 1617 | struct rtl_tx_desc *pdesc; |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame] | 1618 | struct rtl_tx_buffer_desc *ptx_bd_desc = NULL; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1619 | u16 idx; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1620 | u8 hw_queue = _rtl_mac_to_hwqueue(hw, skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1621 | unsigned long flags; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1622 | struct ieee80211_hdr *hdr = rtl_get_hdr(skb); |
| 1623 | __le16 fc = rtl_get_fc(skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1624 | u8 *pda_addr = hdr->addr1; |
| 1625 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1626 | /*ssn */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1627 | u8 tid = 0; |
| 1628 | u16 seq_number = 0; |
| 1629 | u8 own; |
| 1630 | u8 temp_one = 1; |
| 1631 | |
Larry Finger | 0f01545 | 2012-10-25 13:46:46 -0500 | [diff] [blame] | 1632 | if (ieee80211_is_mgmt(fc)) |
| 1633 | rtl_tx_mgmt_proc(hw, skb); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1634 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1635 | if (rtlpriv->psc.sw_ps_enabled) { |
| 1636 | if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) && |
| 1637 | !ieee80211_has_pm(fc)) |
| 1638 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
| 1639 | } |
| 1640 | |
| 1641 | rtl_action_proc(hw, skb, true); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1642 | |
| 1643 | if (is_multicast_ether_addr(pda_addr)) |
| 1644 | rtlpriv->stats.txbytesmulticast += skb->len; |
| 1645 | else if (is_broadcast_ether_addr(pda_addr)) |
| 1646 | rtlpriv->stats.txbytesbroadcast += skb->len; |
| 1647 | else |
| 1648 | rtlpriv->stats.txbytesunicast += skb->len; |
| 1649 | |
| 1650 | spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1651 | ring = &rtlpci->tx_ring[hw_queue]; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1652 | if (hw_queue != BEACON_QUEUE) { |
| 1653 | if (rtlpriv->use_new_trx_flow) |
| 1654 | idx = ring->cur_tx_wp; |
| 1655 | else |
| 1656 | idx = (ring->idx + skb_queue_len(&ring->queue)) % |
| 1657 | ring->entries; |
| 1658 | } else { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1659 | idx = 0; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1660 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1661 | |
| 1662 | pdesc = &ring->desc[idx]; |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame] | 1663 | if (rtlpriv->use_new_trx_flow) { |
| 1664 | ptx_bd_desc = &ring->buffer_desc[idx]; |
| 1665 | } else { |
| 1666 | own = (u8) rtlpriv->cfg->ops->get_desc((u8 *)pdesc, |
| 1667 | true, HW_DESC_OWN); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1668 | |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame] | 1669 | if ((own == 1) && (hw_queue != BEACON_QUEUE)) { |
| 1670 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Hans Wennborg | 4f4378d | 2014-09-05 20:19:50 -0700 | [diff] [blame] | 1671 | "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] | 1672 | hw_queue, ring->idx, idx, |
| 1673 | skb_queue_len(&ring->queue)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1674 | |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame] | 1675 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, |
| 1676 | flags); |
| 1677 | return skb->len; |
| 1678 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1679 | } |
| 1680 | |
Troy Tan | d031131 | 2015-02-03 11:15:17 -0600 | [diff] [blame] | 1681 | if (rtlpriv->cfg->ops->get_available_desc && |
| 1682 | rtlpriv->cfg->ops->get_available_desc(hw, hw_queue) == 0) { |
| 1683 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
| 1684 | "get_available_desc fail\n"); |
| 1685 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, |
| 1686 | flags); |
| 1687 | return skb->len; |
| 1688 | } |
| 1689 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1690 | if (ieee80211_is_data_qos(fc)) { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1691 | tid = rtl_get_tid(skb); |
| 1692 | if (sta) { |
| 1693 | sta_entry = (struct rtl_sta_info *)sta->drv_priv; |
| 1694 | seq_number = (le16_to_cpu(hdr->seq_ctrl) & |
| 1695 | IEEE80211_SCTL_SEQ) >> 4; |
| 1696 | seq_number += 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1697 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1698 | if (!ieee80211_has_morefrags(hdr->frame_control)) |
| 1699 | sta_entry->tids[tid].seq_number = seq_number; |
| 1700 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | if (ieee80211_is_data(fc)) |
| 1704 | rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX); |
| 1705 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1706 | rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc, |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame] | 1707 | (u8 *)ptx_bd_desc, info, sta, skb, hw_queue, ptcb_desc); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1708 | |
| 1709 | __skb_queue_tail(&ring->queue, skb); |
| 1710 | |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame] | 1711 | if (rtlpriv->use_new_trx_flow) { |
| 1712 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, true, |
Joe Perches | 9cb76aa | 2014-03-24 10:46:20 -0700 | [diff] [blame] | 1713 | HW_DESC_OWN, &hw_queue); |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame] | 1714 | } else { |
| 1715 | rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, true, |
Joe Perches | 9cb76aa | 2014-03-24 10:46:20 -0700 | [diff] [blame] | 1716 | HW_DESC_OWN, &temp_one); |
Larry Finger | f3355dd | 2014-03-04 16:53:47 -0600 | [diff] [blame] | 1717 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1718 | |
| 1719 | if ((ring->entries - skb_queue_len(&ring->queue)) < 2 && |
| 1720 | hw_queue != BEACON_QUEUE) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1721 | RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD, |
Hans Wennborg | 4f4378d | 2014-09-05 20:19:50 -0700 | [diff] [blame] | 1722 | "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] | 1723 | hw_queue, ring->idx, idx, |
| 1724 | skb_queue_len(&ring->queue)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1725 | |
| 1726 | ieee80211_stop_queue(hw, skb_get_queue_mapping(skb)); |
| 1727 | } |
| 1728 | |
| 1729 | spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags); |
| 1730 | |
| 1731 | rtlpriv->cfg->ops->tx_polling(hw, hw_queue); |
| 1732 | |
| 1733 | return 0; |
| 1734 | } |
| 1735 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1736 | 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] | 1737 | { |
| 1738 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1739 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 1740 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1741 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1742 | u16 i = 0; |
| 1743 | int queue_id; |
| 1744 | struct rtl8192_tx_ring *ring; |
| 1745 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 1746 | if (mac->skip_scan) |
| 1747 | return; |
| 1748 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1749 | for (queue_id = RTL_PCI_MAX_TX_QUEUE_COUNT - 1; queue_id >= 0;) { |
| 1750 | u32 queue_len; |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1751 | |
| 1752 | if (((queues >> queue_id) & 0x1) == 0) { |
| 1753 | queue_id--; |
| 1754 | continue; |
| 1755 | } |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1756 | ring = &pcipriv->dev.tx_ring[queue_id]; |
| 1757 | queue_len = skb_queue_len(&ring->queue); |
| 1758 | if (queue_len == 0 || queue_id == BEACON_QUEUE || |
| 1759 | queue_id == TXCMD_QUEUE) { |
| 1760 | queue_id--; |
| 1761 | continue; |
| 1762 | } else { |
| 1763 | msleep(20); |
| 1764 | i++; |
| 1765 | } |
| 1766 | |
| 1767 | /* we just wait 1s for all queues */ |
| 1768 | if (rtlpriv->psc.rfpwr_state == ERFOFF || |
| 1769 | is_hal_stop(rtlhal) || i >= 200) |
| 1770 | return; |
| 1771 | } |
| 1772 | } |
| 1773 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1774 | static void rtl_pci_deinit(struct ieee80211_hw *hw) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1775 | { |
| 1776 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1777 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1778 | |
| 1779 | _rtl_pci_deinit_trx_ring(hw); |
| 1780 | |
| 1781 | synchronize_irq(rtlpci->pdev->irq); |
| 1782 | tasklet_kill(&rtlpriv->works.irq_tasklet); |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1783 | cancel_work_sync(&rtlpriv->works.lps_change_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1784 | |
| 1785 | flush_workqueue(rtlpriv->works.rtl_wq); |
| 1786 | destroy_workqueue(rtlpriv->works.rtl_wq); |
| 1787 | |
| 1788 | } |
| 1789 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1790 | 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] | 1791 | { |
| 1792 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1793 | int err; |
| 1794 | |
| 1795 | _rtl_pci_init_struct(hw, pdev); |
| 1796 | |
| 1797 | err = _rtl_pci_init_trx_ring(hw); |
| 1798 | if (err) { |
| 1799 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1800 | "tx ring initialization failed\n"); |
John W. Linville | 1232528 | 2012-02-09 14:48:25 -0500 | [diff] [blame] | 1801 | return err; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1802 | } |
| 1803 | |
John W. Linville | 1232528 | 2012-02-09 14:48:25 -0500 | [diff] [blame] | 1804 | return 0; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1805 | } |
| 1806 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1807 | static int rtl_pci_start(struct ieee80211_hw *hw) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1808 | { |
| 1809 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1810 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1811 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1812 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 1813 | |
| 1814 | int err; |
| 1815 | |
| 1816 | rtl_pci_reset_trx_ring(hw); |
| 1817 | |
| 1818 | rtlpci->driver_is_goingto_unload = false; |
Larry Finger | 0805420 | 2014-10-23 11:27:09 -0500 | [diff] [blame] | 1819 | if (rtlpriv->cfg->ops->get_btc_status && |
| 1820 | rtlpriv->cfg->ops->get_btc_status()) { |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1821 | rtlpriv->btcoexist.btc_ops->btc_init_variables(rtlpriv); |
| 1822 | rtlpriv->btcoexist.btc_ops->btc_init_hal_vars(rtlpriv); |
| 1823 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1824 | err = rtlpriv->cfg->ops->hw_init(hw); |
| 1825 | if (err) { |
| 1826 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1827 | "Failed to config hardware!\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1828 | return err; |
| 1829 | } |
| 1830 | |
| 1831 | rtlpriv->cfg->ops->enable_interrupt(hw); |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1832 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "enable_interrupt OK\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1833 | |
| 1834 | rtl_init_rx_config(hw); |
| 1835 | |
Vitaliy Ivanov | fb914eb | 2011-06-23 20:01:55 +0300 | [diff] [blame] | 1836 | /*should be after adapter start and interrupt enable. */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1837 | set_hal_start(rtlhal); |
| 1838 | |
| 1839 | RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); |
| 1840 | |
| 1841 | rtlpci->up_first_time = false; |
| 1842 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1843 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "rtl_pci_start OK\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1844 | return 0; |
| 1845 | } |
| 1846 | |
Larry Finger | d3bb142 | 2011-04-25 13:23:20 -0500 | [diff] [blame] | 1847 | static void rtl_pci_stop(struct ieee80211_hw *hw) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1848 | { |
| 1849 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1850 | struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); |
| 1851 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); |
| 1852 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1853 | unsigned long flags; |
| 1854 | u8 RFInProgressTimeOut = 0; |
| 1855 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1856 | if (rtlpriv->cfg->ops->get_btc_status()) |
| 1857 | rtlpriv->btcoexist.btc_ops->btc_halt_notify(); |
| 1858 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1859 | /* |
Vitaliy Ivanov | fb914eb | 2011-06-23 20:01:55 +0300 | [diff] [blame] | 1860 | *should be before disable interrupt&adapter |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1861 | *and will do it immediately. |
| 1862 | */ |
| 1863 | set_hal_stop(rtlhal); |
| 1864 | |
Larry Finger | 9278db6 | 2013-12-11 17:13:10 -0600 | [diff] [blame] | 1865 | rtlpci->driver_is_goingto_unload = true; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1866 | rtlpriv->cfg->ops->disable_interrupt(hw); |
Larry Finger | a269913 | 2013-03-24 22:06:41 -0500 | [diff] [blame] | 1867 | cancel_work_sync(&rtlpriv->works.lps_change_work); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1868 | |
| 1869 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags); |
| 1870 | while (ppsc->rfchange_inprogress) { |
| 1871 | spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags); |
| 1872 | if (RFInProgressTimeOut > 100) { |
| 1873 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags); |
| 1874 | break; |
| 1875 | } |
| 1876 | mdelay(1); |
| 1877 | RFInProgressTimeOut++; |
| 1878 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags); |
| 1879 | } |
| 1880 | ppsc->rfchange_inprogress = true; |
| 1881 | spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags); |
| 1882 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1883 | rtlpriv->cfg->ops->hw_disable(hw); |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 1884 | /* some things are not needed if firmware not available */ |
| 1885 | if (!rtlpriv->max_fw_size) |
| 1886 | return; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1887 | rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF); |
| 1888 | |
| 1889 | spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags); |
| 1890 | ppsc->rfchange_inprogress = false; |
| 1891 | spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags); |
| 1892 | |
| 1893 | rtl_pci_enable_aspm(hw); |
| 1894 | } |
| 1895 | |
| 1896 | static bool _rtl_pci_find_adapter(struct pci_dev *pdev, |
| 1897 | struct ieee80211_hw *hw) |
| 1898 | { |
| 1899 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 1900 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 1901 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 1902 | struct pci_dev *bridge_pdev = pdev->bus->self; |
| 1903 | u16 venderid; |
| 1904 | u16 deviceid; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1905 | u8 revisionid; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1906 | u16 irqline; |
| 1907 | u8 tmp; |
| 1908 | |
Chaoming Li | fc7707a | 2011-05-06 15:32:02 -0500 | [diff] [blame] | 1909 | pcipriv->ndis_adapter.pcibridge_vendor = PCI_BRIDGE_VENDOR_UNKNOWN; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1910 | venderid = pdev->vendor; |
| 1911 | deviceid = pdev->device; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1912 | pci_read_config_byte(pdev, 0x8, &revisionid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1913 | pci_read_config_word(pdev, 0x3C, &irqline); |
| 1914 | |
Larry Finger | fa7ccfb | 2011-06-18 22:49:53 -0500 | [diff] [blame] | 1915 | /* PCI ID 0x10ec:0x8192 occurs for both RTL8192E, which uses |
| 1916 | * r8192e_pci, and RTL8192SE, which uses this driver. If the |
| 1917 | * revision ID is RTL_PCI_REVISION_ID_8192PCIE (0x01), then |
| 1918 | * the correct driver is r8192e_pci, thus this routine should |
| 1919 | * return false. |
| 1920 | */ |
| 1921 | if (deviceid == RTL_PCI_8192SE_DID && |
| 1922 | revisionid == RTL_PCI_REVISION_ID_8192PCIE) |
| 1923 | return false; |
| 1924 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1925 | if (deviceid == RTL_PCI_8192_DID || |
| 1926 | deviceid == RTL_PCI_0044_DID || |
| 1927 | deviceid == RTL_PCI_0047_DID || |
| 1928 | deviceid == RTL_PCI_8192SE_DID || |
| 1929 | deviceid == RTL_PCI_8174_DID || |
| 1930 | deviceid == RTL_PCI_8173_DID || |
| 1931 | deviceid == RTL_PCI_8172_DID || |
| 1932 | deviceid == RTL_PCI_8171_DID) { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1933 | switch (revisionid) { |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1934 | case RTL_PCI_REVISION_ID_8192PCIE: |
| 1935 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1936 | "8192 PCI-E is found - vid/did=%x/%x\n", |
| 1937 | venderid, deviceid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1938 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192E; |
Larry Finger | 0f01545 | 2012-10-25 13:46:46 -0500 | [diff] [blame] | 1939 | return false; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1940 | case RTL_PCI_REVISION_ID_8192SE: |
| 1941 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1942 | "8192SE is found - vid/did=%x/%x\n", |
| 1943 | venderid, deviceid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1944 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192SE; |
| 1945 | break; |
| 1946 | default: |
| 1947 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1948 | "Err: Unknown device - vid/did=%x/%x\n", |
| 1949 | venderid, deviceid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1950 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192SE; |
| 1951 | break; |
| 1952 | |
| 1953 | } |
Larry Finger | 0f01545 | 2012-10-25 13:46:46 -0500 | [diff] [blame] | 1954 | } else if (deviceid == RTL_PCI_8723AE_DID) { |
| 1955 | rtlhal->hw_type = HARDWARE_TYPE_RTL8723AE; |
| 1956 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
| 1957 | "8723AE PCI-E is found - " |
| 1958 | "vid/did=%x/%x\n", venderid, deviceid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1959 | } else if (deviceid == RTL_PCI_8192CET_DID || |
| 1960 | deviceid == RTL_PCI_8192CE_DID || |
| 1961 | deviceid == RTL_PCI_8191CE_DID || |
| 1962 | deviceid == RTL_PCI_8188CE_DID) { |
| 1963 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192CE; |
| 1964 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1965 | "8192C PCI-E is found - vid/did=%x/%x\n", |
| 1966 | venderid, deviceid); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 1967 | } else if (deviceid == RTL_PCI_8192DE_DID || |
| 1968 | deviceid == RTL_PCI_8192DE_DID2) { |
| 1969 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192DE; |
| 1970 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1971 | "8192D PCI-E is found - vid/did=%x/%x\n", |
| 1972 | venderid, deviceid); |
Larry Finger | 5c69177d | 2013-03-24 22:06:56 -0500 | [diff] [blame] | 1973 | } else if (deviceid == RTL_PCI_8188EE_DID) { |
| 1974 | rtlhal->hw_type = HARDWARE_TYPE_RTL8188EE; |
| 1975 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, |
| 1976 | "Find adapter, Hardware type is 8188EE\n"); |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 1977 | } else if (deviceid == RTL_PCI_8723BE_DID) { |
| 1978 | rtlhal->hw_type = HARDWARE_TYPE_RTL8723BE; |
| 1979 | RT_TRACE(rtlpriv, COMP_INIT , DBG_LOUD, |
| 1980 | "Find adapter, Hardware type is 8723BE\n"); |
| 1981 | } else if (deviceid == RTL_PCI_8192EE_DID) { |
| 1982 | rtlhal->hw_type = HARDWARE_TYPE_RTL8192EE; |
| 1983 | RT_TRACE(rtlpriv, COMP_INIT , DBG_LOUD, |
| 1984 | "Find adapter, Hardware type is 8192EE\n"); |
| 1985 | } else if (deviceid == RTL_PCI_8821AE_DID) { |
| 1986 | rtlhal->hw_type = HARDWARE_TYPE_RTL8821AE; |
| 1987 | RT_TRACE(rtlpriv, COMP_INIT , DBG_LOUD, |
| 1988 | "Find adapter, Hardware type is 8821AE\n"); |
| 1989 | } else if (deviceid == RTL_PCI_8812AE_DID) { |
| 1990 | rtlhal->hw_type = HARDWARE_TYPE_RTL8812AE; |
| 1991 | RT_TRACE(rtlpriv, COMP_INIT , DBG_LOUD, |
| 1992 | "Find adapter, Hardware type is 8812AE\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1993 | } else { |
| 1994 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 1995 | "Err: Unknown device - vid/did=%x/%x\n", |
| 1996 | venderid, deviceid); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1997 | |
| 1998 | rtlhal->hw_type = RTL_DEFAULT_HARDWARE_TYPE; |
| 1999 | } |
| 2000 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2001 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE) { |
| 2002 | if (revisionid == 0 || revisionid == 1) { |
| 2003 | if (revisionid == 0) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2004 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, |
| 2005 | "Find 92DE MAC0\n"); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2006 | rtlhal->interfaceindex = 0; |
| 2007 | } else if (revisionid == 1) { |
| 2008 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2009 | "Find 92DE MAC1\n"); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2010 | rtlhal->interfaceindex = 1; |
| 2011 | } |
| 2012 | } else { |
| 2013 | RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2014 | "Unknown device - VendorID/DeviceID=%x/%x, Revision=%x\n", |
| 2015 | venderid, deviceid, revisionid); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2016 | rtlhal->interfaceindex = 0; |
| 2017 | } |
| 2018 | } |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 2019 | |
| 2020 | /* 92ee use new trx flow */ |
| 2021 | if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) |
| 2022 | rtlpriv->use_new_trx_flow = true; |
| 2023 | else |
| 2024 | rtlpriv->use_new_trx_flow = false; |
| 2025 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2026 | /*find bus info */ |
| 2027 | pcipriv->ndis_adapter.busnumber = pdev->bus->number; |
| 2028 | pcipriv->ndis_adapter.devnumber = PCI_SLOT(pdev->devfn); |
| 2029 | pcipriv->ndis_adapter.funcnumber = PCI_FUNC(pdev->devfn); |
| 2030 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 2031 | /*find bridge info */ |
| 2032 | pcipriv->ndis_adapter.pcibridge_vendor = PCI_BRIDGE_VENDOR_UNKNOWN; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2033 | /* some ARM have no bridge_pdev and will crash here |
| 2034 | * so we should check if bridge_pdev is NULL |
| 2035 | */ |
Larry Finger | b6b67df | 2011-07-29 10:53:12 -0500 | [diff] [blame] | 2036 | if (bridge_pdev) { |
| 2037 | /*find bridge info if available */ |
| 2038 | pcipriv->ndis_adapter.pcibridge_vendorid = bridge_pdev->vendor; |
| 2039 | for (tmp = 0; tmp < PCI_BRIDGE_VENDOR_MAX; tmp++) { |
| 2040 | if (bridge_pdev->vendor == pcibridge_vendors[tmp]) { |
| 2041 | pcipriv->ndis_adapter.pcibridge_vendor = tmp; |
| 2042 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2043 | "Pci Bridge Vendor is found index: %d\n", |
| 2044 | tmp); |
Larry Finger | b6b67df | 2011-07-29 10:53:12 -0500 | [diff] [blame] | 2045 | break; |
| 2046 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | if (pcipriv->ndis_adapter.pcibridge_vendor != |
| 2051 | PCI_BRIDGE_VENDOR_UNKNOWN) { |
| 2052 | pcipriv->ndis_adapter.pcibridge_busnum = |
| 2053 | bridge_pdev->bus->number; |
| 2054 | pcipriv->ndis_adapter.pcibridge_devnum = |
| 2055 | PCI_SLOT(bridge_pdev->devfn); |
| 2056 | pcipriv->ndis_adapter.pcibridge_funcnum = |
| 2057 | PCI_FUNC(bridge_pdev->devfn); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2058 | pcipriv->ndis_adapter.pcibridge_pciehdr_offset = |
| 2059 | pci_pcie_cap(bridge_pdev); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2060 | pcipriv->ndis_adapter.num4bytes = |
| 2061 | (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10) / 4; |
| 2062 | |
| 2063 | rtl_pci_get_linkcontrol_field(hw); |
| 2064 | |
| 2065 | if (pcipriv->ndis_adapter.pcibridge_vendor == |
| 2066 | PCI_BRIDGE_VENDOR_AMD) { |
| 2067 | pcipriv->ndis_adapter.amd_l1_patch = |
| 2068 | rtl_pci_get_amd_l1_patch(hw); |
| 2069 | } |
| 2070 | } |
| 2071 | |
| 2072 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2073 | "pcidev busnumber:devnumber:funcnumber:vendor:link_ctl %d:%d:%d:%x:%x\n", |
| 2074 | pcipriv->ndis_adapter.busnumber, |
| 2075 | pcipriv->ndis_adapter.devnumber, |
| 2076 | pcipriv->ndis_adapter.funcnumber, |
| 2077 | pdev->vendor, pcipriv->ndis_adapter.linkctrl_reg); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2078 | |
| 2079 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2080 | "pci_bridge busnumber:devnumber:funcnumber:vendor:pcie_cap:link_ctl_reg:amd %d:%d:%d:%x:%x:%x:%x\n", |
| 2081 | pcipriv->ndis_adapter.pcibridge_busnum, |
| 2082 | pcipriv->ndis_adapter.pcibridge_devnum, |
| 2083 | pcipriv->ndis_adapter.pcibridge_funcnum, |
| 2084 | pcibridge_vendors[pcipriv->ndis_adapter.pcibridge_vendor], |
| 2085 | pcipriv->ndis_adapter.pcibridge_pciehdr_offset, |
| 2086 | pcipriv->ndis_adapter.pcibridge_linkctrlreg, |
| 2087 | pcipriv->ndis_adapter.amd_l1_patch); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2088 | |
| 2089 | rtl_pci_parse_configuration(pdev, hw); |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2090 | list_add_tail(&rtlpriv->list, &rtlpriv->glb_var->glb_priv_list); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2091 | |
| 2092 | return true; |
| 2093 | } |
| 2094 | |
Adam Lee | 94010fa | 2014-03-28 11:36:18 +0800 | [diff] [blame] | 2095 | static int rtl_pci_intr_mode_msi(struct ieee80211_hw *hw) |
| 2096 | { |
| 2097 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2098 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 2099 | struct rtl_pci *rtlpci = rtl_pcidev(pcipriv); |
| 2100 | int ret; |
| 2101 | |
| 2102 | ret = pci_enable_msi(rtlpci->pdev); |
| 2103 | if (ret < 0) |
| 2104 | return ret; |
| 2105 | |
| 2106 | ret = request_irq(rtlpci->pdev->irq, &_rtl_pci_interrupt, |
| 2107 | IRQF_SHARED, KBUILD_MODNAME, hw); |
| 2108 | if (ret < 0) { |
| 2109 | pci_disable_msi(rtlpci->pdev); |
| 2110 | return ret; |
| 2111 | } |
| 2112 | |
| 2113 | rtlpci->using_msi = true; |
| 2114 | |
| 2115 | RT_TRACE(rtlpriv, COMP_INIT|COMP_INTR, DBG_DMESG, |
| 2116 | "MSI Interrupt Mode!\n"); |
| 2117 | return 0; |
| 2118 | } |
| 2119 | |
| 2120 | static int rtl_pci_intr_mode_legacy(struct ieee80211_hw *hw) |
| 2121 | { |
| 2122 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2123 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 2124 | struct rtl_pci *rtlpci = rtl_pcidev(pcipriv); |
| 2125 | int ret; |
| 2126 | |
| 2127 | ret = request_irq(rtlpci->pdev->irq, &_rtl_pci_interrupt, |
| 2128 | IRQF_SHARED, KBUILD_MODNAME, hw); |
| 2129 | if (ret < 0) |
| 2130 | return ret; |
| 2131 | |
| 2132 | rtlpci->using_msi = false; |
| 2133 | RT_TRACE(rtlpriv, COMP_INIT|COMP_INTR, DBG_DMESG, |
| 2134 | "Pin-based Interrupt Mode!\n"); |
| 2135 | return 0; |
| 2136 | } |
| 2137 | |
| 2138 | static int rtl_pci_intr_mode_decide(struct ieee80211_hw *hw) |
| 2139 | { |
| 2140 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 2141 | struct rtl_pci *rtlpci = rtl_pcidev(pcipriv); |
| 2142 | int ret; |
| 2143 | |
| 2144 | if (rtlpci->msi_support) { |
| 2145 | ret = rtl_pci_intr_mode_msi(hw); |
| 2146 | if (ret < 0) |
| 2147 | ret = rtl_pci_intr_mode_legacy(hw); |
| 2148 | } else { |
| 2149 | ret = rtl_pci_intr_mode_legacy(hw); |
| 2150 | } |
| 2151 | return ret; |
| 2152 | } |
| 2153 | |
Bill Pemberton | 9e2ff36 | 2012-12-03 09:56:43 -0500 | [diff] [blame] | 2154 | int rtl_pci_probe(struct pci_dev *pdev, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2155 | const struct pci_device_id *id) |
| 2156 | { |
| 2157 | struct ieee80211_hw *hw = NULL; |
| 2158 | |
| 2159 | struct rtl_priv *rtlpriv = NULL; |
| 2160 | struct rtl_pci_priv *pcipriv = NULL; |
| 2161 | struct rtl_pci *rtlpci; |
| 2162 | unsigned long pmem_start, pmem_len, pmem_flags; |
| 2163 | int err; |
| 2164 | |
| 2165 | err = pci_enable_device(pdev); |
| 2166 | if (err) { |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 2167 | RT_ASSERT(false, "%s : Cannot enable new PCI device\n", |
| 2168 | pci_name(pdev)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2169 | return err; |
| 2170 | } |
| 2171 | |
| 2172 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { |
| 2173 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) { |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 2174 | RT_ASSERT(false, |
| 2175 | "Unable to obtain 32bit DMA for consistent allocations\n"); |
Tim Gardner | 3d86b93 | 2012-02-02 13:48:06 -0700 | [diff] [blame] | 2176 | err = -ENOMEM; |
| 2177 | goto fail1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2178 | } |
| 2179 | } |
| 2180 | |
| 2181 | pci_set_master(pdev); |
| 2182 | |
| 2183 | hw = ieee80211_alloc_hw(sizeof(struct rtl_pci_priv) + |
| 2184 | sizeof(struct rtl_priv), &rtl_ops); |
| 2185 | if (!hw) { |
| 2186 | RT_ASSERT(false, |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 2187 | "%s : ieee80211 alloc failed\n", pci_name(pdev)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2188 | err = -ENOMEM; |
| 2189 | goto fail1; |
| 2190 | } |
| 2191 | |
| 2192 | SET_IEEE80211_DEV(hw, &pdev->dev); |
| 2193 | pci_set_drvdata(pdev, hw); |
| 2194 | |
| 2195 | rtlpriv = hw->priv; |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2196 | rtlpriv->hw = hw; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2197 | pcipriv = (void *)rtlpriv->priv; |
| 2198 | pcipriv->dev.pdev = pdev; |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 2199 | init_completion(&rtlpriv->firmware_loading_complete); |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 2200 | /*proximity init here*/ |
| 2201 | rtlpriv->proximity.proxim_on = false; |
| 2202 | |
| 2203 | pcipriv = (void *)rtlpriv->priv; |
| 2204 | pcipriv->dev.pdev = pdev; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2205 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2206 | /* init cfg & intf_ops */ |
| 2207 | rtlpriv->rtlhal.interface = INTF_PCI; |
| 2208 | rtlpriv->cfg = (struct rtl_hal_cfg *)(id->driver_data); |
| 2209 | rtlpriv->intf_ops = &rtl_pci_ops; |
Larry Finger | 6f334c2 | 2013-07-12 15:32:15 -0500 | [diff] [blame] | 2210 | rtlpriv->glb_var = &rtl_global_var; |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2211 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2212 | /* |
| 2213 | *init dbgp flags before all |
| 2214 | *other functions, because we will |
| 2215 | *use it in other funtions like |
| 2216 | *RT_TRACE/RT_PRINT/RTL_PRINT_DATA |
| 2217 | *you can not use these macro |
| 2218 | *before this |
| 2219 | */ |
| 2220 | rtl_dbgp_flag_init(hw); |
| 2221 | |
| 2222 | /* MEM map */ |
| 2223 | err = pci_request_regions(pdev, KBUILD_MODNAME); |
| 2224 | if (err) { |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 2225 | RT_ASSERT(false, "Can't obtain PCI resources\n"); |
Tim Gardner | 3d86b93 | 2012-02-02 13:48:06 -0700 | [diff] [blame] | 2226 | goto fail1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2227 | } |
| 2228 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2229 | pmem_start = pci_resource_start(pdev, rtlpriv->cfg->bar_id); |
| 2230 | pmem_len = pci_resource_len(pdev, rtlpriv->cfg->bar_id); |
| 2231 | pmem_flags = pci_resource_flags(pdev, rtlpriv->cfg->bar_id); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2232 | |
| 2233 | /*shared mem start */ |
| 2234 | rtlpriv->io.pci_mem_start = |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2235 | (unsigned long)pci_iomap(pdev, |
| 2236 | rtlpriv->cfg->bar_id, pmem_len); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2237 | if (rtlpriv->io.pci_mem_start == 0) { |
Joe Perches | 9d833ed | 2012-01-04 19:40:43 -0800 | [diff] [blame] | 2238 | RT_ASSERT(false, "Can't map PCI mem\n"); |
Tim Gardner | 3d86b93 | 2012-02-02 13:48:06 -0700 | [diff] [blame] | 2239 | err = -ENOMEM; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2240 | goto fail2; |
| 2241 | } |
| 2242 | |
| 2243 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2244 | "mem mapped space: start: 0x%08lx len:%08lx flags:%08lx, after map:0x%08lx\n", |
| 2245 | pmem_start, pmem_len, pmem_flags, |
| 2246 | rtlpriv->io.pci_mem_start); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2247 | |
| 2248 | /* Disable Clk Request */ |
| 2249 | pci_write_config_byte(pdev, 0x81, 0); |
| 2250 | /* leave D3 mode */ |
| 2251 | pci_write_config_byte(pdev, 0x44, 0); |
| 2252 | pci_write_config_byte(pdev, 0x04, 0x06); |
| 2253 | pci_write_config_byte(pdev, 0x04, 0x07); |
| 2254 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2255 | /* find adapter */ |
Tim Gardner | 3d86b93 | 2012-02-02 13:48:06 -0700 | [diff] [blame] | 2256 | if (!_rtl_pci_find_adapter(pdev, hw)) { |
| 2257 | err = -ENODEV; |
Larry Finger | fa7ccfb | 2011-06-18 22:49:53 -0500 | [diff] [blame] | 2258 | goto fail3; |
Tim Gardner | 3d86b93 | 2012-02-02 13:48:06 -0700 | [diff] [blame] | 2259 | } |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2260 | |
| 2261 | /* Init IO handler */ |
| 2262 | _rtl_pci_io_handler_init(&pdev->dev, hw); |
| 2263 | |
| 2264 | /*like read eeprom and so on */ |
| 2265 | rtlpriv->cfg->ops->read_eeprom_info(hw); |
| 2266 | |
Larry Finger | 7d63a5f | 2014-11-25 10:32:07 -0600 | [diff] [blame] | 2267 | if (rtlpriv->cfg->ops->init_sw_vars(hw)) { |
| 2268 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Can't init_sw_vars\n"); |
| 2269 | err = -ENODEV; |
| 2270 | goto fail3; |
| 2271 | } |
| 2272 | rtlpriv->cfg->ops->init_sw_leds(hw); |
| 2273 | |
| 2274 | /*aspm */ |
| 2275 | rtl_pci_init_aspm(hw); |
| 2276 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2277 | /* Init mac80211 sw */ |
| 2278 | err = rtl_init_core(hw); |
| 2279 | if (err) { |
| 2280 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2281 | "Can't allocate sw for mac80211\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2282 | goto fail3; |
| 2283 | } |
| 2284 | |
| 2285 | /* Init PCI sw */ |
John W. Linville | 1232528 | 2012-02-09 14:48:25 -0500 | [diff] [blame] | 2286 | err = rtl_pci_init(hw, pdev); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2287 | if (err) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2288 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, "Failed to init PCI\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 | err = ieee80211_register_hw(hw); |
| 2293 | if (err) { |
| 2294 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
| 2295 | "Can't register mac80211 hw.\n"); |
Larry Finger | 574e02a | 2012-05-04 08:27:43 -0500 | [diff] [blame] | 2296 | err = -ENODEV; |
| 2297 | goto fail3; |
| 2298 | } |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 2299 | rtlpriv->mac80211.mac80211_registered = 1; |
Larry Finger | 574e02a | 2012-05-04 08:27:43 -0500 | [diff] [blame] | 2300 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2301 | err = sysfs_create_group(&pdev->dev.kobj, &rtl_attribute_group); |
| 2302 | if (err) { |
| 2303 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2304 | "failed to create sysfs device attributes\n"); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2305 | goto fail3; |
| 2306 | } |
| 2307 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 2308 | /*init rfkill */ |
| 2309 | rtl_init_rfkill(hw); /* Init PCI sw */ |
| 2310 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2311 | rtlpci = rtl_pcidev(pcipriv); |
Adam Lee | 94010fa | 2014-03-28 11:36:18 +0800 | [diff] [blame] | 2312 | err = rtl_pci_intr_mode_decide(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2313 | if (err) { |
| 2314 | RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 2315 | "%s: failed to register IRQ handler\n", |
| 2316 | wiphy_name(hw->wiphy)); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2317 | goto fail3; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2318 | } |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 2319 | rtlpci->irq_alloc = 1; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2320 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 2321 | set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2322 | return 0; |
| 2323 | |
| 2324 | fail3: |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 2325 | pci_set_drvdata(pdev, NULL); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2326 | rtl_deinit_core(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2327 | |
| 2328 | if (rtlpriv->io.pci_mem_start != 0) |
Larry Finger | 62e6397 | 2011-02-11 14:27:46 -0600 | [diff] [blame] | 2329 | pci_iounmap(pdev, (void __iomem *)rtlpriv->io.pci_mem_start); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2330 | |
| 2331 | fail2: |
| 2332 | pci_release_regions(pdev); |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 2333 | complete(&rtlpriv->firmware_loading_complete); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2334 | |
| 2335 | fail1: |
Tim Gardner | 3d86b93 | 2012-02-02 13:48:06 -0700 | [diff] [blame] | 2336 | if (hw) |
| 2337 | ieee80211_free_hw(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2338 | pci_disable_device(pdev); |
| 2339 | |
Tim Gardner | 3d86b93 | 2012-02-02 13:48:06 -0700 | [diff] [blame] | 2340 | return err; |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2341 | |
| 2342 | } |
| 2343 | EXPORT_SYMBOL(rtl_pci_probe); |
| 2344 | |
| 2345 | void rtl_pci_disconnect(struct pci_dev *pdev) |
| 2346 | { |
| 2347 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 2348 | struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw); |
| 2349 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2350 | struct rtl_pci *rtlpci = rtl_pcidev(pcipriv); |
| 2351 | struct rtl_mac *rtlmac = rtl_mac(rtlpriv); |
| 2352 | |
Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 2353 | /* just in case driver is removed before firmware callback */ |
| 2354 | wait_for_completion(&rtlpriv->firmware_loading_complete); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2355 | clear_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status); |
| 2356 | |
| 2357 | sysfs_remove_group(&pdev->dev.kobj, &rtl_attribute_group); |
| 2358 | |
| 2359 | /*ieee80211_unregister_hw will call ops_stop */ |
| 2360 | if (rtlmac->mac80211_registered == 1) { |
| 2361 | ieee80211_unregister_hw(hw); |
| 2362 | rtlmac->mac80211_registered = 0; |
| 2363 | } else { |
| 2364 | rtl_deinit_deferred_work(hw); |
| 2365 | rtlpriv->intf_ops->adapter_stop(hw); |
| 2366 | } |
Larry Finger | 44eb65cf | 2012-04-19 21:39:06 -0500 | [diff] [blame] | 2367 | rtlpriv->cfg->ops->disable_interrupt(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2368 | |
| 2369 | /*deinit rfkill */ |
| 2370 | rtl_deinit_rfkill(hw); |
| 2371 | |
| 2372 | rtl_pci_deinit(hw); |
| 2373 | rtl_deinit_core(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2374 | rtlpriv->cfg->ops->deinit_sw_vars(hw); |
| 2375 | |
| 2376 | if (rtlpci->irq_alloc) { |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2377 | synchronize_irq(rtlpci->pdev->irq); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2378 | free_irq(rtlpci->pdev->irq, hw); |
| 2379 | rtlpci->irq_alloc = 0; |
| 2380 | } |
| 2381 | |
Adam Lee | 94010fa | 2014-03-28 11:36:18 +0800 | [diff] [blame] | 2382 | if (rtlpci->using_msi) |
| 2383 | pci_disable_msi(rtlpci->pdev); |
| 2384 | |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2385 | list_del(&rtlpriv->list); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2386 | if (rtlpriv->io.pci_mem_start != 0) { |
Larry Finger | 62e6397 | 2011-02-11 14:27:46 -0600 | [diff] [blame] | 2387 | pci_iounmap(pdev, (void __iomem *)rtlpriv->io.pci_mem_start); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2388 | pci_release_regions(pdev); |
| 2389 | } |
| 2390 | |
| 2391 | pci_disable_device(pdev); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2392 | |
| 2393 | rtl_pci_disable_aspm(hw); |
| 2394 | |
Larry Finger | 38506ec | 2014-09-22 09:39:19 -0500 | [diff] [blame] | 2395 | pci_set_drvdata(pdev, NULL); |
| 2396 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2397 | ieee80211_free_hw(hw); |
| 2398 | } |
| 2399 | EXPORT_SYMBOL(rtl_pci_disconnect); |
| 2400 | |
Hauke Mehrtens | 244a77e | 2012-11-29 23:27:17 +0100 | [diff] [blame] | 2401 | #ifdef CONFIG_PM_SLEEP |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2402 | /*************************************** |
| 2403 | kernel pci power state define: |
| 2404 | PCI_D0 ((pci_power_t __force) 0) |
| 2405 | PCI_D1 ((pci_power_t __force) 1) |
| 2406 | PCI_D2 ((pci_power_t __force) 2) |
| 2407 | PCI_D3hot ((pci_power_t __force) 3) |
| 2408 | PCI_D3cold ((pci_power_t __force) 4) |
| 2409 | PCI_UNKNOWN ((pci_power_t __force) 5) |
| 2410 | |
| 2411 | This function is called when system |
| 2412 | goes into suspend state mac80211 will |
| 2413 | call rtl_mac_stop() from the mac80211 |
| 2414 | suspend function first, So there is |
| 2415 | no need to call hw_disable here. |
| 2416 | ****************************************/ |
Larry Finger | 603be38 | 2011-10-11 21:28:47 -0500 | [diff] [blame] | 2417 | int rtl_pci_suspend(struct device *dev) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2418 | { |
Larry Finger | 603be38 | 2011-10-11 21:28:47 -0500 | [diff] [blame] | 2419 | struct pci_dev *pdev = to_pci_dev(dev); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2420 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 2421 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 2422 | |
| 2423 | rtlpriv->cfg->ops->hw_suspend(hw); |
| 2424 | rtl_deinit_rfkill(hw); |
| 2425 | |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2426 | return 0; |
| 2427 | } |
| 2428 | EXPORT_SYMBOL(rtl_pci_suspend); |
| 2429 | |
Larry Finger | 603be38 | 2011-10-11 21:28:47 -0500 | [diff] [blame] | 2430 | int rtl_pci_resume(struct device *dev) |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2431 | { |
Larry Finger | 603be38 | 2011-10-11 21:28:47 -0500 | [diff] [blame] | 2432 | struct pci_dev *pdev = to_pci_dev(dev); |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2433 | struct ieee80211_hw *hw = pci_get_drvdata(pdev); |
| 2434 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2435 | |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2436 | rtlpriv->cfg->ops->hw_resume(hw); |
| 2437 | rtl_init_rfkill(hw); |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2438 | return 0; |
| 2439 | } |
| 2440 | EXPORT_SYMBOL(rtl_pci_resume); |
Hauke Mehrtens | 244a77e | 2012-11-29 23:27:17 +0100 | [diff] [blame] | 2441 | #endif /* CONFIG_PM_SLEEP */ |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2442 | |
| 2443 | struct rtl_intf_ops rtl_pci_ops = { |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2444 | .read_efuse_byte = read_efuse_byte, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2445 | .adapter_start = rtl_pci_start, |
| 2446 | .adapter_stop = rtl_pci_stop, |
Larry Finger | 26634c4 | 2013-03-24 22:06:33 -0500 | [diff] [blame] | 2447 | .check_buddy_priv = rtl_pci_check_buddy_priv, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2448 | .adapter_tx = rtl_pci_tx, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2449 | .flush = rtl_pci_flush, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2450 | .reset_trx_ring = rtl_pci_reset_trx_ring, |
Chaoming_Li | c7cfe38 | 2011-04-25 13:23:15 -0500 | [diff] [blame] | 2451 | .waitq_insert = rtl_pci_tx_chk_waitq_insert, |
Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 2452 | |
| 2453 | .disable_aspm = rtl_pci_disable_aspm, |
| 2454 | .enable_aspm = rtl_pci_enable_aspm, |
| 2455 | }; |