pci.c 66.8 KB
Newer Older
L
Larry Finger 已提交
1 2
/******************************************************************************
 *
L
Larry Finger 已提交
3
 * Copyright(c) 2009-2012  Realtek Corporation.
L
Larry Finger 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * The full GNU General Public License is included in this distribution in the
 * file called LICENSE.
 *
 * Contact Information:
 * wlanfae <wlanfae@realtek.com>
 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
 * Hsinchu 300, Taiwan.
 *
 * Larry Finger <Larry.Finger@lwfinger.net>
 *
 *****************************************************************************/

#include "wifi.h"
27
#include "core.h"
L
Larry Finger 已提交
28 29 30
#include "pci.h"
#include "base.h"
#include "ps.h"
31
#include "efuse.h"
32
#include <linux/interrupt.h>
33
#include <linux/export.h>
34
#include <linux/kmemleak.h>
35 36 37 38 39 40 41
#include <linux/module.h>

MODULE_AUTHOR("lizhaoming	<chaoming_li@realsil.com.cn>");
MODULE_AUTHOR("Realtek WlanFAE	<wlanfae@realtek.com>");
MODULE_AUTHOR("Larry Finger	<Larry.FInger@lwfinger.net>");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("PCI basic driver for rtlwifi");
L
Larry Finger 已提交
42 43

static const u16 pcibridge_vendors[PCI_BRIDGE_VENDOR_MAX] = {
44 45 46 47
	INTEL_VENDOR_ID,
	ATI_VENDOR_ID,
	AMD_VENDOR_ID,
	SIS_VENDOR_ID
L
Larry Finger 已提交
48 49
};

50 51 52 53 54 55 56
static const u8 ac_to_hwq[] = {
	VO_QUEUE,
	VI_QUEUE,
	BE_QUEUE,
	BK_QUEUE
};

57
static u8 _rtl_mac_to_hwqueue(struct ieee80211_hw *hw, struct sk_buff *skb)
58 59
{
	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
60
	__le16 fc = rtl_get_fc(skb);
61 62 63 64
	u8 queue_index = skb_get_queue_mapping(skb);

	if (unlikely(ieee80211_is_beacon(fc)))
		return BEACON_QUEUE;
65
	if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc))
66 67 68 69 70 71 72 73
		return MGNT_QUEUE;
	if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE)
		if (ieee80211_is_nullfunc(fc))
			return HIGH_QUEUE;

	return ac_to_hwq[queue_index];
}

L
Larry Finger 已提交
74 75 76 77 78 79 80 81
/* Update PCI dependent default settings*/
static void _rtl_pci_update_default_setting(struct ieee80211_hw *hw)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor;
82
	u8 init_aspm;
L
Larry Finger 已提交
83 84

	ppsc->reg_rfps_level = 0;
85
	ppsc->support_aspm = false;
L
Larry Finger 已提交
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105

	/*Update PCI ASPM setting */
	ppsc->const_amdpci_aspm = rtlpci->const_amdpci_aspm;
	switch (rtlpci->const_pci_aspm) {
	case 0:
		/*No ASPM */
		break;

	case 1:
		/*ASPM dynamically enabled/disable. */
		ppsc->reg_rfps_level |= RT_RF_LPS_LEVEL_ASPM;
		break;

	case 2:
		/*ASPM with Clock Req dynamically enabled/disable. */
		ppsc->reg_rfps_level |= (RT_RF_LPS_LEVEL_ASPM |
					 RT_RF_OFF_LEVL_CLK_REQ);
		break;

	case 3:
106
		/* Always enable ASPM and Clock Req
L
Larry Finger 已提交
107
		 * from initialization to halt.
108
		 */
L
Larry Finger 已提交
109 110 111 112 113 114
		ppsc->reg_rfps_level &= ~(RT_RF_LPS_LEVEL_ASPM);
		ppsc->reg_rfps_level |= (RT_RF_PS_LEVEL_ALWAYS_ASPM |
					 RT_RF_OFF_LEVL_CLK_REQ);
		break;

	case 4:
115
		/* Always enable ASPM without Clock Req
L
Larry Finger 已提交
116
		 * from initialization to halt.
117
		 */
L
Larry Finger 已提交
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
		ppsc->reg_rfps_level &= ~(RT_RF_LPS_LEVEL_ASPM |
					  RT_RF_OFF_LEVL_CLK_REQ);
		ppsc->reg_rfps_level |= RT_RF_PS_LEVEL_ALWAYS_ASPM;
		break;
	}

	ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_HALT_NIC;

	/*Update Radio OFF setting */
	switch (rtlpci->const_hwsw_rfoff_d3) {
	case 1:
		if (ppsc->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM)
			ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_ASPM;
		break;

	case 2:
		if (ppsc->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM)
			ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_ASPM;
		ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_HALT_NIC;
		break;

	case 3:
		ppsc->reg_rfps_level |= RT_RF_OFF_LEVL_PCI_D3;
		break;
	}

	/*Set HW definition to determine if it supports ASPM. */
	switch (rtlpci->const_support_pciaspm) {
146 147 148 149 150 151 152 153 154
	case 0:
		/*Not support ASPM. */
		ppsc->support_aspm = false;
		break;
	case 1:
		/*Support ASPM. */
		ppsc->support_aspm = true;
		ppsc->support_backdoor = true;
		break;
L
Larry Finger 已提交
155 156
	case 2:
		/*ASPM value set by chipset. */
157 158
		if (pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL)
			ppsc->support_aspm = true;
L
Larry Finger 已提交
159 160
		break;
	default:
161 162
		pr_err("switch case %#x not processed\n",
		       rtlpci->const_support_pciaspm);
L
Larry Finger 已提交
163 164
		break;
	}
165 166

	/* toshiba aspm issue, toshiba will set aspm selfly
167 168
	 * so we should not set aspm in driver
	 */
169 170
	pci_read_config_byte(rtlpci->pdev, 0x80, &init_aspm);
	if (rtlpriv->rtlhal.hw_type == HARDWARE_TYPE_RTL8192SE &&
171
	    init_aspm == 0x43)
172 173 174
		ppsc->support_aspm = false;
}

L
Larry Finger 已提交
175 176 177 178 179
static bool _rtl_pci_platform_switch_device_pci_aspm(
			struct ieee80211_hw *hw,
			u8 value)
{
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
180 181 182 183
	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));

	if (rtlhal->hw_type != HARDWARE_TYPE_RTL8192SE)
		value |= 0x40;
L
Larry Finger 已提交
184 185 186

	pci_write_config_byte(rtlpci->pdev, 0x80, value);

187
	return false;
L
Larry Finger 已提交
188 189 190
}

/*When we set 0x01 to enable clk request. Set 0x0 to disable clk req.*/
191
static void _rtl_pci_switch_clk_req(struct ieee80211_hw *hw, u8 value)
L
Larry Finger 已提交
192 193
{
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
194
	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
L
Larry Finger 已提交
195 196 197

	pci_write_config_byte(rtlpci->pdev, 0x81, value);

198 199
	if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE)
		udelay(100);
L
Larry Finger 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
}

/*Disable RTL8192SE ASPM & Disable Pci Bridge ASPM*/
static void rtl_pci_disable_aspm(struct ieee80211_hw *hw)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor;
	u8 num4bytes = pcipriv->ndis_adapter.num4bytes;
	/*Retrieve original configuration settings. */
	u8 linkctrl_reg = pcipriv->ndis_adapter.linkctrl_reg;
	u16 pcibridge_linkctrlreg = pcipriv->ndis_adapter.
				pcibridge_linkctrlreg;
	u16 aspmlevel = 0;
216
	u8 tmp_u1b = 0;
L
Larry Finger 已提交
217

218 219 220
	if (!ppsc->support_aspm)
		return;

L
Larry Finger 已提交
221 222
	if (pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) {
		RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
223
			 "PCI(Bridge) UNKNOWN\n");
L
Larry Finger 已提交
224 225 226 227 228 229 230 231 232

		return;
	}

	if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) {
		RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_CLK_REQ);
		_rtl_pci_switch_clk_req(hw, 0x0);
	}

233 234
	/*for promising device will in L0 state after an I/O. */
	pci_read_config_byte(rtlpci->pdev, 0x80, &tmp_u1b);
L
Larry Finger 已提交
235 236 237 238 239 240 241 242 243 244

	/*Set corresponding value. */
	aspmlevel |= BIT(0) | BIT(1);
	linkctrl_reg &= ~aspmlevel;
	pcibridge_linkctrlreg &= ~(BIT(0) | BIT(1));

	_rtl_pci_platform_switch_device_pci_aspm(hw, linkctrl_reg);
	udelay(50);

	/*4 Disable Pci Bridge ASPM */
245 246
	pci_write_config_byte(rtlpci->pdev, (num4bytes << 2),
			      pcibridge_linkctrlreg);
L
Larry Finger 已提交
247 248 249 250

	udelay(50);
}

251
/*Enable RTL8192SE ASPM & Enable Pci Bridge ASPM for
L
Larry Finger 已提交
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
 *power saving We should follow the sequence to enable
 *RTL8192SE first then enable Pci Bridge ASPM
 *or the system will show bluescreen.
 */
static void rtl_pci_enable_aspm(struct ieee80211_hw *hw)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	u8 pcibridge_vendor = pcipriv->ndis_adapter.pcibridge_vendor;
	u8 num4bytes = pcipriv->ndis_adapter.num4bytes;
	u16 aspmlevel;
	u8 u_pcibridge_aspmsetting;
	u8 u_device_aspmsetting;

268 269 270
	if (!ppsc->support_aspm)
		return;

L
Larry Finger 已提交
271 272
	if (pcibridge_vendor == PCI_BRIDGE_VENDOR_UNKNOWN) {
		RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE,
273
			 "PCI(Bridge) UNKNOWN\n");
L
Larry Finger 已提交
274 275 276 277 278 279 280 281 282 283 284 285
		return;
	}

	/*4 Enable Pci Bridge ASPM */

	u_pcibridge_aspmsetting =
	    pcipriv->ndis_adapter.pcibridge_linkctrlreg |
	    rtlpci->const_hostpci_aspm_setting;

	if (pcibridge_vendor == PCI_BRIDGE_VENDOR_INTEL)
		u_pcibridge_aspmsetting &= ~BIT(0);

286 287
	pci_write_config_byte(rtlpci->pdev, (num4bytes << 2),
			      u_pcibridge_aspmsetting);
L
Larry Finger 已提交
288 289

	RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
290
		 "PlatformEnableASPM(): Write reg[%x] = %x\n",
291 292
		 (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10),
		 u_pcibridge_aspmsetting);
L
Larry Finger 已提交
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311

	udelay(50);

	/*Get ASPM level (with/without Clock Req) */
	aspmlevel = rtlpci->const_devicepci_aspm_setting;
	u_device_aspmsetting = pcipriv->ndis_adapter.linkctrl_reg;

	/*_rtl_pci_platform_switch_device_pci_aspm(dev,*/
	/*(priv->ndis_adapter.linkctrl_reg | ASPMLevel)); */

	u_device_aspmsetting |= aspmlevel;

	_rtl_pci_platform_switch_device_pci_aspm(hw, u_device_aspmsetting);

	if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_CLK_REQ) {
		_rtl_pci_switch_clk_req(hw, (ppsc->reg_rfps_level &
					     RT_RF_OFF_LEVL_CLK_REQ) ? 1 : 0);
		RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_CLK_REQ);
	}
312
	udelay(100);
L
Larry Finger 已提交
313 314 315 316
}

static bool rtl_pci_get_amd_l1_patch(struct ieee80211_hw *hw)
{
317
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
L
Larry Finger 已提交
318 319 320

	bool status = false;
	u8 offset_e0;
321
	unsigned int offset_e4;
L
Larry Finger 已提交
322

323
	pci_write_config_byte(rtlpci->pdev, 0xe0, 0xa0);
L
Larry Finger 已提交
324

325
	pci_read_config_byte(rtlpci->pdev, 0xe0, &offset_e0);
L
Larry Finger 已提交
326 327

	if (offset_e0 == 0xA0) {
328
		pci_read_config_dword(rtlpci->pdev, 0xe4, &offset_e4);
L
Larry Finger 已提交
329 330 331 332 333 334 335
		if (offset_e4 & BIT(23))
			status = true;
	}

	return status;
}

336 337 338 339 340 341
static bool rtl_pci_check_buddy_priv(struct ieee80211_hw *hw,
				     struct rtl_priv **buddy_priv)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
	bool find_buddy_priv = false;
L
Larry Finger 已提交
342
	struct rtl_priv *tpriv;
343 344 345 346 347
	struct rtl_pci_priv *tpcipriv = NULL;

	if (!list_empty(&rtlpriv->glb_var->glb_priv_list)) {
		list_for_each_entry(tpriv, &rtlpriv->glb_var->glb_priv_list,
				    list) {
L
Larry Finger 已提交
348 349 350 351 352 353 354 355
			tpcipriv = (struct rtl_pci_priv *)tpriv->priv;
			RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
				 "pcipriv->ndis_adapter.funcnumber %x\n",
				pcipriv->ndis_adapter.funcnumber);
			RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
				 "tpcipriv->ndis_adapter.funcnumber %x\n",
				tpcipriv->ndis_adapter.funcnumber);

