pci.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2012 Realtek Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * The full GNU General Public License is included in this distribution in the
  15. * file called LICENSE.
  16. *
  17. * Contact Information:
  18. * wlanfae <wlanfae@realtek.com>
  19. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  20. * Hsinchu 300, Taiwan.
  21. *
  22. * Larry Finger <Larry.Finger@lwfinger.net>
  23. *
  24. *****************************************************************************/
  25. #ifndef __RTL_PCI_H__
  26. #define __RTL_PCI_H__
  27. #include <linux/pci.h>
  28. /* 1: MSDU packet queue,
  29. * 2: Rx Command Queue
  30. */
  31. #define RTL_PCI_RX_MPDU_QUEUE 0
  32. #define RTL_PCI_RX_CMD_QUEUE 1
  33. #define RTL_PCI_MAX_RX_QUEUE 2
  34. #define RTL_PCI_MAX_RX_COUNT 512/*64*/
  35. #define RTL_PCI_MAX_TX_QUEUE_COUNT 9
  36. #define RT_TXDESC_NUM 128
  37. #define TX_DESC_NUM_92E 512
  38. #define TX_DESC_NUM_8822B 512
  39. #define RT_TXDESC_NUM_BE_QUEUE 256
  40. #define BK_QUEUE 0
  41. #define BE_QUEUE 1
  42. #define VI_QUEUE 2
  43. #define VO_QUEUE 3
  44. #define BEACON_QUEUE 4
  45. #define TXCMD_QUEUE 5
  46. #define MGNT_QUEUE 6
  47. #define HIGH_QUEUE 7
  48. #define HCCA_QUEUE 8
  49. #define H2C_QUEUE TXCMD_QUEUE /* In 8822B */
  50. #define RTL_PCI_DEVICE(vend, dev, cfg) \
  51. .vendor = (vend), \
  52. .device = (dev), \
  53. .subvendor = PCI_ANY_ID, \
  54. .subdevice = PCI_ANY_ID,\
  55. .driver_data = (kernel_ulong_t)&(cfg)
  56. #define INTEL_VENDOR_ID 0x8086
  57. #define SIS_VENDOR_ID 0x1039
  58. #define ATI_VENDOR_ID 0x1002
  59. #define ATI_DEVICE_ID 0x7914
  60. #define AMD_VENDOR_ID 0x1022
  61. #define PCI_MAX_BRIDGE_NUMBER 255
  62. #define PCI_MAX_DEVICES 32
  63. #define PCI_MAX_FUNCTION 8
  64. #define PCI_CONF_ADDRESS 0x0CF8 /*PCI Configuration Space Address */
  65. #define PCI_CONF_DATA 0x0CFC /*PCI Configuration Space Data */
  66. #define PCI_CLASS_BRIDGE_DEV 0x06
  67. #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
  68. #define PCI_CAPABILITY_ID_PCI_EXPRESS 0x10
  69. #define PCI_CAP_ID_EXP 0x10
  70. #define U1DONTCARE 0xFF
  71. #define U2DONTCARE 0xFFFF
  72. #define U4DONTCARE 0xFFFFFFFF
  73. #define RTL_PCI_8192_DID 0x8192 /*8192 PCI-E */
  74. #define RTL_PCI_8192SE_DID 0x8192 /*8192 SE */
  75. #define RTL_PCI_8174_DID 0x8174 /*8192 SE */
  76. #define RTL_PCI_8173_DID 0x8173 /*8191 SE Crab */
  77. #define RTL_PCI_8172_DID 0x8172 /*8191 SE RE */
  78. #define RTL_PCI_8171_DID 0x8171 /*8191 SE Unicron */
  79. #define RTL_PCI_8723AE_DID 0x8723 /*8723AE */
  80. #define RTL_PCI_0045_DID 0x0045 /*8190 PCI for Ceraga */
  81. #define RTL_PCI_0046_DID 0x0046 /*8190 Cardbus for Ceraga */
  82. #define RTL_PCI_0044_DID 0x0044 /*8192e PCIE for Ceraga */
  83. #define RTL_PCI_0047_DID 0x0047 /*8192e Express Card for Ceraga */
  84. #define RTL_PCI_700F_DID 0x700F
  85. #define RTL_PCI_701F_DID 0x701F
  86. #define RTL_PCI_DLINK_DID 0x3304
  87. #define RTL_PCI_8723AE_DID 0x8723 /*8723e */
  88. #define RTL_PCI_8192CET_DID 0x8191 /*8192ce */
  89. #define RTL_PCI_8192CE_DID 0x8178 /*8192ce */
  90. #define RTL_PCI_8191CE_DID 0x8177 /*8192ce */
  91. #define RTL_PCI_8188CE_DID 0x8176 /*8192ce */
  92. #define RTL_PCI_8192CU_DID 0x8191 /*8192ce */
  93. #define RTL_PCI_8192DE_DID 0x8193 /*8192de */
  94. #define RTL_PCI_8192DE_DID2 0x002B /*92DE*/
  95. #define RTL_PCI_8188EE_DID 0x8179 /*8188ee*/
  96. #define RTL_PCI_8723BE_DID 0xB723 /*8723be*/
  97. #define RTL_PCI_8192EE_DID 0x818B /*8192ee*/
  98. #define RTL_PCI_8821AE_DID 0x8821 /*8821ae*/
  99. #define RTL_PCI_8812AE_DID 0x8812 /*8812ae*/
  100. #define RTL_PCI_8822BE_DID 0xB822 /*8822be*/
  101. /*8192 support 16 pages of IO registers*/
  102. #define RTL_MEM_MAPPED_IO_RANGE_8190PCI 0x1000
  103. #define RTL_MEM_MAPPED_IO_RANGE_8192PCIE 0x4000
  104. #define RTL_MEM_MAPPED_IO_RANGE_8192SE 0x4000
  105. #define RTL_MEM_MAPPED_IO_RANGE_8192CE 0x4000
  106. #define RTL_MEM_MAPPED_IO_RANGE_8192DE 0x4000
  107. #define RTL_PCI_REVISION_ID_8190PCI 0x00
  108. #define RTL_PCI_REVISION_ID_8192PCIE 0x01
  109. #define RTL_PCI_REVISION_ID_8192SE 0x10
  110. #define RTL_PCI_REVISION_ID_8192CE 0x1
  111. #define RTL_PCI_REVISION_ID_8192DE 0x0
  112. #define RTL_DEFAULT_HARDWARE_TYPE HARDWARE_TYPE_RTL8192CE
  113. enum pci_bridge_vendor {
  114. PCI_BRIDGE_VENDOR_INTEL = 0x0, /*0b'0000,0001 */
  115. PCI_BRIDGE_VENDOR_ATI, /*0b'0000,0010*/
  116. PCI_BRIDGE_VENDOR_AMD, /*0b'0000,0100*/
  117. PCI_BRIDGE_VENDOR_SIS, /*0b'0000,1000*/
  118. PCI_BRIDGE_VENDOR_UNKNOWN, /*0b'0100,0000*/
  119. PCI_BRIDGE_VENDOR_MAX,
  120. };
  121. struct rtl_pci_capabilities_header {
  122. u8 capability_id;
  123. u8 next;
  124. };
  125. /* In new TRX flow, Buffer_desc is new concept
  126. * But TX wifi info == TX descriptor in old flow
  127. * RX wifi info == RX descriptor in old flow
  128. */
  129. struct rtl_tx_buffer_desc {
  130. u32 dword[4 * (1 << (BUFDESC_SEG_NUM + 1))];
  131. } __packed;
  132. struct rtl_tx_desc {
  133. u32 dword[16];
  134. } __packed;
  135. struct rtl_rx_buffer_desc { /*rx buffer desc*/
  136. u32 dword[4];
  137. } __packed;
  138. struct rtl_rx_desc { /*old: rx desc new: rx wifi info*/
  139. u32 dword[8];
  140. } __packed;
  141. struct rtl_tx_cmd_desc {
  142. u32 dword[16];
  143. } __packed;
  144. struct rtl8192_tx_ring {
  145. struct rtl_tx_desc *desc;
  146. dma_addr_t dma;
  147. unsigned int idx;
  148. unsigned int entries;
  149. struct sk_buff_head queue;
  150. /*add for new trx flow*/
  151. struct rtl_tx_buffer_desc *buffer_desc; /*tx buffer descriptor*/
  152. dma_addr_t buffer_desc_dma; /*tx bufferd desc dma memory*/
  153. u16 cur_tx_wp; /* current_tx_write_point */
  154. u16 cur_tx_rp; /* current_tx_read_point */
  155. };
  156. struct rtl8192_rx_ring {
  157. struct rtl_rx_desc *desc;
  158. dma_addr_t dma;
  159. unsigned int idx;
  160. struct sk_buff *rx_buf[RTL_PCI_MAX_RX_COUNT];
  161. /*add for new trx flow*/
  162. struct rtl_rx_buffer_desc *buffer_desc; /*rx buffer descriptor*/
  163. u16 next_rx_rp; /* next_rx_read_point */
  164. };
  165. struct rtl_pci {
  166. struct pci_dev *pdev;
  167. bool irq_enabled;
  168. bool driver_is_goingto_unload;
  169. bool up_first_time;
  170. bool first_init;
  171. bool being_init_adapter;
  172. bool init_ready;
  173. /*Tx */
  174. struct rtl8192_tx_ring tx_ring[RTL_PCI_MAX_TX_QUEUE_COUNT];
  175. int txringcount[RTL_PCI_MAX_TX_QUEUE_COUNT];
  176. u32 transmit_config;
  177. /*Rx */
  178. struct rtl8192_rx_ring rx_ring[RTL_PCI_MAX_RX_QUEUE];
  179. int rxringcount;
  180. u16 rxbuffersize;
  181. u32 receive_config;
  182. /*irq */
  183. u8 irq_alloc;
  184. u32 irq_mask[4]; /* 0-1: normal, 2: unused, 3: h2c */
  185. u32 sys_irq_mask;
  186. /*Bcn control register setting */
  187. u32 reg_bcn_ctrl_val;
  188. /*ASPM*/ u8 const_pci_aspm;
  189. u8 const_amdpci_aspm;
  190. u8 const_hwsw_rfoff_d3;
  191. u8 const_support_pciaspm;
  192. /*pci-e bridge */
  193. u8 const_hostpci_aspm_setting;
  194. /*pci-e device */
  195. u8 const_devicepci_aspm_setting;
  196. /* If it supports ASPM, Offset[560h] = 0x40,
  197. * otherwise Offset[560h] = 0x00.
  198. */
  199. bool support_aspm;
  200. bool support_backdoor;
  201. /*QOS & EDCA */
  202. enum acm_method acm_method;
  203. u16 shortretry_limit;
  204. u16 longretry_limit;
  205. /* MSI support */
  206. bool msi_support;
  207. bool using_msi;
  208. /* interrupt clear before set */
  209. bool int_clear;
  210. };
  211. struct mp_adapter {
  212. u8 linkctrl_reg;
  213. u8 busnumber;
  214. u8 devnumber;
  215. u8 funcnumber;
  216. u8 pcibridge_busnum;
  217. u8 pcibridge_devnum;
  218. u8 pcibridge_funcnum;
  219. u8 pcibridge_vendor;
  220. u16 pcibridge_vendorid;
  221. u16 pcibridge_deviceid;
  222. u8 num4bytes;
  223. u8 pcibridge_pciehdr_offset;
  224. u8 pcibridge_linkctrlreg;
  225. bool amd_l1_patch;
  226. };
  227. struct rtl_pci_priv {
  228. struct bt_coexist_info bt_coexist;
  229. struct rtl_led_ctl ledctl;
  230. struct rtl_pci dev;
  231. struct mp_adapter ndis_adapter;
  232. };
  233. #define rtl_pcipriv(hw) (((struct rtl_pci_priv *)(rtl_priv(hw))->priv))
  234. #define rtl_pcidev(pcipriv) (&((pcipriv)->dev))
  235. int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw);
  236. extern const struct rtl_intf_ops rtl_pci_ops;
  237. int rtl_pci_probe(struct pci_dev *pdev,
  238. const struct pci_device_id *id);
  239. void rtl_pci_disconnect(struct pci_dev *pdev);
  240. #ifdef CONFIG_PM_SLEEP
  241. int rtl_pci_suspend(struct device *dev);
  242. int rtl_pci_resume(struct device *dev);
  243. #endif /* CONFIG_PM_SLEEP */
  244. static inline u8 pci_read8_sync(struct rtl_priv *rtlpriv, u32 addr)
  245. {
  246. return readb((u8 __iomem *)rtlpriv->io.pci_mem_start + addr);
  247. }
  248. static inline u16 pci_read16_sync(struct rtl_priv *rtlpriv, u32 addr)
  249. {
  250. return readw((u8 __iomem *)rtlpriv->io.pci_mem_start + addr);
  251. }
  252. static inline u32 pci_read32_sync(struct rtl_priv *rtlpriv, u32 addr)
  253. {
  254. return readl((u8 __iomem *)rtlpriv->io.pci_mem_start + addr);
  255. }
  256. static inline void pci_write8_async(struct rtl_priv *rtlpriv, u32 addr, u8 val)
  257. {
  258. writeb(val, (u8 __iomem *)rtlpriv->io.pci_mem_start + addr);
  259. }
  260. static inline void pci_write16_async(struct rtl_priv *rtlpriv,
  261. u32 addr, u16 val)
  262. {
  263. writew(val, (u8 __iomem *)rtlpriv->io.pci_mem_start + addr);
  264. }
  265. static inline void pci_write32_async(struct rtl_priv *rtlpriv,
  266. u32 addr, u32 val)
  267. {
  268. writel(val, (u8 __iomem *)rtlpriv->io.pci_mem_start + addr);
  269. }
  270. static inline u16 calc_fifo_space(u16 rp, u16 wp, u16 size)
  271. {
  272. if (rp <= wp)
  273. return size - 1 + rp - wp;
  274. return rp - wp - 1;
  275. }
  276. #endif