pci.h 9.0 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
 *
 * 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>
 *
 *****************************************************************************/

#ifndef __RTL_PCI_H__
#define __RTL_PCI_H__

#include <linux/pci.h>
/*
1: MSDU packet queue,
2: Rx Command Queue
*/
#define RTL_PCI_RX_MPDU_QUEUE			0
#define RTL_PCI_RX_CMD_QUEUE			1
#define RTL_PCI_MAX_RX_QUEUE			2

42
#define RTL_PCI_MAX_RX_COUNT			512/*64*/
L
Larry Finger 已提交
43 44 45
#define RTL_PCI_MAX_TX_QUEUE_COUNT		9

#define RT_TXDESC_NUM				128
46
#define TX_DESC_NUM_92E				512
L
Larry Finger 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
#define RT_TXDESC_NUM_BE_QUEUE			256

#define BK_QUEUE				0
#define BE_QUEUE				1
#define VI_QUEUE				2
#define VO_QUEUE				3
#define BEACON_QUEUE				4
#define TXCMD_QUEUE				5
#define MGNT_QUEUE				6
#define HIGH_QUEUE				7
#define HCCA_QUEUE				8

#define RTL_PCI_DEVICE(vend, dev, cfg)  \
	.vendor = (vend), \
	.device = (dev), \
	.subvendor = PCI_ANY_ID, \
	.subdevice = PCI_ANY_ID,\
	.driver_data = (kernel_ulong_t)&(cfg)

66 67 68 69 70 71
#define INTEL_VENDOR_ID				0x8086
#define SIS_VENDOR_ID				0x1039
#define ATI_VENDOR_ID				0x1002
#define ATI_DEVICE_ID				0x7914
#define AMD_VENDOR_ID				0x1022

L
Larry Finger 已提交
72 73 74 75 76 77 78
#define PCI_MAX_BRIDGE_NUMBER			255
#define PCI_MAX_DEVICES				32
#define PCI_MAX_FUNCTION			8

#define PCI_CONF_ADDRESS	0x0CF8	/*PCI Configuration Space Address */
#define PCI_CONF_DATA		0x0CFC	/*PCI Configuration Space Data */

79 80 81 82 83
#define PCI_CLASS_BRIDGE_DEV		0x06
#define PCI_SUBCLASS_BR_PCI_TO_PCI	0x04
#define PCI_CAPABILITY_ID_PCI_EXPRESS	0x10
#define PCI_CAP_ID_EXP			0x10

L
Larry Finger 已提交
84 85 86 87 88 89 90 91 92 93
#define U1DONTCARE			0xFF
#define U2DONTCARE			0xFFFF
#define U4DONTCARE			0xFFFFFFFF

#define RTL_PCI_8192_DID	0x8192	/*8192 PCI-E */
#define RTL_PCI_8192SE_DID	0x8192	/*8192 SE */
#define RTL_PCI_8174_DID	0x8174	/*8192 SE */
#define RTL_PCI_8173_DID	0x8173	/*8191 SE Crab */
#define RTL_PCI_8172_DID	0x8172	/*8191 SE RE */
#define RTL_PCI_8171_DID	0x8171	/*8191 SE Unicron */
94
#define RTL_PCI_8723AE_DID	0x8723	/*8723AE */
L
Larry Finger 已提交
95 96 97 98 99 100 101
#define RTL_PCI_0045_DID	0x0045	/*8190 PCI for Ceraga */
#define RTL_PCI_0046_DID	0x0046	/*8190 Cardbus for Ceraga */
#define RTL_PCI_0044_DID	0x0044	/*8192e PCIE for Ceraga */
#define RTL_PCI_0047_DID	0x0047	/*8192e Express Card for Ceraga */
#define RTL_PCI_700F_DID	0x700F
#define RTL_PCI_701F_DID	0x701F
#define RTL_PCI_DLINK_DID	0x3304
102
#define RTL_PCI_8723AE_DID	0x8723	/*8723e */
L
Larry Finger 已提交
103 104 105 106 107
#define RTL_PCI_8192CET_DID	0x8191	/*8192ce */
#define RTL_PCI_8192CE_DID	0x8178	/*8192ce */
#define RTL_PCI_8191CE_DID	0x8177	/*8192ce */
#define RTL_PCI_8188CE_DID	0x8176	/*8192ce */
#define RTL_PCI_8192CU_DID	0x8191	/*8192ce */
108 109
#define RTL_PCI_8192DE_DID	0x8193	/*8192de */
#define RTL_PCI_8192DE_DID2	0x002B	/*92DE*/
110
#define RTL_PCI_8188EE_DID	0x8179  /*8188ee*/
111 112 113 114
#define RTL_PCI_8723BE_DID	0xB723  /*8723be*/
#define RTL_PCI_8192EE_DID	0x818B	/*8192ee*/
#define RTL_PCI_8821AE_DID	0x8821	/*8821ae*/
#define RTL_PCI_8812AE_DID	0x8812	/*8812ae*/
L
Larry Finger 已提交
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139