356 357 358 359 360 361
			if (pcipriv->ndis_adapter.busnumber ==
			    tpcipriv->ndis_adapter.busnumber &&
			    pcipriv->ndis_adapter.devnumber ==
			    tpcipriv->ndis_adapter.devnumber &&
			    pcipriv->ndis_adapter.funcnumber !=
			    tpcipriv->ndis_adapter.funcnumber) {
L
Larry Finger 已提交
362 363
				find_buddy_priv = true;
				break;
364 365 366 367 368 369 370 371 372 373 374 375 376
			}
		}
	}

	RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
		 "find_buddy_priv %d\n", find_buddy_priv);

	if (find_buddy_priv)
		*buddy_priv = tpriv;

	return find_buddy_priv;
}

377
static void rtl_pci_get_linkcontrol_field(struct ieee80211_hw *hw)
L
Larry Finger 已提交
378 379
{
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
380
	struct rtl_pci *rtlpci = rtl_pcidev(pcipriv);
L
Larry Finger 已提交
381 382
	u8 capabilityoffset = pcipriv->ndis_adapter.pcibridge_pciehdr_offset;
	u8 linkctrl_reg;
383
	u8 num4bbytes;
L
Larry Finger 已提交
384

385
	num4bbytes = (capabilityoffset + 0x10) / 4;
L
Larry Finger 已提交
386 387

	/*Read  Link Control Register */
388
	pci_read_config_byte(rtlpci->pdev, (num4bbytes << 2), &linkctrl_reg);
L
Larry Finger 已提交
389 390 391 392 393

	pcipriv->ndis_adapter.pcibridge_linkctrlreg = linkctrl_reg;
}

static void rtl_pci_parse_configuration(struct pci_dev *pdev,
394
					struct ieee80211_hw *hw)
L
Larry Finger 已提交
395 396 397 398 399
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);

	u8 tmp;
400
	u16 linkctrl_reg;
L
Larry Finger 已提交
401 402

	/*Link Control Register */
403 404
	pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &linkctrl_reg);
	pcipriv->ndis_adapter.linkctrl_reg = (u8)linkctrl_reg;
L
Larry Finger 已提交
405

406 407
	RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "Link Control Register =%x\n",
		 pcipriv->ndis_adapter.linkctrl_reg);
L
Larry Finger 已提交
408 409 410 411 412 413 414 415 416

	pci_read_config_byte(pdev, 0x98, &tmp);
	tmp |= BIT(4);
	pci_write_config_byte(pdev, 0x98, tmp);

	tmp = 0x17;
	pci_write_config_byte(pdev, 0x70f, tmp);
}

417
static void rtl_pci_init_aspm(struct ieee80211_hw *hw)
L
Larry Finger 已提交
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
{
	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));

	_rtl_pci_update_default_setting(hw);

	if (ppsc->reg_rfps_level & RT_RF_PS_LEVEL_ALWAYS_ASPM) {
		/*Always enable ASPM & Clock Req. */
		rtl_pci_enable_aspm(hw);
		RT_SET_PS_LEVEL(ppsc, RT_RF_PS_LEVEL_ALWAYS_ASPM);
	}
}

static void _rtl_pci_io_handler_init(struct device *dev,
				     struct ieee80211_hw *hw)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);

	rtlpriv->io.dev = dev;

	rtlpriv->io.write8_async = pci_write8_async;
	rtlpriv->io.write16_async = pci_write16_async;
	rtlpriv->io.write32_async = pci_write32_async;

	rtlpriv->io.read8_sync = pci_read8_sync;
	rtlpriv->io.read16_sync = pci_read16_sync;
	rtlpriv->io.read32_sync = pci_read32_sync;
}

446
static bool _rtl_update_earlymode_info(struct ieee80211_hw *hw,
447 448
				       struct sk_buff *skb,
				       struct rtl_tcb_desc *tcb_desc, u8 tid)
449 450 451
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
452
	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
453
	struct sk_buff *next_skb;
454
	u8 additionlen = FCS_LEN;
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478

	/* here open is 4, wep/tkip is 8, aes is 12*/
	if (info->control.hw_key)
		additionlen += info->control.hw_key->icv_len;

	/* The most skb num is 6 */
	tcb_desc->empkt_num = 0;
	spin_lock_bh(&rtlpriv->locks.waitq_lock);
	skb_queue_walk(&rtlpriv->mac80211.skb_waitq[tid], next_skb) {
		struct ieee80211_tx_info *next_info;

		next_info = IEEE80211_SKB_CB(next_skb);
		if (next_info->flags & IEEE80211_TX_CTL_AMPDU) {
			tcb_desc->empkt_len[tcb_desc->empkt_num] =
				next_skb->len + additionlen;
			tcb_desc->empkt_num++;
		} else {
			break;
		}

		if (skb_queue_is_last(&rtlpriv->mac80211.skb_waitq[tid],
				      next_skb))
			break;

479
		if (tcb_desc->empkt_num >= rtlhal->max_earlymode_num)
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494
			break;
	}
	spin_unlock_bh(&rtlpriv->locks.waitq_lock);

	return true;
}

/* just for early mode now */
static void _rtl_pci_tx_chk_waitq(struct ieee80211_hw *hw)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	struct sk_buff *skb = NULL;
	struct ieee80211_tx_info *info = NULL;
495
	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
496
	int tid;
497 498 499 500

	if (!rtlpriv->rtlhal.earlymode_enable)
		return;

501 502 503 504 505
	if (rtlpriv->dm.supp_phymode_switch &&
	    (rtlpriv->easy_concurrent_ctl.switch_in_process ||
	    (rtlpriv->buddy_priv &&
	    rtlpriv->buddy_priv->easy_concurrent_ctl.switch_in_process)))
		return;
506
	/* we just use em for BE/BK/VI/VO */
507
	for (tid = 7; tid >= 0; tid--) {
508
		u8 hw_queue = ac_to_hwq[rtl_tid_to_ac(tid)];
509
		struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[hw_queue];
510

511 512 513
		while (!mac->act_scanning &&
		       rtlpriv->psc.rfpwr_state == ERFON) {
			struct rtl_tcb_desc tcb_desc;
514

515 516 517 518
			memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));

			spin_lock_bh(&rtlpriv->locks.waitq_lock);
			if (!skb_queue_empty(&mac->skb_waitq[tid]) &&
519 520
			    (ring->entries - skb_queue_len(&ring->queue) >
			     rtlhal->max_earlymode_num)) {
521 522 523 524 525 526 527 528
				skb = skb_dequeue(&mac->skb_waitq[tid]);
			} else {
				spin_unlock_bh(&rtlpriv->locks.waitq_lock);
				break;
			}
			spin_unlock_bh(&rtlpriv->locks.waitq_lock);

			/* Some macaddr can't do early mode. like
529 530
			 * multicast/broadcast/no_qos data
			 */
531 532 533 534 535
			info = IEEE80211_SKB_CB(skb);
			if (info->flags & IEEE80211_TX_CTL_AMPDU)
				_rtl_update_earlymode_info(hw, skb,
							   &tcb_desc, tid);

536
			rtlpriv->intf_ops->adapter_tx(hw, NULL, skb, &tcb_desc);
537 538 539 540
		}
	}
}

L
Larry Finger 已提交
541 542 543 544 545 546 547 548 549 550
static void _rtl_pci_tx_isr(struct ieee80211_hw *hw, int prio)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));

	struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[prio];

	while (skb_queue_len(&ring->queue)) {
		struct sk_buff *skb;
		struct ieee80211_tx_info *info;
551 552
		__le16 fc;
		u8 tid;
553
		u8 *entry;
L
Larry Finger 已提交
554

555 556 557 558
		if (rtlpriv->use_new_trx_flow)
			entry = (u8 *)(&ring->buffer_desc[ring->idx]);
		else
			entry = (u8 *)(&ring->desc[ring->idx]);
L
Larry Finger 已提交
559

560 561 562 563 564 565 566
		if (rtlpriv->cfg->ops->get_available_desc &&
		    rtlpriv->cfg->ops->get_available_desc(hw, prio) <= 1) {
			RT_TRACE(rtlpriv, (COMP_INTR | COMP_SEND), DBG_DMESG,
				 "no available desc!\n");
			return;
		}

567
		if (!rtlpriv->cfg->ops->is_tx_desc_closed(hw, prio, ring->idx))
L
Larry Finger 已提交
568 569 570 571 572
			return;
		ring->idx = (ring->idx + 1) % ring->entries;

		skb = __skb_dequeue(&ring->queue);
		pci_unmap_single(rtlpci->pdev,
573
				 rtlpriv->cfg->ops->
574
					     get_desc(hw, (u8 *)entry, true,
575
						      HW_DESC_TXBUFF_ADDR),
L
Larry Finger 已提交
576 577
				 skb->len, PCI_DMA_TODEVICE);

578 579 580 581
		/* remove early mode header */
		if (rtlpriv->rtlhal.earlymode_enable)
			skb_pull(skb, EM_HDR_LEN);

L
Larry Finger 已提交
582
		RT_TRACE(rtlpriv, (COMP_INTR | COMP_SEND), DBG_TRACE,
583 584 585
			 "new ring->idx:%d, free: skb_queue_len:%d, free: seq:%x\n",
			 ring->idx,
			 skb_queue_len(&ring->queue),
586
			 *(u16 *)(skb->data + 22));
L
Larry Finger 已提交
587

588 589 590 591 592 593
		if (prio == TXCMD_QUEUE) {
			dev_kfree_skb(skb);
			goto tx_status_ok;
		}

		/* for sw LPS, just after NULL skb send out, we can
594 595 596
		 * sure AP knows we are sleeping, we should not let
		 * rf sleep
		 */
597 598 599
		fc = rtl_get_fc(skb);
		if (ieee80211_is_nullfunc(fc)) {
			if (ieee80211_has_pm(fc)) {
600
				rtlpriv->mac80211.offchan_delay = true;
601
				rtlpriv->psc.state_inap = true;
602
			} else {
603
				rtlpriv->psc.state_inap = false;
604 605
			}
		}
606 607 608 609 610 611 612 613 614
		if (ieee80211_is_action(fc)) {
			struct ieee80211_mgmt *action_frame =
				(struct ieee80211_mgmt *)skb->data;
			if (action_frame->u.action.u.ht_smps.action ==
			    WLAN_HT_ACTION_SMPS) {
				dev_kfree_skb(skb);
				goto tx_status_ok;
			}
		}
615 616 617 618 619 620

		/* update tid tx pkt num */
		tid = rtl_get_tid(skb);
		if (tid <= 7)
			rtlpriv->link_info.tidtx_inperiod[tid]++;

L
Larry Finger 已提交
621 622 623 624 625 626 627 628
		info = IEEE80211_SKB_CB(skb);
		ieee80211_tx_info_clear_status(info);

		info->flags |= IEEE80211_TX_STAT_ACK;
		/*info->status.rates[0].count = 1; */

		ieee80211_tx_status_irqsafe(hw, skb);

629 630
		if ((ring->entries - skb_queue_len(&ring->queue)) <= 4) {
			RT_TRACE(rtlpriv, COMP_ERR, DBG_DMESG,
631
				 "more desc left, wake skb_queue@%d, ring->idx = %d, skb_queue_len = 0x%x\n",
632 633
				 prio, ring->idx,
				 skb_queue_len(&ring->queue));
L
Larry Finger 已提交
634

635
			ieee80211_wake_queue(hw, skb_get_queue_mapping(skb));
L
Larry Finger 已提交
636
		}
637
tx_status_ok:
L
Larry Finger 已提交
638 639 640 641
		skb = NULL;
	}

	if (((rtlpriv->link_info.num_rx_inperiod +
L
Larry Finger 已提交
642
	      rtlpriv->link_info.num_tx_inperiod) > 8) ||
643
	      rtlpriv->link_info.num_rx_inperiod > 2)
L
Larry Finger 已提交
644
		rtl_lps_leave(hw);
L
Larry Finger 已提交
645 646
}

647
static int _rtl_pci_init_one_rxdesc(struct ieee80211_hw *hw,
648 649
				    struct sk_buff *new_skb, u8 *entry,
				    int rxring_idx, int desc_idx)
650 651
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
652 653 654 655 656
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	u32 bufferaddress;
	u8 tmp_one = 1;
	struct sk_buff *skb;

657 658 659 660
	if (likely(new_skb)) {
		skb = new_skb;
		goto remap;
	}
661 662 663 664
	skb = dev_alloc_skb(rtlpci->rxbuffersize);
	if (!skb)
		return 0;

665
remap:
666 667 668 669 670 671 672
	/* just set skb->cb to mapping addr for pci_unmap_single use */
	*((dma_addr_t *)skb->cb) =
		pci_map_single(rtlpci->pdev, skb_tail_pointer(skb),
			       rtlpci->rxbuffersize, PCI_DMA_FROMDEVICE);
	bufferaddress = *((dma_addr_t *)skb->cb);
	if (pci_dma_mapping_error(rtlpci->pdev, bufferaddress))
		return 0;
673
	rtlpci->rx_ring[rxring_idx].rx_buf[desc_idx] = skb;
674
	if (rtlpriv->use_new_trx_flow) {
675
		/* skb->cb may be 64 bit address */
676 677
		rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false,
					    HW_DESC_RX_PREPARE,
678
					    (u8 *)(dma_addr_t *)skb->cb);
