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