/*8192 support 16 pages of IO registers*/
#define RTL_MEM_MAPPED_IO_RANGE_8190PCI		0x1000
#define RTL_MEM_MAPPED_IO_RANGE_8192PCIE	0x4000
#define RTL_MEM_MAPPED_IO_RANGE_8192SE		0x4000
#define RTL_MEM_MAPPED_IO_RANGE_8192CE		0x4000
#define RTL_MEM_MAPPED_IO_RANGE_8192DE		0x4000

#define RTL_PCI_REVISION_ID_8190PCI		0x00
#define RTL_PCI_REVISION_ID_8192PCIE		0x01
#define RTL_PCI_REVISION_ID_8192SE		0x10
#define RTL_PCI_REVISION_ID_8192CE		0x1
#define RTL_PCI_REVISION_ID_8192DE		0x0

#define RTL_DEFAULT_HARDWARE_TYPE	HARDWARE_TYPE_RTL8192CE

enum pci_bridge_vendor {
	PCI_BRIDGE_VENDOR_INTEL = 0x0,	/*0b'0000,0001 */
	PCI_BRIDGE_VENDOR_ATI,		/*0b'0000,0010*/
	PCI_BRIDGE_VENDOR_AMD,		/*0b'0000,0100*/
	PCI_BRIDGE_VENDOR_SIS,		/*0b'0000,1000*/
	PCI_BRIDGE_VENDOR_UNKNOWN,	/*0b'0100,0000*/
	PCI_BRIDGE_VENDOR_MAX,
};

140 141 142 143 144
struct rtl_pci_capabilities_header {
	u8 capability_id;
	u8 next;
};

145 146 147 148 149 150 151 152 153 154 155 156
/* In new TRX flow, Buffer_desc is new concept
 * But TX wifi info == TX descriptor in old flow
 * RX wifi info == RX descriptor in old flow
 */
struct rtl_tx_buffer_desc {
#if (RTL8192EE_SEG_NUM == 2)
	u32 dword[2*(DMA_IS_64BIT + 1)*8]; /*seg = 8*/
#elif (RTL8192EE_SEG_NUM == 1)
	u32 dword[2*(DMA_IS_64BIT + 1)*4]; /*seg = 4*/
#elif (RTL8192EE_SEG_NUM == 0)
	u32 dword[2*(DMA_IS_64BIT + 1)*2]; /*seg = 2*/
#endif
157
} __packed;
L
Larry Finger 已提交
158 159 160

struct rtl_tx_desc {
	u32 dword[16];
161
} __packed;
L
Larry Finger 已提交
162

163 164
struct rtl_rx_buffer_desc { /*rx buffer desc*/
	u32 dword[2];
165
} __packed;
L
Larry Finger 已提交
166

167 168 169 170 171 172
struct rtl_rx_desc { /*old: rx desc new: rx wifi info*/
	u32 dword[8];
} __packed;

struct rtl_tx_cmd_desc {
	u32 dword[16];
173 174
} __packed;

L
Larry Finger 已提交
175 176 177 178 179 180
struct rtl8192_tx_ring {
	struct rtl_tx_desc *desc;
	dma_addr_t dma;
	unsigned int idx;
	unsigned int entries;
	struct sk_buff_head queue;
181 182
	/*add for new trx flow*/
	struct rtl_tx_buffer_desc *buffer_desc; /*tx buffer descriptor*/
183 184 185 186
	dma_addr_t buffer_desc_dma; /*tx bufferd desc dma memory*/
	u16 avl_desc; /* available_desc_to_write */
	u16 cur_tx_wp; /* current_tx_write_point */
	u16 cur_tx_rp; /* current_tx_read_point */
L
Larry Finger 已提交
187 188 189 190 191 192 193
};

struct rtl8192_rx_ring {
	struct rtl_rx_desc *desc;
	dma_addr_t dma;
	unsigned int idx;
	struct sk_buff *rx_buf[RTL_PCI_MAX_RX_COUNT];
194 195 196
	/*add for new trx flow*/
	struct rtl_rx_buffer_desc *buffer_desc; /*rx buffer descriptor*/
	u16 next_rx_rp; /* next_rx_read_point */
L
Larry Finger 已提交
197 198 199 200
};

struct rtl_pci {
	struct pci_dev *pdev;
201
	bool irq_enabled;
L
Larry Finger 已提交
202 203 204

	bool driver_is_goingto_unload;
	bool up_first_time;
205
	bool first_init;
L
Larry Finger 已提交
206
	bool being_init_adapter;
207
	bool init_ready;
L
Larry Finger 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222

	/*Tx */
	struct rtl8192_tx_ring tx_ring[RTL_PCI_MAX_TX_QUEUE_COUNT];
	int txringcount[RTL_PCI_MAX_TX_QUEUE_COUNT];
	u32 transmit_config;