679
	} else {
680 681 682 683 684 685 686 687 688
		rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false,
					    HW_DESC_RXBUFF_ADDR,
					    (u8 *)&bufferaddress);
		rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false,
					    HW_DESC_RXPKT_LEN,
					    (u8 *)&rtlpci->rxbuffersize);
		rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false,
					    HW_DESC_RXOWN,
					    (u8 *)&tmp_one);
689
	}
690 691
	return 1;
}
692

693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
/* inorder to receive 8K AMSDU we have set skb to
 * 9100bytes in init rx ring, but if this packet is
 * not a AMSDU, this large packet will be sent to
 * TCP/IP directly, this cause big packet ping fail
 * like: "ping -s 65507", so here we will realloc skb
 * based on the true size of packet, Mac80211
 * Probably will do it better, but does not yet.
 *
 * Some platform will fail when alloc skb sometimes.
 * in this condition, we will send the old skb to
 * mac80211 directly, this will not cause any other
 * issues, but only this packet will be lost by TCP/IP
 */
static void _rtl_pci_rx_to_mac80211(struct ieee80211_hw *hw,
				    struct sk_buff *skb,
				    struct ieee80211_rx_status rx_status)
{
	if (unlikely(!rtl_action_proc(hw, skb, false))) {
		dev_kfree_skb_any(skb);
	} else {
		struct sk_buff *uskb = NULL;

		uskb = dev_alloc_skb(skb->len + 128);
		if (likely(uskb)) {
			memcpy(IEEE80211_SKB_RXCB(uskb), &rx_status,
			       sizeof(rx_status));
719
			skb_put_data(uskb, skb->data, skb->len);
720 721 722 723 724
			dev_kfree_skb_any(skb);
			ieee80211_rx_irqsafe(hw, uskb);
		} else {
			ieee80211_rx_irqsafe(hw, skb);
		}
725
	}
726
}
727

728 729 730 731 732
/*hsisr interrupt handler*/
static void _rtl_pci_hs_interrupt(struct ieee80211_hw *hw)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
733

734 735 736
	rtl_write_byte(rtlpriv, rtlpriv->cfg->maps[MAC_HSISR],
		       rtl_read_byte(rtlpriv, rtlpriv->cfg->maps[MAC_HSISR]) |
		       rtlpci->sys_irq_mask);
737 738
}

L
Larry Finger 已提交
739 740 741 742
static void _rtl_pci_rx_interrupt(struct ieee80211_hw *hw)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
743
	int rxring_idx = RTL_PCI_RX_MPDU_QUEUE;
L
Larry Finger 已提交
744 745 746 747
	struct ieee80211_rx_status rx_status = { 0 };
	unsigned int count = rtlpci->rxringcount;
	u8 own;
	u8 tmp_one;
748 749 750
	bool unicast = false;
	u8 hw_queue = 0;
	unsigned int rx_remained_cnt;
L
Larry Finger 已提交
751 752 753 754 755 756 757
	struct rtl_stats stats = {
		.signal = 0,
		.rate = 0,
	};

	/*RX NORMAL PKT */
	while (count--) {
758 759 760 761 762 763 764
		struct ieee80211_hdr *hdr;
		__le16 fc;
		u16 len;
		/*rx buffer descriptor */
		struct rtl_rx_buffer_desc *buffer_desc = NULL;
		/*if use new trx flow, it means wifi info */
		struct rtl_rx_desc *pdesc = NULL;
L
Larry Finger 已提交
765
		/*rx pkt */
766 767
		struct sk_buff *skb = rtlpci->rx_ring[rxring_idx].rx_buf[
				      rtlpci->rx_ring[rxring_idx].idx];
768
		struct sk_buff *new_skb;
769 770 771 772 773

		if (rtlpriv->use_new_trx_flow) {
			rx_remained_cnt =
				rtlpriv->cfg->ops->rx_desc_buff_remained_cnt(hw,
								      hw_queue);
774
			if (rx_remained_cnt == 0)
775
				return;
L
Larry Finger 已提交
776 777 778
			buffer_desc = &rtlpci->rx_ring[rxring_idx].buffer_desc[
				rtlpci->rx_ring[rxring_idx].idx];
			pdesc = (struct rtl_rx_desc *)skb->data;
779 780 781 782
		} else {	/* rx descriptor */
			pdesc = &rtlpci->rx_ring[rxring_idx].desc[
				rtlpci->rx_ring[rxring_idx].idx];

783
			own = (u8)rtlpriv->cfg->ops->get_desc(hw, (u8 *)pdesc,
784 785 786 787 788
							      false,
							      HW_DESC_OWN);
			if (own) /* wait data to be filled by hardware */
				return;
		}
789

790 791 792 793 794 795 796
		/* Reaching this point means: data is filled already
		 * AAAAAAttention !!!
		 * We can NOT access 'skb' before 'pci_unmap_single'
		 */
		pci_unmap_single(rtlpci->pdev, *((dma_addr_t *)skb->cb),
				 rtlpci->rxbuffersize, PCI_DMA_FROMDEVICE);

797 798
		/* get a new skb - if fail, old one will be reused */
		new_skb = dev_alloc_skb(rtlpci->rxbuffersize);
799
		if (unlikely(!new_skb))
800
			goto no_new;
801
		memset(&rx_status, 0, sizeof(rx_status));
802
		rtlpriv->cfg->ops->query_rx_desc(hw, &stats,
803
						 &rx_status, (u8 *)pdesc, skb);
804

805 806 807 808
		if (rtlpriv->use_new_trx_flow)
			rtlpriv->cfg->ops->rx_check_dma_ok(hw,
							   (u8 *)buffer_desc,
							   hw_queue);
809

810
		len = rtlpriv->cfg->ops->get_desc(hw, (u8 *)pdesc, false,
811
						  HW_DESC_RXPKT_LEN);
812

813 814 815 816 817 818 819 820 821 822 823 824
		if (skb->end - skb->tail > len) {
			skb_put(skb, len);
			if (rtlpriv->use_new_trx_flow)
				skb_reserve(skb, stats.rx_drvinfo_size +
					    stats.rx_bufshift + 24);
			else
				skb_reserve(skb, stats.rx_drvinfo_size +
					    stats.rx_bufshift);
		} else {
			RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
				 "skb->end - skb->tail = %d, len is %d\n",
				 skb->end - skb->tail, len);
825 826
			dev_kfree_skb_any(skb);
			goto new_trx_end;
827 828
		}
		/* handle command packet here */
829
		if (rtlpriv->cfg->ops->rx_command_packet &&
830
		    rtlpriv->cfg->ops->rx_command_packet(hw, &stats, skb)) {
831 832
			dev_kfree_skb_any(skb);
			goto new_trx_end;
833
		}
834

835
		/* NOTICE This can not be use for mac80211,
836
		 * this is done in mac80211 code,
837
		 * if done here sec DHCP will fail
838 839 840
		 * skb_trim(skb, skb->len - 4);
		 */

841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
		hdr = rtl_get_hdr(skb);
		fc = rtl_get_fc(skb);

		if (!stats.crc && !stats.hwerror) {
			memcpy(IEEE80211_SKB_RXCB(skb), &rx_status,
			       sizeof(rx_status));

			if (is_broadcast_ether_addr(hdr->addr1)) {
				;/*TODO*/
			} else if (is_multicast_ether_addr(hdr->addr1)) {
				;/*TODO*/
			} else {
				unicast = true;
				rtlpriv->stats.rxbytesunicast += skb->len;
			}
856
			rtl_is_special_data(hw, skb, false, true);
L
Larry Finger 已提交
857

858 859 860 861 862
			if (ieee80211_is_data(fc)) {
				rtlpriv->cfg->ops->led_control(hw, LED_CTL_RX);
				if (unicast)
					rtlpriv->link_info.num_rx_inperiod++;
			}
863 864 865

			rtl_collect_scan_list(hw, skb);

866 867 868 869 870 871
			/* static bcn for roaming */
			rtl_beacon_statistic(hw, skb);
			rtl_p2p_info(hw, (void *)skb->data, skb->len);
			/* for sw lps */
			rtl_swlps_beacon(hw, (void *)skb->data, skb->len);
			rtl_recognize_peer(hw, (void *)skb->data, skb->len);
872 873
			if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_AP &&
			    rtlpriv->rtlhal.current_bandtype == BAND_ON_2_4G &&
874 875 876 877 878 879 880 881 882
			    (ieee80211_is_beacon(fc) ||
			     ieee80211_is_probe_resp(fc))) {
				dev_kfree_skb_any(skb);
			} else {
				_rtl_pci_rx_to_mac80211(hw, skb, rx_status);
			}
		} else {
			dev_kfree_skb_any(skb);
		}
883
new_trx_end:
884 885 886 887 888 889 890 891 892
		if (rtlpriv->use_new_trx_flow) {
			rtlpci->rx_ring[hw_queue].next_rx_rp += 1;
			rtlpci->rx_ring[hw_queue].next_rx_rp %=
					RTL_PCI_MAX_RX_COUNT;

			rx_remained_cnt--;
			rtl_write_word(rtlpriv, 0x3B4,
				       rtlpci->rx_ring[hw_queue].next_rx_rp);
		}
893
		if (((rtlpriv->link_info.num_rx_inperiod +
894
		      rtlpriv->link_info.num_tx_inperiod) > 8) ||
895
		      rtlpriv->link_info.num_rx_inperiod > 2)
L
Larry Finger 已提交
896
			rtl_lps_leave(hw);
897 898
		skb = new_skb;
no_new:
899
		if (rtlpriv->use_new_trx_flow) {
900
			_rtl_pci_init_one_rxdesc(hw, skb, (u8 *)buffer_desc,
901
						 rxring_idx,
902
						 rtlpci->rx_ring[rxring_idx].idx);
903
		} else {
904 905
			_rtl_pci_init_one_rxdesc(hw, skb, (u8 *)pdesc,
						 rxring_idx,
906 907 908 909 910 911 912 913 914 915 916
						 rtlpci->rx_ring[rxring_idx].idx);
			if (rtlpci->rx_ring[rxring_idx].idx ==
			    rtlpci->rxringcount - 1)
				rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc,
							    false,
							    HW_DESC_RXERO,
							    (u8 *)&tmp_one);
		}
		rtlpci->rx_ring[rxring_idx].idx =
				(rtlpci->rx_ring[rxring_idx].idx + 1) %
				rtlpci->rxringcount;
L
Larry Finger 已提交
917 918 919 920 921 922
	}
}

static irqreturn_t _rtl_pci_interrupt(int irq, void *dev_id)
{
	struct ieee80211_hw *hw = dev_id;
923
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
L
Larry Finger 已提交
924
	struct rtl_priv *rtlpriv = rtl_priv(hw);
925
	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
L
Larry Finger 已提交
926 927 928
	unsigned long flags;
	u32 inta = 0;
	u32 intb = 0;
929
	u32 intc = 0;
930
	u32 intd = 0;
931
	irqreturn_t ret = IRQ_HANDLED;
L
Larry Finger 已提交
932

933 934 935
	if (rtlpci->irq_enabled == 0)
		return ret;

936
	spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
937
	rtlpriv->cfg->ops->disable_interrupt(hw);
L
Larry Finger 已提交
938 939

	/*read ISR: 4/8bytes */
940
	rtlpriv->cfg->ops->interrupt_recognized(hw, &inta, &intb, &intc, &intd);
L
Larry Finger 已提交
941

942
	/*Shared IRQ or HW disappeared */
943
	if (!inta || inta == 0xffff)
L
Larry Finger 已提交
944 945 946
		goto done;

	/*<1> beacon related */
947
	if (inta & rtlpriv->cfg->maps[RTL_IMR_TBDOK])
L
Larry Finger 已提交
948
		RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
949
			 "beacon ok interrupt!\n");
L
Larry Finger 已提交
950

951
	if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_TBDER]))
L
Larry Finger 已提交
952
		RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
953
			 "beacon err interrupt!\n");
L
Larry Finger 已提交
954

955
	if (inta & rtlpriv->cfg->maps[RTL_IMR_BDOK])
956
		RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, "beacon interrupt!\n");
L
Larry Finger 已提交
957

958
	if (inta & rtlpriv->cfg->maps[RTL_IMR_BCNINT]) {
L
Larry Finger 已提交
959
		RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
960
			 "prepare beacon for interrupt!\n");
L
Larry Finger 已提交
961 962 963
		tasklet_schedule(&rtlpriv->works.irq_prepare_bcn_tasklet);
	}

964 965
	/*<2> Tx related */
	if (unlikely(intb & rtlpriv->cfg->maps[RTL_IMR_TXFOVW]))
966
		RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, "IMR_TXFOVW!\n");
L
Larry Finger 已提交
967 968 969

	if (inta & rtlpriv->cfg->maps[RTL_IMR_MGNTDOK]) {
		RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
970
			 "Manage ok interrupt!\n");
L
Larry Finger 已提交
971 972 973 974 975
		_rtl_pci_tx_isr(hw, MGNT_QUEUE);
	}

	if (inta & rtlpriv->cfg->maps[RTL_IMR_HIGHDOK]) {
		RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
976
			 "HIGH_QUEUE ok interrupt!\n");
L
Larry Finger 已提交
977 978 979 980 981 982 983
		_rtl_pci_tx_isr(hw, HIGH_QUEUE);
	}

	if (inta & rtlpriv->cfg->maps[RTL_IMR_BKDOK]) {
		rtlpriv->link_info.num_tx_inperiod++;

		RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
984
			 "BK Tx OK interrupt!\n");
