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