	/*Rx */
	struct rtl8192_rx_ring rx_ring[RTL_PCI_MAX_RX_QUEUE];
	int rxringcount;
	u16 rxbuffersize;
	u32 receive_config;

	/*irq */
	u8 irq_alloc;
	u32 irq_mask[2];
223
	u32 sys_irq_mask;
L
Larry Finger 已提交
224 225 226 227 228 229 230 231 232 233 234 235 236 237

	/*Bcn control register setting */
	u32 reg_bcn_ctrl_val;

	 /*ASPM*/ u8 const_pci_aspm;
	u8 const_amdpci_aspm;
	u8 const_hwsw_rfoff_d3;
	u8 const_support_pciaspm;
	/*pci-e bridge */
	u8 const_hostpci_aspm_setting;
	/*pci-e device */
	u8 const_devicepci_aspm_setting;
	/*If it supports ASPM, Offset[560h] = 0x40,
	   otherwise Offset[560h] = 0x00. */
238 239
	bool support_aspm;
	bool support_backdoor;
L
Larry Finger 已提交
240 241 242

	/*QOS & EDCA */
	enum acm_method acm_method;
243 244 245

	u16 shortretry_limit;
	u16 longretry_limit;
246 247 248 249

	/* MSI support */
	bool msi_support;
	bool using_msi;
250 251
	/* interrupt clear before set */
	bool int_clear;
L
Larry Finger 已提交
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
};

struct mp_adapter {
	u8 linkctrl_reg;

	u8 busnumber;
	u8 devnumber;
	u8 funcnumber;

	u8 pcibridge_busnum;
	u8 pcibridge_devnum;
	u8 pcibridge_funcnum;

	u8 pcibridge_vendor;
	u16 pcibridge_vendorid;
	u16 pcibridge_deviceid;

	u8 num4bytes;

	u8 pcibridge_pciehdr_offset;
	u8 pcibridge_linkctrlreg;

	bool amd_l1_patch;
};

struct rtl_pci_priv {
	struct rtl_pci dev;
	struct mp_adapter ndis_adapter;
	struct rtl_led_ctl ledctl;
281
	struct bt_coexist_info bt_coexist;
L
Larry Finger 已提交
282 283 284 285 286 287 288 289 290
};

#define rtl_pcipriv(hw)		(((struct rtl_pci_priv *)(rtl_priv(hw))->priv))
#define rtl_pcidev(pcipriv)	(&((pcipriv)->dev))

int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw);

extern struct rtl_intf_ops rtl_pci_ops;

B
Bill Pemberton 已提交
291
int rtl_pci_probe(struct pci_dev *pdev,
L
Larry Finger 已提交
292 293
			    const struct pci_device_id *id);
void rtl_pci_disconnect(struct pci_dev *pdev);
H
Hauke Mehrtens 已提交
294
#ifdef CONFIG_PM_SLEEP
295 296
int rtl_pci_suspend(struct device *dev);
int rtl_pci_resume(struct device *dev);
H
Hauke Mehrtens 已提交
297
#endif /* CONFIG_PM_SLEEP */
L
Larry Finger 已提交
298 299
static inline u8 pci_read8_sync(struct rtl_priv *rtlpriv, u32 addr)
{
L
Larry Finger 已提交
300
	return readb((u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
L
Larry Finger 已提交
301 302 303 304
}

static inline u16 pci_read16_sync(struct rtl_priv *rtlpriv, u32 addr)
{
L
Larry Finger 已提交
305
	return readw((u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
L
Larry Finger 已提交
306 307 308 309
}

static inline u32 pci_read32_sync(struct rtl_priv *rtlpriv, u32 addr)
{
L
Larry Finger 已提交
310
	return readl((u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
L
Larry Finger 已提交
311 312 313 314
}

static inline void pci_write8_async(struct rtl_priv *rtlpriv, u32 addr, u8 val)
{
L
Larry Finger 已提交
315
	writeb(val, (u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
L
Larry Finger 已提交
316 317 318 319 320
}

static inline void pci_write16_async(struct rtl_priv *rtlpriv,
				     u32 addr, u16 val)
{
L
Larry Finger 已提交
321
	writew(val, (u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
L
Larry Finger 已提交
322 323 324 325 326
}

static inline void pci_write32_async(struct rtl_priv *rtlpriv,
				     u32 addr, u32 val)
{
L
Larry Finger 已提交
327
	writel(val, (u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
L
Larry Finger 已提交
328 329
}

330 331 332 333 334 335 336
static inline u16 calc_fifo_space(u16 rp, u16 wp)
{
	if (rp <= wp)
		return RTL_PCI_MAX_RX_COUNT - 1 + rp - wp;
	return rp - wp - 1;
}

L
Larry Finger 已提交
337
#endif