L
Larry Finger 已提交
985 986 987 988 989 990 991
		_rtl_pci_tx_isr(hw, BK_QUEUE);
	}

	if (inta & rtlpriv->cfg->maps[RTL_IMR_BEDOK]) {
		rtlpriv->link_info.num_tx_inperiod++;

		RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
992
			 "BE TX OK interrupt!\n");
L
Larry Finger 已提交
993 994 995 996 997 998 999
		_rtl_pci_tx_isr(hw, BE_QUEUE);
	}

	if (inta & rtlpriv->cfg->maps[RTL_IMR_VIDOK]) {
		rtlpriv->link_info.num_tx_inperiod++;

		RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
1000
			 "VI TX OK interrupt!\n");
L
Larry Finger 已提交
1001 1002 1003 1004 1005 1006 1007
		_rtl_pci_tx_isr(hw, VI_QUEUE);
	}

	if (inta & rtlpriv->cfg->maps[RTL_IMR_VODOK]) {
		rtlpriv->link_info.num_tx_inperiod++;

		RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
1008
			 "Vo TX OK interrupt!\n");
L
Larry Finger 已提交
1009 1010 1011
		_rtl_pci_tx_isr(hw, VO_QUEUE);
	}

1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
	if (rtlhal->hw_type == HARDWARE_TYPE_RTL8822BE) {
		if (intd & rtlpriv->cfg->maps[RTL_IMR_H2CDOK]) {
			rtlpriv->link_info.num_tx_inperiod++;

			RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
				 "H2C TX OK interrupt!\n");
			_rtl_pci_tx_isr(hw, H2C_QUEUE);
		}
	}

1022 1023 1024 1025 1026
	if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192SE) {
		if (inta & rtlpriv->cfg->maps[RTL_IMR_COMDOK]) {
			rtlpriv->link_info.num_tx_inperiod++;

			RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
1027
				 "CMD TX OK interrupt!\n");
1028 1029 1030 1031
			_rtl_pci_tx_isr(hw, TXCMD_QUEUE);
		}
	}

1032
	/*<3> Rx related */
L
Larry Finger 已提交
1033
	if (inta & rtlpriv->cfg->maps[RTL_IMR_ROK]) {
1034
		RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE, "Rx ok interrupt!\n");
1035
		_rtl_pci_rx_interrupt(hw);
L
Larry Finger 已提交
1036 1037 1038 1039
	}

	if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_RDU])) {
		RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1040
			 "rx descriptor unavailable!\n");
1041
		_rtl_pci_rx_interrupt(hw);
L
Larry Finger 已提交
1042 1043
	}

1044
	if (unlikely(intb & rtlpriv->cfg->maps[RTL_IMR_RXFOVW])) {
1045
		RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, "rx overflow !\n");
1046
		_rtl_pci_rx_interrupt(hw);
L
Larry Finger 已提交
1047 1048
	}

1049
	/*<4> fw related*/
1050 1051 1052 1053 1054 1055 1056 1057 1058
	if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723AE) {
		if (inta & rtlpriv->cfg->maps[RTL_IMR_C2HCMD]) {
			RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
				 "firmware interrupt!\n");
			queue_delayed_work(rtlpriv->works.rtl_wq,
					   &rtlpriv->works.fwevt_wq, 0);
		}
	}

1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073
	/*<5> hsisr related*/
	/* Only 8188EE & 8723BE Supported.
	 * If Other ICs Come in, System will corrupt,
	 * because maps[RTL_IMR_HSISR_IND] & maps[MAC_HSISR]
	 * are not initialized
	 */
	if (rtlhal->hw_type == HARDWARE_TYPE_RTL8188EE ||
	    rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
		if (unlikely(inta & rtlpriv->cfg->maps[RTL_IMR_HSISR_IND])) {
			RT_TRACE(rtlpriv, COMP_INTR, DBG_TRACE,
				 "hsisr interrupt!\n");
			_rtl_pci_hs_interrupt(hw);
		}
	}

1074 1075 1076
	if (rtlpriv->rtlhal.earlymode_enable)
		tasklet_schedule(&rtlpriv->works.irq_tasklet);

L
Larry Finger 已提交
1077
done:
1078
	rtlpriv->cfg->ops->enable_interrupt(hw);
L
Larry Finger 已提交
1079
	spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
1080
	return ret;
L
Larry Finger 已提交
1081 1082 1083 1084
}

static void _rtl_pci_irq_tasklet(struct ieee80211_hw *hw)
{
1085
	_rtl_pci_tx_chk_waitq(hw);
L
Larry Finger 已提交
1086 1087 1088 1089 1090 1091 1092
}

static void _rtl_pci_prepare_bcn_tasklet(struct ieee80211_hw *hw)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1093
	struct rtl8192_tx_ring *ring = NULL;
L
Larry Finger 已提交
1094 1095 1096 1097
	struct ieee80211_hdr *hdr = NULL;
	struct ieee80211_tx_info *info = NULL;
	struct sk_buff *pskb = NULL;
	struct rtl_tx_desc *pdesc = NULL;
1098
	struct rtl_tcb_desc tcb_desc;
1099 1100
	/*This is for new trx flow*/
	struct rtl_tx_buffer_desc *pbuffer_desc = NULL;
L
Larry Finger 已提交
1101
	u8 temp_one = 1;
1102
	u8 *entry;
L
Larry Finger 已提交
1103

1104
	memset(&tcb_desc, 0, sizeof(struct rtl_tcb_desc));
L
Larry Finger 已提交
1105 1106
	ring = &rtlpci->tx_ring[BEACON_QUEUE];
	pskb = __skb_dequeue(&ring->queue);
1107 1108 1109 1110 1111 1112 1113
	if (rtlpriv->use_new_trx_flow)
		entry = (u8 *)(&ring->buffer_desc[ring->idx]);
	else
		entry = (u8 *)(&ring->desc[ring->idx]);
	if (pskb) {
		pci_unmap_single(rtlpci->pdev,
				 rtlpriv->cfg->ops->get_desc(
1114
				 hw, (u8 *)entry, true, HW_DESC_TXBUFF_ADDR),
1115
				 pskb->len, PCI_DMA_TODEVICE);
L
Larry Finger 已提交
1116
		kfree_skb(pskb);
1117
	}
L
Larry Finger 已提交
1118 1119 1120

	/*NB: the beacon data buffer must be 32-bit aligned. */
	pskb = ieee80211_beacon_get(hw, mac->vif);
1121
	if (!pskb)
L
Larry Finger 已提交
1122
		return;
1123
	hdr = rtl_get_hdr(pskb);
L
Larry Finger 已提交
1124 1125
	info = IEEE80211_SKB_CB(pskb);
	pdesc = &ring->desc[0];
1126 1127 1128 1129
	if (rtlpriv->use_new_trx_flow)
		pbuffer_desc = &ring->buffer_desc[0];

	rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc,
1130 1131
					(u8 *)pbuffer_desc, info, NULL, pskb,
					BEACON_QUEUE, &tcb_desc);
L
Larry Finger 已提交
1132 1133 1134

	__skb_queue_tail(&ring->queue, pskb);

1135 1136 1137 1138 1139 1140 1141 1142
	if (rtlpriv->use_new_trx_flow) {
		temp_one = 4;
		rtlpriv->cfg->ops->set_desc(hw, (u8 *)pbuffer_desc, true,
					    HW_DESC_OWN, (u8 *)&temp_one);
	} else {
		rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, true, HW_DESC_OWN,
					    &temp_one);
	}
L
Larry Finger 已提交
1143 1144 1145 1146 1147
}

static void _rtl_pci_init_trx_var(struct ieee80211_hw *hw)
{
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1148 1149
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
L
Larry Finger 已提交
1150
	u8 i;
1151 1152 1153 1154
	u16 desc_num;

	if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE)
		desc_num = TX_DESC_NUM_92E;
1155 1156
	else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8822BE)
		desc_num = TX_DESC_NUM_8822B;
1157 1158
	else
		desc_num = RT_TXDESC_NUM;
L
Larry Finger 已提交
1159 1160

	for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++)
1161
		rtlpci->txringcount[i] = desc_num;
L
Larry Finger 已提交
1162

1163
	/*we just alloc 2 desc for beacon queue,
L
Larry Finger 已提交
1164 1165 1166 1167
	 *because we just need first desc in hw beacon.
	 */
	rtlpci->txringcount[BEACON_QUEUE] = 2;

1168
	/*BE queue need more descriptor for performance
L
Larry Finger 已提交
1169 1170 1171
	 *consideration or, No more tx desc will happen,
	 *and may cause mac80211 mem leakage.
	 */
1172 1173
	if (!rtl_priv(hw)->use_new_trx_flow)
		rtlpci->txringcount[BE_QUEUE] = RT_TXDESC_NUM_BE_QUEUE;
L
Larry Finger 已提交
1174 1175 1176 1177 1178 1179

	rtlpci->rxbuffersize = 9100;	/*2048/1024; */
	rtlpci->rxringcount = RTL_PCI_MAX_RX_COUNT;	/*64; */
}

static void _rtl_pci_init_struct(struct ieee80211_hw *hw,
1180
				 struct pci_dev *pdev)
L
Larry Finger 已提交
1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));

	rtlpci->up_first_time = true;
	rtlpci->being_init_adapter = false;

	rtlhal->hw = hw;
	rtlpci->pdev = pdev;

	/*Tx/Rx related var */
	_rtl_pci_init_trx_var(hw);

L
Larry Finger 已提交
1196 1197
	/*IBSS*/
	mac->beacon_interval = 100;
L
Larry Finger 已提交
1198

1199 1200
	/*AMPDU*/
	mac->min_space_cfg = 0;
L
Larry Finger 已提交
1201 1202 1203 1204 1205
	mac->max_mss_density = 0;
	/*set sane AMPDU defaults */
	mac->current_ampdu_density = 7;
	mac->current_ampdu_factor = 3;

1206 1207 1208 1209
	/*Retry Limit*/
	mac->retry_short = 7;
	mac->retry_long = 7;

1210
	/*QOS*/
1211
	rtlpci->acm_method = EACMWAY2_SW;
L
Larry Finger 已提交
1212 1213 1214 1215 1216 1217 1218 1219

	/*task */
	tasklet_init(&rtlpriv->works.irq_tasklet,
		     (void (*)(unsigned long))_rtl_pci_irq_tasklet,
		     (unsigned long)hw);
	tasklet_init(&rtlpriv->works.irq_prepare_bcn_tasklet,
		     (void (*)(unsigned long))_rtl_pci_prepare_bcn_tasklet,
		     (unsigned long)hw);
1220 1221
	INIT_WORK(&rtlpriv->works.lps_change_work,
		  rtl_lps_change_work_callback);
L
Larry Finger 已提交
1222 1223 1224 1225 1226 1227 1228
}

static int _rtl_pci_init_tx_ring(struct ieee80211_hw *hw,
				 unsigned int prio, unsigned int entries)
{
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	struct rtl_priv *rtlpriv = rtl_priv(hw);
1229 1230 1231
	struct rtl_tx_buffer_desc *buffer_desc;
	struct rtl_tx_desc *desc;
	dma_addr_t buffer_desc_dma, desc_dma;
L
Larry Finger 已提交
1232 1233 1234
	u32 nextdescaddress;
	int i;

1235 1236 1237 1238 1239 1240 1241 1242
	/* alloc tx buffer desc for new trx flow*/
	if (rtlpriv->use_new_trx_flow) {
		buffer_desc =
		   pci_zalloc_consistent(rtlpci->pdev,
					 sizeof(*buffer_desc) * entries,
					 &buffer_desc_dma);

		if (!buffer_desc || (unsigned long)buffer_desc & 0xFF) {
1243 1244
			pr_err("Cannot allocate TX ring (prio = %d)\n",
			       prio);
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260
			return -ENOMEM;
		}

		rtlpci->tx_ring[prio].buffer_desc = buffer_desc;
		rtlpci->tx_ring[prio].buffer_desc_dma = buffer_desc_dma;

		rtlpci->tx_ring[prio].cur_tx_rp = 0;
		rtlpci->tx_ring[prio].cur_tx_wp = 0;
		rtlpci->tx_ring[prio].avl_desc = entries;
	}

	/* alloc dma for this ring */
	desc = pci_zalloc_consistent(rtlpci->pdev,
				     sizeof(*desc) * entries, &desc_dma);

	if (!desc || (unsigned long)desc & 0xFF) {
1261
		pr_err("Cannot allocate TX ring (prio = %d)\n", prio);
L
Larry Finger 已提交
1262 1263 1264
		return -ENOMEM;
	}

1265 1266 1267
	rtlpci->tx_ring[prio].desc = desc;
	rtlpci->tx_ring[prio].dma = desc_dma;

L
Larry Finger 已提交
1268 1269 1270 1271
	rtlpci->tx_ring[prio].idx = 0;
	rtlpci->tx_ring[prio].entries = entries;
	skb_queue_head_init(&rtlpci->tx_ring[prio].queue);

1272
	RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "queue:%d, ring_addr:%p\n",
1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
		 prio, desc);

	/* init every desc in this ring */
	if (!rtlpriv->use_new_trx_flow) {
		for (i = 0; i < entries; i++) {
			nextdescaddress = (u32)desc_dma +
					  ((i +	1) % entries) *
					  sizeof(*desc);

			rtlpriv->cfg->ops->set_desc(hw, (u8 *)&desc[i],
						    true,
						    HW_DESC_TX_NEXTDESC_ADDR,
						    (u8 *)&nextdescaddress);
		}
L
Larry Finger 已提交
1287 1288 1289 1290
	}
	return 0;
}

1291
static int _rtl_pci_init_rx_ring(struct ieee80211_hw *hw, int rxring_idx)
L
Larry Finger 已提交
1292 1293 1294
{
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	struct rtl_priv *rtlpriv = rtl_priv(hw);
1295
	int i;
L
Larry Finger 已提交
1296

1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
	if (rtlpriv->use_new_trx_flow) {
		struct rtl_rx_buffer_desc *entry = NULL;
		/* alloc dma for this ring */
		rtlpci->rx_ring[rxring_idx].buffer_desc =
		    pci_zalloc_consistent(rtlpci->pdev,
					  sizeof(*rtlpci->rx_ring[rxring_idx].
						 buffer_desc) *
						 rtlpci->rxringcount,
					  &rtlpci->rx_ring[rxring_idx].dma);
		if (!rtlpci->rx_ring[rxring_idx].buffer_desc ||
		    (ulong)rtlpci->rx_ring[rxring_idx].buffer_desc & 0xFF) {
1308
			pr_err("Cannot allocate RX ring\n");
L
Larry Finger 已提交
1309 1310 1311
			return -ENOMEM;
		}

1312 1313 1314 1315
		/* init every desc in this ring */
		rtlpci->rx_ring[rxring_idx].idx = 0;
		for (i = 0; i < rtlpci->rxringcount; i++) {
			entry = &rtlpci->rx_ring[rxring_idx].buffer_desc[i];
1316
			if (!_rtl_pci_init_one_rxdesc(hw, NULL, (u8 *)entry,
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330
						      rxring_idx, i))
				return -ENOMEM;
		}
	} else {
		struct rtl_rx_desc *entry = NULL;
		u8 tmp_one = 1;
		/* alloc dma for this ring */
		rtlpci->rx_ring[rxring_idx].desc =
		    pci_zalloc_consistent(rtlpci->pdev,
					  sizeof(*rtlpci->rx_ring[rxring_idx].
					  desc) * rtlpci->rxringcount,
					  &rtlpci->rx_ring[rxring_idx].dma);
		if (!rtlpci->rx_ring[rxring_idx].desc ||
		    (unsigned long)rtlpci->rx_ring[rxring_idx].desc & 0xFF) {
1331
			pr_err("Cannot allocate RX ring\n");
1332 1333
			return -ENOMEM;
		}
L
Larry Finger 已提交
1334

1335 1336
		/* init every desc in this ring */
		rtlpci->rx_ring[rxring_idx].idx = 0;
1337

L
Larry Finger 已提交
1338
		for (i = 0; i < rtlpci->rxringcount; i++) {
1339
			entry = &rtlpci->rx_ring[rxring_idx].desc[i];
1340
			if (!_rtl_pci_init_one_rxdesc(hw, NULL, (u8 *)entry,
1341 1342
						      rxring_idx, i))
				return -ENOMEM;
L
Larry Finger 已提交
1343 1344
		}

1345
		rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false,
1346
					    HW_DESC_RXERO, &tmp_one);
L
Larry Finger 已提交
1347 1348 1349 1350 1351
	}
	return 0;
}

static void _rtl_pci_free_tx_ring(struct ieee80211_hw *hw,
1352
				  unsigned int prio)
L
Larry Finger 已提交
1353 1354 1355 1356 1357
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[prio];

1358
	/* free every desc in this ring */
L
Larry Finger 已提交
1359
	while (skb_queue_len(&ring->queue)) {
1360
		u8 *entry;
L
Larry Finger 已提交
1361 1362
		struct sk_buff *skb = __skb_dequeue(&ring->queue);

1363 1364 1365 1366 1367
		if (rtlpriv->use_new_trx_flow)
			entry = (u8 *)(&ring->buffer_desc[ring->idx]);
		else
			entry = (u8 *)(&ring->desc[ring->idx]);

L
Larry Finger 已提交
1368
		pci_unmap_single(rtlpci->pdev,
1369
				 rtlpriv->cfg->ops->get_desc(hw, (u8 *)entry,
1370
						   true,
1371
						   HW_DESC_TXBUFF_ADDR),
L
Larry Finger 已提交
1372 1373 1374 1375 1376
				 skb->len, PCI_DMA_TODEVICE);
		kfree_skb(skb);
		ring->idx = (ring->idx + 1) % ring->entries;
	}

1377 1378 1379 1380 1381 1382
	/* free dma of this ring */
	pci_free_consistent(rtlpci->pdev,
			    sizeof(*ring->desc) * ring->entries,
			    ring->desc, ring->dma);
	ring->desc = NULL;
	if (rtlpriv->use_new_trx_flow) {
1383
		pci_free_consistent(rtlpci->pdev,
1384
				    sizeof(*ring->buffer_desc) * ring->entries,
1385
				    ring->buffer_desc, ring->buffer_desc_dma);
1386
		ring->buffer_desc = NULL;
1387
	}
L
Larry Finger 已提交
1388 1389
}

1390
static void _rtl_pci_free_rx_ring(struct ieee80211_hw *hw, int rxring_idx)
L
Larry Finger 已提交
1391
{
1392 1393 1394
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	int i;
L
Larry Finger 已提交
1395

1396 1397 1398
	/* free every desc in this ring */
	for (i = 0; i < rtlpci->rxringcount; i++) {
		struct sk_buff *skb = rtlpci->rx_ring[rxring_idx].rx_buf[i];
L
Larry Finger 已提交
1399

1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421
		if (!skb)
			continue;
		pci_unmap_single(rtlpci->pdev, *((dma_addr_t *)skb->cb),
				 rtlpci->rxbuffersize, PCI_DMA_FROMDEVICE);
		kfree_skb(skb);
	}

	/* free dma of this ring */
	if (rtlpriv->use_new_trx_flow) {
		pci_free_consistent(rtlpci->pdev,
				    sizeof(*rtlpci->rx_ring[rxring_idx].
				    buffer_desc) * rtlpci->rxringcount,
				    rtlpci->rx_ring[rxring_idx].buffer_desc,
				    rtlpci->rx_ring[rxring_idx].dma);
		rtlpci->rx_ring[rxring_idx].buffer_desc = NULL;
	} else {
		pci_free_consistent(rtlpci->pdev,
				    sizeof(*rtlpci->rx_ring[rxring_idx].desc) *
				    rtlpci->rxringcount,
				    rtlpci->rx_ring[rxring_idx].desc,
				    rtlpci->rx_ring[rxring_idx].dma);
		rtlpci->rx_ring[rxring_idx].desc = NULL;
L
Larry Finger 已提交
1422 1423 1424 1425 1426 1427 1428
	}
}

static int _rtl_pci_init_trx_ring(struct ieee80211_hw *hw)
{
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	int ret;
1429
	int i, rxring_idx;
L
Larry Finger 已提交
1430

1431 1432 1433 1434 1435 1436 1437 1438
	/* rxring_idx 0:RX_MPDU_QUEUE
	 * rxring_idx 1:RX_CMD_QUEUE
	 */
	for (rxring_idx = 0; rxring_idx < RTL_PCI_MAX_RX_QUEUE; rxring_idx++) {
		ret = _rtl_pci_init_rx_ring(hw, rxring_idx);
		if (ret)
			return ret;
	}
L
Larry Finger 已提交
1439 1440

	for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) {
1441
		ret = _rtl_pci_init_tx_ring(hw, i, rtlpci->txringcount[i]);
L
Larry Finger 已提交
1442 1443 1444 1445 1446 1447 1448
		if (ret)
			goto err_free_rings;
	}

	return 0;

err_free_rings:
1449 1450
	for (rxring_idx = 0; rxring_idx < RTL_PCI_MAX_RX_QUEUE; rxring_idx++)
		_rtl_pci_free_rx_ring(hw, rxring_idx);
L
Larry Finger 已提交
1451 1452

	for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++)
1453 1454
		if (rtlpci->tx_ring[i].desc ||
		    rtlpci->tx_ring[i].buffer_desc)
L
Larry Finger 已提交
1455 1456 1457 1458 1459 1460 1461
			_rtl_pci_free_tx_ring(hw, i);

	return 1;
}

static int _rtl_pci_deinit_trx_ring(struct ieee80211_hw *hw)
{
1462
	u32 i, rxring_idx;
L
Larry Finger 已提交
1463 1464

	/*free rx rings */
1465 1466
	for (rxring_idx = 0; rxring_idx < RTL_PCI_MAX_RX_QUEUE; rxring_idx++)
		_rtl_pci_free_rx_ring(hw, rxring_idx);
L
Larry Finger 已提交
1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478

	/*free tx rings */
	for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++)
		_rtl_pci_free_tx_ring(hw, i);

	return 0;
}

int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
1479
	int i, rxring_idx;
L
Larry Finger 已提交
1480 1481
	unsigned long flags;
	u8 tmp_one = 1;
1482 1483 1484 1485 1486 1487 1488
	u32 bufferaddress;
	/* rxring_idx 0:RX_MPDU_QUEUE */
	/* rxring_idx 1:RX_CMD_QUEUE */
	for (rxring_idx = 0; rxring_idx < RTL_PCI_MAX_RX_QUEUE; rxring_idx++) {
		/* force the rx_ring[RX_MPDU_QUEUE/
		 * RX_CMD_QUEUE].idx to the first one
		 *new trx flow, do nothing
1489
		 */
1490 1491
		if (!rtlpriv->use_new_trx_flow &&
		    rtlpci->rx_ring[rxring_idx].desc) {
L
Larry Finger 已提交
1492 1493
			struct rtl_rx_desc *entry = NULL;

1494
			rtlpci->rx_ring[rxring_idx].idx = 0;
L
Larry Finger 已提交
1495
			for (i = 0; i < rtlpci->rxringcount; i++) {
1496 1497
				entry = &rtlpci->rx_ring[rxring_idx].desc[i];
				bufferaddress =
1498
				  rtlpriv->cfg->ops->get_desc(hw, (u8 *)entry,
1499 1500
				  false, HW_DESC_RXBUFF_ADDR);
				memset((u8 *)entry, 0,
1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521
				       sizeof(*rtlpci->rx_ring
				       [rxring_idx].desc));/*clear one entry*/
				if (rtlpriv->use_new_trx_flow) {
					rtlpriv->cfg->ops->set_desc(hw,
					    (u8 *)entry, false,
					    HW_DESC_RX_PREPARE,
					    (u8 *)&bufferaddress);
				} else {
					rtlpriv->cfg->ops->set_desc(hw,
					    (u8 *)entry, false,
					    HW_DESC_RXBUFF_ADDR,
					    (u8 *)&bufferaddress);
					rtlpriv->cfg->ops->set_desc(hw,
					    (u8 *)entry, false,
					    HW_DESC_RXPKT_LEN,
					    (u8 *)&rtlpci->rxbuffersize);
					rtlpriv->cfg->ops->set_desc(hw,
					    (u8 *)entry, false,
					    HW_DESC_RXOWN,
					    (u8 *)&tmp_one);
				}
L
Larry Finger 已提交
1522
			}
1523 1524
			rtlpriv->cfg->ops->set_desc(hw, (u8 *)entry, false,
					    HW_DESC_RXERO, (u8 *)&tmp_one);
L
Larry Finger 已提交
1525
		}
1526
		rtlpci->rx_ring[rxring_idx].idx = 0;
L
Larry Finger 已提交
1527 1528
	}

1529
	/*after reset, release previous pending packet,
L
Larry Finger 已提交
1530 1531
	 *and force the  tx idx to the first one
	 */
1532
	spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
L
Larry Finger 已提交
1533
	for (i = 0; i < RTL_PCI_MAX_TX_QUEUE_COUNT; i++) {
1534 1535
		if (rtlpci->tx_ring[i].desc ||
		    rtlpci->tx_ring[i].buffer_desc) {
L
Larry Finger 已提交
1536 1537 1538
			struct rtl8192_tx_ring *ring = &rtlpci->tx_ring[i];

			while (skb_queue_len(&ring->queue)) {
1539 1540 1541 1542 1543 1544 1545 1546
				u8 *entry;
				struct sk_buff *skb =
					__skb_dequeue(&ring->queue);
				if (rtlpriv->use_new_trx_flow)
					entry = (u8 *)(&ring->buffer_desc
								[ring->idx]);
				else
					entry = (u8 *)(&ring->desc[ring->idx]);
L
Larry Finger 已提交
1547 1548

				pci_unmap_single(rtlpci->pdev,
1549
						 rtlpriv->cfg->ops->
1550
							 get_desc(hw, (u8 *)
L
Larry Finger 已提交
1551 1552
							 entry,
							 true,
1553
							 HW_DESC_TXBUFF_ADDR),
L
Larry Finger 已提交
1554
						 skb->len, PCI_DMA_TODEVICE);
1555
				dev_kfree_skb_irq(skb);
1556
				ring->idx = (ring->idx + 1) % ring->entries;
L
Larry Finger 已提交
1557 1558 1559 1560
			}
			ring->idx = 0;
		}
	}
1561
	spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
L
Larry Finger 已提交
1562 1563 1564 1565

	return 0;
}

1566
static bool rtl_pci_tx_chk_waitq_insert(struct ieee80211_hw *hw,
1567
					struct ieee80211_sta *sta,
1568
					struct sk_buff *skb)
L
Larry Finger 已提交
1569
{
1570 1571 1572
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_sta_info *sta_entry = NULL;
	u8 tid = rtl_get_tid(skb);
1573
	__le16 fc = rtl_get_fc(skb);
1574 1575 1576 1577 1578 1579 1580

	if (!sta)
		return false;
	sta_entry = (struct rtl_sta_info *)sta->drv_priv;

	if (!rtlpriv->rtlhal.earlymode_enable)
		return false;
1581 1582 1583 1584 1585 1586
	if (ieee80211_is_nullfunc(fc))
		return false;
	if (ieee80211_is_qos_nullfunc(fc))
		return false;
	if (ieee80211_is_pspoll(fc))
		return false;
1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600
	if (sta_entry->tids[tid].agg.agg_state != RTL_AGG_OPERATIONAL)
		return false;
	if (_rtl_mac_to_hwqueue(hw, skb) > VO_QUEUE)
		return false;
	if (tid > 7)
		return false;

	/* maybe every tid should be checked */
	if (!rtlpriv->link_info.higher_busytxtraffic[tid])
		return false;

	spin_lock_bh(&rtlpriv->locks.waitq_lock);
	skb_queue_tail(&rtlpriv->mac80211.skb_waitq[tid], skb);
	spin_unlock_bh(&rtlpriv->locks.waitq_lock);
L
Larry Finger 已提交
1601

1602
	return true;
L
Larry Finger 已提交
1603 1604
}

1605 1606 1607 1608
static int rtl_pci_tx(struct ieee80211_hw *hw,
		      struct ieee80211_sta *sta,
		      struct sk_buff *skb,
		      struct rtl_tcb_desc *ptcb_desc)
L
Larry Finger 已提交
1609 1610 1611 1612 1613
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
	struct rtl8192_tx_ring *ring;
	struct rtl_tx_desc *pdesc;
1614
	struct rtl_tx_buffer_desc *ptx_bd_desc = NULL;
1615
	u16 idx;
1616
	u8 hw_queue = _rtl_mac_to_hwqueue(hw, skb);
L
Larry Finger 已提交
1617
	unsigned long flags;
1618 1619
	struct ieee80211_hdr *hdr = rtl_get_hdr(skb);
	__le16 fc = rtl_get_fc(skb);
L
Larry Finger 已提交
1620 1621 1622 1623 1624
	u8 *pda_addr = hdr->addr1;
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	u8 own;
	u8 temp_one = 1;

1625 1626
	if (ieee80211_is_mgmt(fc))
		rtl_tx_mgmt_proc(hw, skb);
1627 1628 1629

	if (rtlpriv->psc.sw_ps_enabled) {
		if (ieee80211_is_data(fc) && !ieee80211_is_nullfunc(fc) &&
1630
		    !ieee80211_has_pm(fc))
1631 1632
			hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
	}
L
Larry Finger 已提交
1633

1634
	rtl_action_proc(hw, skb, true);
L
Larry Finger 已提交
1635 1636 1637 1638 1639 1640 1641 1642 1643 1644

	if (is_multicast_ether_addr(pda_addr))
		rtlpriv->stats.txbytesmulticast += skb->len;
	else if (is_broadcast_ether_addr(pda_addr))
		rtlpriv->stats.txbytesbroadcast += skb->len;
	else
		rtlpriv->stats.txbytesunicast += skb->len;

	spin_lock_irqsave(&rtlpriv->locks.irq_th_lock, flags);
	ring = &rtlpci->tx_ring[hw_queue];
1645 1646 1647 1648 1649 1650 1651
	if (hw_queue != BEACON_QUEUE) {
		if (rtlpriv->use_new_trx_flow)
			idx = ring->cur_tx_wp;
		else
			idx = (ring->idx + skb_queue_len(&ring->queue)) %
			      ring->entries;
	} else {
L
Larry Finger 已提交
1652
		idx = 0;
1653
	}
L
Larry Finger 已提交
1654 1655

	pdesc = &ring->desc[idx];
1656 1657 1658
	if (rtlpriv->use_new_trx_flow) {
		ptx_bd_desc = &ring->buffer_desc[idx];
	} else {
1659
		own = (u8)rtlpriv->cfg->ops->get_desc(hw, (u8 *)pdesc,
1660
				true, HW_DESC_OWN);
L
Larry Finger 已提交
1661

1662
		if (own == 1 && hw_queue != BEACON_QUEUE) {
1663
			RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1664
				 "No more TX desc@%d, ring->idx = %d, idx = %d, skb_queue_len = 0x%x\n",
1665 1666
				 hw_queue, ring->idx, idx,
				 skb_queue_len(&ring->queue));
L
Larry Finger 已提交
1667

1668 1669 1670 1671
			spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock,
					       flags);
			return skb->len;
		}
L
Larry Finger 已提交
1672 1673
	}

1674 1675
	if (rtlpriv->cfg->ops->get_available_desc &&
	    rtlpriv->cfg->ops->get_available_desc(hw, hw_queue) == 0) {
1676 1677 1678 1679
		RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
			 "get_available_desc fail\n");
		spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);
		return skb->len;
1680 1681
	}

L
Larry Finger 已提交
1682 1683 1684
	if (ieee80211_is_data(fc))
		rtlpriv->cfg->ops->led_control(hw, LED_CTL_TX);

1685
	rtlpriv->cfg->ops->fill_tx_desc(hw, hdr, (u8 *)pdesc,
1686
			(u8 *)ptx_bd_desc, info, sta, skb, hw_queue, ptcb_desc);
L
Larry Finger 已提交
1687 1688 1689

	__skb_queue_tail(&ring->queue, skb);

1690 1691
	if (rtlpriv->use_new_trx_flow) {
		rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, true,
1692
					    HW_DESC_OWN, &hw_queue);
1693 1694
	} else {
		rtlpriv->cfg->ops->set_desc(hw, (u8 *)pdesc, true,
1695
					    HW_DESC_OWN, &temp_one);
1696
	}
L
Larry Finger 已提交
1697 1698 1699 1700

	if ((ring->entries - skb_queue_len(&ring->queue)) < 2 &&
	    hw_queue != BEACON_QUEUE) {
		RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD,
1701
			 "less desc left, stop skb_queue@%d, ring->idx = %d, idx = %d, skb_queue_len = 0x%x\n",
1702 1703
			 hw_queue, ring->idx, idx,
			 skb_queue_len(&ring->queue));
L
Larry Finger 已提交
1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714

		ieee80211_stop_queue(hw, skb_get_queue_mapping(skb));
	}

	spin_unlock_irqrestore(&rtlpriv->locks.irq_th_lock, flags);

	rtlpriv->cfg->ops->tx_polling(hw, hw_queue);

	return 0;
}

1715
static void rtl_pci_flush(struct ieee80211_hw *hw, u32 queues, bool drop)
1716 1717 1718 1719
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
1720
	struct rtl_mac *mac = rtl_mac(rtl_priv(hw));
1721 1722 1723 1724
	u16 i = 0;
	int queue_id;
	struct rtl8192_tx_ring *ring;

1725 1726 1727
	if (mac->skip_scan)
		return;

1728 1729
	for (queue_id = RTL_PCI_MAX_TX_QUEUE_COUNT - 1; queue_id >= 0;) {
		u32 queue_len;
1730 1731 1732 1733 1734

		if (((queues >> queue_id) & 0x1) == 0) {
			queue_id--;
			continue;
		}
1735 1736 1737
		ring = &pcipriv->dev.tx_ring[queue_id];
		queue_len = skb_queue_len(&ring->queue);
		if (queue_len == 0 || queue_id == BEACON_QUEUE ||
1738
		    queue_id == TXCMD_QUEUE) {
1739 1740 1741 1742 1743 1744 1745 1746 1747
			queue_id--;
			continue;
		} else {
			msleep(20);
			i++;
		}

		/* we just wait 1s for all queues */
		if (rtlpriv->psc.rfpwr_state == ERFOFF ||
1748
		    is_hal_stop(rtlhal) || i >= 200)
1749 1750 1751 1752
			return;
	}
}

1753
static void rtl_pci_deinit(struct ieee80211_hw *hw)
L
Larry Finger 已提交
1754 1755 1756 1757 1758 1759 1760 1761
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));

	_rtl_pci_deinit_trx_ring(hw);

	synchronize_irq(rtlpci->pdev->irq);
	tasklet_kill(&rtlpriv->works.irq_tasklet);
1762
	cancel_work_sync(&rtlpriv->works.lps_change_work);
L
Larry Finger 已提交
1763 1764 1765 1766 1767

	flush_workqueue(rtlpriv->works.rtl_wq);
	destroy_workqueue(rtlpriv->works.rtl_wq);
}

1768
static int rtl_pci_init(struct ieee80211_hw *hw, struct pci_dev *pdev)
L
Larry Finger 已提交
1769 1770 1771 1772 1773 1774 1775
{
	int err;

	_rtl_pci_init_struct(hw, pdev);

	err = _rtl_pci_init_trx_ring(hw);
	if (err) {
1776
		pr_err("tx ring initialization failed\n");
1777
		return err;
L
Larry Finger 已提交
1778 1779
	}

1780
	return 0;
L
Larry Finger 已提交
1781 1782
}

1783
static int rtl_pci_start(struct ieee80211_hw *hw)
L
Larry Finger 已提交
1784 1785 1786 1787 1788
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
1789
	struct rtl_mac *rtlmac = rtl_mac(rtl_priv(hw));
L
Larry Finger 已提交
1790 1791 1792 1793 1794 1795

	int err;

	rtl_pci_reset_trx_ring(hw);

	rtlpci->driver_is_goingto_unload = false;
1796 1797
	if (rtlpriv->cfg->ops->get_btc_status &&
	    rtlpriv->cfg->ops->get_btc_status()) {
1798
		rtlpriv->btcoexist.btc_info.ap_num = 36;
1799 1800 1801
		rtlpriv->btcoexist.btc_ops->btc_init_variables(rtlpriv);
		rtlpriv->btcoexist.btc_ops->btc_init_hal_vars(rtlpriv);
	}
L
Larry Finger 已提交
1802 1803 1804
	err = rtlpriv->cfg->ops->hw_init(hw);
	if (err) {
		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1805
			 "Failed to config hardware!\n");
L
Larry Finger 已提交
1806 1807
		return err;
	}
1808 1809
	rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RETRY_LIMIT,
			&rtlmac->retry_long);
L
Larry Finger 已提交
1810 1811

	rtlpriv->cfg->ops->enable_interrupt(hw);
1812
	RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "enable_interrupt OK\n");
L
Larry Finger 已提交
1813 1814 1815

	rtl_init_rx_config(hw);

1816
	/*should be after adapter start and interrupt enable. */
L
Larry Finger 已提交
1817 1818 1819 1820 1821 1822
	set_hal_start(rtlhal);

	RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC);

	rtlpci->up_first_time = false;

1823
	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "%s OK\n", __func__);
L
Larry Finger 已提交
1824 1825 1826
	return 0;
}

1827
static void rtl_pci_stop(struct ieee80211_hw *hw)
L
Larry Finger 已提交
1828 1829 1830 1831 1832 1833
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw));
	struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw));
	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
	unsigned long flags;
1834
	u8 rf_timeout = 0;
L
Larry Finger 已提交
1835

1836 1837 1838
	if (rtlpriv->cfg->ops->get_btc_status())
		rtlpriv->btcoexist.btc_ops->btc_halt_notify();

1839
	/*should be before disable interrupt&adapter
L
Larry Finger 已提交
1840 1841 1842 1843
	 *and will do it immediately.
	 */
	set_hal_stop(rtlhal);

1844
	rtlpci->driver_is_goingto_unload = true;
L
Larry Finger 已提交
1845
	rtlpriv->cfg->ops->disable_interrupt(hw);
1846
	cancel_work_sync(&rtlpriv->works.lps_change_work);
L
Larry Finger 已提交
1847 1848 1849 1850

	spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
	while (ppsc->rfchange_inprogress) {
		spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags);
1851
		if (rf_timeout > 100) {
L
Larry Finger 已提交
1852 1853 1854 1855
			spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
			break;
		}
		mdelay(1);
1856
		rf_timeout++;
L
Larry Finger 已提交
1857 1858 1859 1860 1861 1862
		spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
	}
	ppsc->rfchange_inprogress = true;
	spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags);

	rtlpriv->cfg->ops->hw_disable(hw);
1863 1864 1865
	/* some things are not needed if firmware not available */
	if (!rtlpriv->max_fw_size)
		return;
L
Larry Finger 已提交
1866 1867 1868 1869 1870 1871 1872 1873 1874 1875
	rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF);

	spin_lock_irqsave(&rtlpriv->locks.rf_ps_lock, flags);
	ppsc->rfchange_inprogress = false;
	spin_unlock_irqrestore(&rtlpriv->locks.rf_ps_lock, flags);

	rtl_pci_enable_aspm(hw);
}

static bool _rtl_pci_find_adapter(struct pci_dev *pdev,
1876
				  struct ieee80211_hw *hw)
L
Larry Finger 已提交
1877 1878 1879 1880 1881 1882 1883
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
	struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw));
	struct pci_dev *bridge_pdev = pdev->bus->self;
	u16 venderid;
	u16 deviceid;
1884
	u8 revisionid;
L
Larry Finger 已提交
1885 1886 1887
	u16 irqline;
	u8 tmp;

1888
	pcipriv->ndis_adapter.pcibridge_vendor = PCI_BRIDGE_VENDOR_UNKNOWN;
L
Larry Finger 已提交
1889 1890
	venderid = pdev->vendor;
	deviceid = pdev->device;
1891
	pci_read_config_byte(pdev, 0x8, &revisionid);
L
Larry Finger 已提交
1892 1893
	pci_read_config_word(pdev, 0x3C, &irqline);

1894 1895 1896 1897 1898 1899 1900 1901 1902 1903
	/* PCI ID 0x10ec:0x8192 occurs for both RTL8192E, which uses
	 * r8192e_pci, and RTL8192SE, which uses this driver. If the
	 * revision ID is RTL_PCI_REVISION_ID_8192PCIE (0x01), then
	 * the correct driver is r8192e_pci, thus this routine should
	 * return false.
	 */
	if (deviceid == RTL_PCI_8192SE_DID &&
	    revisionid == RTL_PCI_REVISION_ID_8192PCIE)
		return false;

L
Larry Finger 已提交
1904 1905 1906 1907 1908 1909 1910 1911
	if (deviceid == RTL_PCI_8192_DID ||
	    deviceid == RTL_PCI_0044_DID ||
	    deviceid == RTL_PCI_0047_DID ||
	    deviceid == RTL_PCI_8192SE_DID ||
	    deviceid == RTL_PCI_8174_DID ||
	    deviceid == RTL_PCI_8173_DID ||
	    deviceid == RTL_PCI_8172_DID ||
	    deviceid == RTL_PCI_8171_DID) {
1912
		switch (revisionid) {
L
Larry Finger 已提交
1913 1914
		case RTL_PCI_REVISION_ID_8192PCIE:
			RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1915 1916
				 "8192 PCI-E is found - vid/did=%x/%x\n",
				 venderid, deviceid);
L
Larry Finger 已提交
1917
			rtlhal->hw_type = HARDWARE_TYPE_RTL8192E;
1918
			return false;
L
Larry Finger 已提交
1919 1920
		case RTL_PCI_REVISION_ID_8192SE:
			RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1921 1922
				 "8192SE is found - vid/did=%x/%x\n",
				 venderid, deviceid);
L
Larry Finger 已提交
1923 1924 1925 1926
			rtlhal->hw_type = HARDWARE_TYPE_RTL8192SE;
			break;
		default:
			RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1927 1928
				 "Err: Unknown device - vid/did=%x/%x\n",
				 venderid, deviceid);
L
Larry Finger 已提交
1929 1930 1931
			rtlhal->hw_type = HARDWARE_TYPE_RTL8192SE;
			break;
		}
1932 1933 1934
	} else if (deviceid == RTL_PCI_8723AE_DID) {
		rtlhal->hw_type = HARDWARE_TYPE_RTL8723AE;
		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1935 1936
			 "8723AE PCI-E is found - vid/did=%x/%x\n",
			 venderid, deviceid);
L
Larry Finger 已提交
1937 1938 1939 1940 1941 1942
	} else if (deviceid == RTL_PCI_8192CET_DID ||
		   deviceid == RTL_PCI_8192CE_DID ||
		   deviceid == RTL_PCI_8191CE_DID ||
		   deviceid == RTL_PCI_8188CE_DID) {
		rtlhal->hw_type = HARDWARE_TYPE_RTL8192CE;
		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1943 1944
			 "8192C PCI-E is found - vid/did=%x/%x\n",
			 venderid, deviceid);
1945 1946 1947 1948
	} else if (deviceid == RTL_PCI_8192DE_DID ||
		   deviceid == RTL_PCI_8192DE_DID2) {
		rtlhal->hw_type = HARDWARE_TYPE_RTL8192DE;
		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
1949 1950
			 "8192D PCI-E is found - vid/did=%x/%x\n",
			 venderid, deviceid);
1951 1952 1953 1954
	} else if (deviceid == RTL_PCI_8188EE_DID) {
		rtlhal->hw_type = HARDWARE_TYPE_RTL8188EE;
		RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
			 "Find adapter, Hardware type is 8188EE\n");
1955
	} else if (deviceid == RTL_PCI_8723BE_DID) {
1956 1957 1958
		rtlhal->hw_type = HARDWARE_TYPE_RTL8723BE;
		RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
			 "Find adapter, Hardware type is 8723BE\n");
1959
	} else if (deviceid == RTL_PCI_8192EE_DID) {
1960 1961 1962
		rtlhal->hw_type = HARDWARE_TYPE_RTL8192EE;
		RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
			 "Find adapter, Hardware type is 8192EE\n");
1963
	} else if (deviceid == RTL_PCI_8821AE_DID) {
1964 1965 1966
		rtlhal->hw_type = HARDWARE_TYPE_RTL8821AE;
		RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
			 "Find adapter, Hardware type is 8821AE\n");
1967
	} else if (deviceid == RTL_PCI_8812AE_DID) {
1968 1969 1970
		rtlhal->hw_type = HARDWARE_TYPE_RTL8812AE;
		RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
			 "Find adapter, Hardware type is 8812AE\n");
P
Ping-Ke Shih 已提交
1971 1972 1973 1974 1975
	} else if (deviceid == RTL_PCI_8822BE_DID) {
		rtlhal->hw_type = HARDWARE_TYPE_RTL8822BE;
		rtlhal->bandset = BAND_ON_BOTH;
		RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
			 "Find adapter, Hardware type is 8822BE\n");
L
Larry Finger 已提交
1976 1977
	} else {
		RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING,
1978 1979
			 "Err: Unknown device - vid/did=%x/%x\n",
			 venderid, deviceid);
L
Larry Finger 已提交
1980 1981 1982 1983

		rtlhal->hw_type = RTL_DEFAULT_HARDWARE_TYPE;
	}

1984 1985 1986
	if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192DE) {
		if (revisionid == 0 || revisionid == 1) {
			if (revisionid == 0) {
1987 1988
				RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
					 "Find 92DE MAC0\n");
1989 1990 1991
				rtlhal->interfaceindex = 0;
			} else if (revisionid == 1) {
				RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1992
					 "Find 92DE MAC1\n");
1993 1994 1995 1996
				rtlhal->interfaceindex = 1;
			}
		} else {
			RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD,
1997 1998
				 "Unknown device - VendorID/DeviceID=%x/%x, Revision=%x\n",
				 venderid, deviceid, revisionid);
1999 2000 2001
			rtlhal->interfaceindex = 0;
		}
	}
2002

2003 2004 2005 2006
	switch (rtlhal->hw_type) {
	case HARDWARE_TYPE_RTL8192EE:
	case HARDWARE_TYPE_RTL8822BE:
		/* use new trx flow */
2007
		rtlpriv->use_new_trx_flow = true;
2008 2009 2010
		break;

	default:
2011
		rtlpriv->use_new_trx_flow = false;
2012 2013
		break;
	}
2014

L
Larry Finger 已提交
2015 2016 2017 2018 2019
	/*find bus info */
	pcipriv->ndis_adapter.busnumber = pdev->bus->number;
	pcipriv->ndis_adapter.devnumber = PCI_SLOT(pdev->devfn);
	pcipriv->ndis_adapter.funcnumber = PCI_FUNC(pdev->devfn);

2020 2021
	/*find bridge info */
	pcipriv->ndis_adapter.pcibridge_vendor = PCI_BRIDGE_VENDOR_UNKNOWN;
2022 2023 2024
	/* some ARM have no bridge_pdev and will crash here
	 * so we should check if bridge_pdev is NULL
	 */
2025 2026 2027 2028 2029 2030 2031
	if (bridge_pdev) {
		/*find bridge info if available */
		pcipriv->ndis_adapter.pcibridge_vendorid = bridge_pdev->vendor;
		for (tmp = 0; tmp < PCI_BRIDGE_VENDOR_MAX; tmp++) {
			if (bridge_pdev->vendor == pcibridge_vendors[tmp]) {
				pcipriv->ndis_adapter.pcibridge_vendor = tmp;
				RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2032 2033
					 "Pci Bridge Vendor is found index: %d\n",
					 tmp);
2034 2035
				break;
			}
L
Larry Finger 已提交
2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046
		}
	}

	if (pcipriv->ndis_adapter.pcibridge_vendor !=
		PCI_BRIDGE_VENDOR_UNKNOWN) {
		pcipriv->ndis_adapter.pcibridge_busnum =
		    bridge_pdev->bus->number;
		pcipriv->ndis_adapter.pcibridge_devnum =
		    PCI_SLOT(bridge_pdev->devfn);
		pcipriv->ndis_adapter.pcibridge_funcnum =
		    PCI_FUNC(bridge_pdev->devfn);
2047 2048
		pcipriv->ndis_adapter.pcibridge_pciehdr_offset =
		    pci_pcie_cap(bridge_pdev);
L
Larry Finger 已提交
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061
		pcipriv->ndis_adapter.num4bytes =
		    (pcipriv->ndis_adapter.pcibridge_pciehdr_offset + 0x10) / 4;

		rtl_pci_get_linkcontrol_field(hw);

		if (pcipriv->ndis_adapter.pcibridge_vendor ==
		    PCI_BRIDGE_VENDOR_AMD) {
			pcipriv->ndis_adapter.amd_l1_patch =
			    rtl_pci_get_amd_l1_patch(hw);
		}
	}

	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2062 2063 2064 2065 2066
		 "pcidev busnumber:devnumber:funcnumber:vendor:link_ctl %d:%d:%d:%x:%x\n",
		 pcipriv->ndis_adapter.busnumber,
		 pcipriv->ndis_adapter.devnumber,
		 pcipriv->ndis_adapter.funcnumber,
		 pdev->vendor, pcipriv->ndis_adapter.linkctrl_reg);
L
Larry Finger 已提交
2067 2068

	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2069 2070 2071 2072 2073 2074 2075 2076
		 "pci_bridge busnumber:devnumber:funcnumber:vendor:pcie_cap:link_ctl_reg:amd %d:%d:%d:%x:%x:%x:%x\n",
		 pcipriv->ndis_adapter.pcibridge_busnum,
		 pcipriv->ndis_adapter.pcibridge_devnum,
		 pcipriv->ndis_adapter.pcibridge_funcnum,
		 pcibridge_vendors[pcipriv->ndis_adapter.pcibridge_vendor],
		 pcipriv->ndis_adapter.pcibridge_pciehdr_offset,
		 pcipriv->ndis_adapter.pcibridge_linkctrlreg,
		 pcipriv->ndis_adapter.amd_l1_patch);
L
Larry Finger 已提交
2077 2078

	rtl_pci_parse_configuration(pdev, hw);
2079
	list_add_tail(&rtlpriv->list, &rtlpriv->glb_var->glb_priv_list);
L
Larry Finger 已提交
2080 2081 2082 2083

	return true;
}

2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103
static int rtl_pci_intr_mode_msi(struct ieee80211_hw *hw)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(pcipriv);
	int ret;

	ret = pci_enable_msi(rtlpci->pdev);
	if (ret < 0)
		return ret;

	ret = request_irq(rtlpci->pdev->irq, &_rtl_pci_interrupt,
			  IRQF_SHARED, KBUILD_MODNAME, hw);
	if (ret < 0) {
		pci_disable_msi(rtlpci->pdev);
		return ret;
	}

	rtlpci->using_msi = true;

2104
	RT_TRACE(rtlpriv, COMP_INIT | COMP_INTR, DBG_DMESG,
2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121
		 "MSI Interrupt Mode!\n");
	return 0;
}

static int rtl_pci_intr_mode_legacy(struct ieee80211_hw *hw)
{
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(pcipriv);
	int ret;

	ret = request_irq(rtlpci->pdev->irq, &_rtl_pci_interrupt,
			  IRQF_SHARED, KBUILD_MODNAME, hw);
	if (ret < 0)
		return ret;

	rtlpci->using_msi = false;
2122
	RT_TRACE(rtlpriv, COMP_INIT | COMP_INTR, DBG_DMESG,
2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142
		 "Pin-based Interrupt Mode!\n");
	return 0;
}

static int rtl_pci_intr_mode_decide(struct ieee80211_hw *hw)
{
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(pcipriv);
	int ret;

	if (rtlpci->msi_support) {
		ret = rtl_pci_intr_mode_msi(hw);
		if (ret < 0)
			ret = rtl_pci_intr_mode_legacy(hw);
	} else {
		ret = rtl_pci_intr_mode_legacy(hw);
	}
	return ret;
}

2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157
static void platform_enable_dma64(struct pci_dev *pdev, bool dma64)
{
	u8	value;

	pci_read_config_byte(pdev, 0x719, &value);

	/* 0x719 Bit5 is DMA64 bit fetch. */
	if (dma64)
		value |= BIT(5);
	else
		value &= ~BIT(5);

	pci_write_config_byte(pdev, 0x719, value);
}

B
Bill Pemberton 已提交
2158
int rtl_pci_probe(struct pci_dev *pdev,
2159
		  const struct pci_device_id *id)
L
Larry Finger 已提交
2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170
{
	struct ieee80211_hw *hw = NULL;

	struct rtl_priv *rtlpriv = NULL;
	struct rtl_pci_priv *pcipriv = NULL;
	struct rtl_pci *rtlpci;
	unsigned long pmem_start, pmem_len, pmem_flags;
	int err;

	err = pci_enable_device(pdev);
	if (err) {
2171
		WARN_ONCE(true, "%s : Cannot enable new PCI device\n",
2172
			  pci_name(pdev));
L
Larry Finger 已提交
2173 2174 2175
		return err;
	}

2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186
	if (((struct rtl_hal_cfg *)id->driver_data)->mod_params->dma64 &&
	    !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
		if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) {
			WARN_ONCE(true,
				  "Unable to obtain 64bit DMA for consistent allocations\n");
			err = -ENOMEM;
			goto fail1;
		}

		platform_enable_dma64(pdev, true);
	} else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
L
Larry Finger 已提交
2187
		if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) {
2188 2189
			WARN_ONCE(true,
				  "rtlwifi: Unable to obtain 32bit DMA for consistent allocations\n");
2190 2191
			err = -ENOMEM;
			goto fail1;
L
Larry Finger 已提交
2192
		}
2193 2194

		platform_enable_dma64(pdev, false);
L
Larry Finger 已提交
2195 2196 2197 2198 2199 2200 2201
	}

	pci_set_master(pdev);

	hw = ieee80211_alloc_hw(sizeof(struct rtl_pci_priv) +
				sizeof(struct rtl_priv), &rtl_ops);
	if (!hw) {
2202
		WARN_ONCE(true,
2203
			  "%s : ieee80211 alloc failed\n", pci_name(pdev));
L
Larry Finger 已提交
2204 2205 2206 2207 2208 2209 2210 2211
		err = -ENOMEM;
		goto fail1;
	}

	SET_IEEE80211_DEV(hw, &pdev->dev);
	pci_set_drvdata(pdev, hw);

	rtlpriv = hw->priv;
2212
	rtlpriv->hw = hw;
L
Larry Finger 已提交
2213 2214
	pcipriv = (void *)rtlpriv->priv;
	pcipriv->dev.pdev = pdev;
2215
	init_completion(&rtlpriv->firmware_loading_complete);
2216 2217 2218 2219 2220
	/*proximity init here*/
	rtlpriv->proximity.proxim_on = false;

	pcipriv = (void *)rtlpriv->priv;
	pcipriv->dev.pdev = pdev;
L
Larry Finger 已提交
2221

2222 2223 2224 2225
	/* init cfg & intf_ops */
	rtlpriv->rtlhal.interface = INTF_PCI;
	rtlpriv->cfg = (struct rtl_hal_cfg *)(id->driver_data);
	rtlpriv->intf_ops = &rtl_pci_ops;
2226
	rtlpriv->glb_var = &rtl_global_var;
2227

L
Larry Finger 已提交
2228 2229 2230
	/* MEM map */
	err = pci_request_regions(pdev, KBUILD_MODNAME);
	if (err) {
2231
		WARN_ONCE(true, "rtlwifi: Can't obtain PCI resources\n");
2232
		goto fail1;
L
Larry Finger 已提交
2233 2234
	}

2235 2236 2237
	pmem_start = pci_resource_start(pdev, rtlpriv->cfg->bar_id);
	pmem_len = pci_resource_len(pdev, rtlpriv->cfg->bar_id);
	pmem_flags = pci_resource_flags(pdev, rtlpriv->cfg->bar_id);
L
Larry Finger 已提交
2238 2239 2240

	/*shared mem start */
	rtlpriv->io.pci_mem_start =
2241 2242
			(unsigned long)pci_iomap(pdev,
			rtlpriv->cfg->bar_id, pmem_len);
L
Larry Finger 已提交
2243
	if (rtlpriv->io.pci_mem_start == 0) {
2244
		WARN_ONCE(true, "rtlwifi: Can't map PCI mem\n");
2245
		err = -ENOMEM;
L
Larry Finger 已提交
2246 2247 2248 2249
		goto fail2;
	}

	RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2250 2251 2252
		 "mem mapped space: start: 0x%08lx len:%08lx flags:%08lx, after map:0x%08lx\n",
		 pmem_start, pmem_len, pmem_flags,
		 rtlpriv->io.pci_mem_start);
L
Larry Finger 已提交
2253 2254 2255 2256 2257 2258 2259 2260 2261

	/* Disable Clk Request */
	pci_write_config_byte(pdev, 0x81, 0);
	/* leave D3 mode */
	pci_write_config_byte(pdev, 0x44, 0);
	pci_write_config_byte(pdev, 0x04, 0x06);
	pci_write_config_byte(pdev, 0x04, 0x07);

	/* find adapter */
2262 2263
	if (!_rtl_pci_find_adapter(pdev, hw)) {
		err = -ENODEV;
2264
		goto fail2;
2265
	}
L
Larry Finger 已提交
2266 2267 2268 2269 2270 2271 2272

	/* Init IO handler */
	_rtl_pci_io_handler_init(&pdev->dev, hw);

	/*like read eeprom and so on */
	rtlpriv->cfg->ops->read_eeprom_info(hw);

2273
	if (rtlpriv->cfg->ops->init_sw_vars(hw)) {
2274
		pr_err("Can't init_sw_vars\n");
2275 2276 2277 2278 2279 2280 2281 2282
		err = -ENODEV;
		goto fail3;
	}
	rtlpriv->cfg->ops->init_sw_leds(hw);

	/*aspm */
	rtl_pci_init_aspm(hw);

L
Larry Finger 已提交
2283 2284 2285
	/* Init mac80211 sw */
	err = rtl_init_core(hw);
	if (err) {
2286
		pr_err("Can't allocate sw for mac80211\n");
L
Larry Finger 已提交
2287 2288 2289 2290
		goto fail3;
	}

	/* Init PCI sw */
2291
	err = rtl_pci_init(hw, pdev);
L
Larry Finger 已提交
2292
	if (err) {
2293
		pr_err("Failed to init PCI\n");
L
Larry Finger 已提交
2294 2295 2296
		goto fail3;
	}

2297 2298
	err = ieee80211_register_hw(hw);
	if (err) {
2299
		pr_err("Can't register mac80211 hw.\n");
2300 2301 2302
		err = -ENODEV;
		goto fail3;
	}
2303
	rtlpriv->mac80211.mac80211_registered = 1;
2304

2305 2306 2307
	/*init rfkill */
	rtl_init_rfkill(hw);	/* Init PCI sw */

L
Larry Finger 已提交
2308
	rtlpci = rtl_pcidev(pcipriv);
2309
	err = rtl_pci_intr_mode_decide(hw);
L
Larry Finger 已提交
2310 2311
	if (err) {
		RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2312 2313
			 "%s: failed to register IRQ handler\n",
			 wiphy_name(hw->wiphy));
L
Larry Finger 已提交
2314 2315
		goto fail3;
	}
2316
	rtlpci->irq_alloc = 1;
L
Larry Finger 已提交
2317

2318
	set_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);
L
Larry Finger 已提交
2319 2320 2321
	return 0;

fail3:
2322
	pci_set_drvdata(pdev, NULL);
L
Larry Finger 已提交
2323 2324
	rtl_deinit_core(hw);

2325
fail2:
L
Larry Finger 已提交
2326
	if (rtlpriv->io.pci_mem_start != 0)
L
Larry Finger 已提交
2327
		pci_iounmap(pdev, (void __iomem *)rtlpriv->io.pci_mem_start);
L
Larry Finger 已提交
2328 2329

	pci_release_regions(pdev);
2330
	complete(&rtlpriv->firmware_loading_complete);
L
Larry Finger 已提交
2331 2332

fail1:
2333 2334
	if (hw)
		ieee80211_free_hw(hw);
L
Larry Finger 已提交
2335 2336
	pci_disable_device(pdev);

2337
	return err;
L
Larry Finger 已提交
2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348
}
EXPORT_SYMBOL(rtl_pci_probe);

void rtl_pci_disconnect(struct pci_dev *pdev)
{
	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
	struct rtl_pci_priv *pcipriv = rtl_pcipriv(hw);
	struct rtl_priv *rtlpriv = rtl_priv(hw);
	struct rtl_pci *rtlpci = rtl_pcidev(pcipriv);
	struct rtl_mac *rtlmac = rtl_mac(rtlpriv);

2349 2350
	/* just in case driver is removed before firmware callback */
	wait_for_completion(&rtlpriv->firmware_loading_complete);
L
Larry Finger 已提交
2351 2352 2353 2354 2355 2356 2357 2358 2359 2360
	clear_bit(RTL_STATUS_INTERFACE_START, &rtlpriv->status);

	/*ieee80211_unregister_hw will call ops_stop */
	if (rtlmac->mac80211_registered == 1) {
		ieee80211_unregister_hw(hw);
		rtlmac->mac80211_registered = 0;
	} else {
		rtl_deinit_deferred_work(hw);
		rtlpriv->intf_ops->adapter_stop(hw);
	}
L
Larry Finger 已提交
2361
	rtlpriv->cfg->ops->disable_interrupt(hw);
L
Larry Finger 已提交
2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374

	/*deinit rfkill */
	rtl_deinit_rfkill(hw);

	rtl_pci_deinit(hw);
	rtl_deinit_core(hw);
	rtlpriv->cfg->ops->deinit_sw_vars(hw);

	if (rtlpci->irq_alloc) {
		free_irq(rtlpci->pdev->irq, hw);
		rtlpci->irq_alloc = 0;
	}

2375 2376 2377
	if (rtlpci->using_msi)
		pci_disable_msi(rtlpci->pdev);

2378
	list_del(&rtlpriv->list);
L
Larry Finger 已提交
2379
	if (rtlpriv->io.pci_mem_start != 0) {
L
Larry Finger 已提交
2380
		pci_iounmap(pdev, (void __iomem *)rtlpriv->io.pci_mem_start);
L
Larry Finger 已提交
2381 2382 2383 2384
		pci_release_regions(pdev);
	}

	pci_disable_device(pdev);
2385 2386 2387

	rtl_pci_disable_aspm(hw);

2388 2389
	pci_set_drvdata(pdev, NULL);

L
Larry Finger 已提交
2390 2391 2392 2393
	ieee80211_free_hw(hw);
}
EXPORT_SYMBOL(rtl_pci_disconnect);

H
Hauke Mehrtens 已提交
2394
#ifdef CONFIG_PM_SLEEP
L
Larry Finger 已提交
2395
/***************************************
2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409
 * kernel pci power state define:
 * PCI_D0         ((pci_power_t __force) 0)
 * PCI_D1         ((pci_power_t __force) 1)
 * PCI_D2         ((pci_power_t __force) 2)
 * PCI_D3hot      ((pci_power_t __force) 3)
 * PCI_D3cold     ((pci_power_t __force) 4)
 * PCI_UNKNOWN    ((pci_power_t __force) 5)

 * This function is called when system
 * goes into suspend state mac80211 will
 * call rtl_mac_stop() from the mac80211
 * suspend function first, So there is
 * no need to call hw_disable here.
 ****************************************/
2410
int rtl_pci_suspend(struct device *dev)
L
Larry Finger 已提交
2411
{
2412
	struct pci_dev *pdev = to_pci_dev(dev);
2413 2414 2415 2416 2417 2418
	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
	struct rtl_priv *rtlpriv = rtl_priv(hw);

	rtlpriv->cfg->ops->hw_suspend(hw);
	rtl_deinit_rfkill(hw);

L
Larry Finger 已提交
2419 2420 2421 2422
	return 0;
}
EXPORT_SYMBOL(rtl_pci_suspend);

2423
int rtl_pci_resume(struct device *dev)
L
Larry Finger 已提交
2424
{
2425
	struct pci_dev *pdev = to_pci_dev(dev);
2426 2427
	struct ieee80211_hw *hw = pci_get_drvdata(pdev);
	struct rtl_priv *rtlpriv = rtl_priv(hw);
L
Larry Finger 已提交
2428

2429 2430
	rtlpriv->cfg->ops->hw_resume(hw);
	rtl_init_rfkill(hw);
L
Larry Finger 已提交
2431 2432 2433
	return 0;
}
EXPORT_SYMBOL(rtl_pci_resume);
H
Hauke Mehrtens 已提交
2434
#endif /* CONFIG_PM_SLEEP */
L
Larry Finger 已提交
2435

2436
const struct rtl_intf_ops rtl_pci_ops = {
2437
	.read_efuse_byte = read_efuse_byte,
L
Larry Finger 已提交
2438 2439
	.adapter_start = rtl_pci_start,
	.adapter_stop = rtl_pci_stop,
2440
	.check_buddy_priv = rtl_pci_check_buddy_priv,
L
Larry Finger 已提交
2441
	.adapter_tx = rtl_pci_tx,
2442
	.flush = rtl_pci_flush,
L
Larry Finger 已提交
2443
	.reset_trx_ring = rtl_pci_reset_trx_ring,
2444
	.waitq_insert = rtl_pci_tx_chk_waitq_insert,
L
Larry Finger 已提交
2445 2446 2447 2448

	.disable_aspm = rtl_pci_disable_aspm,
	.enable_aspm = rtl_pci_enable_aspm,
};