pci.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2009-2010 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. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * wlanfae <wlanfae@realtek.com>
  23. * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
  24. * Hsinchu 300, Taiwan.
  25. *
  26. * Larry Finger <Larry.Finger@lwfinger.net>
  27. *
  28. *****************************************************************************/
  29. #ifndef __RTL_PCI_H__
  30. #define __RTL_PCI_H__
  31. #include <linux/pci.h>
  32. /*
  33. 1: MSDU packet queue,
  34. 2: Rx Command Queue
  35. */
  36. #define RTL_PCI_RX_MPDU_QUEUE 0
  37. #define RTL_PCI_RX_CMD_QUEUE 1
  38. #define RTL_PCI_MAX_RX_QUEUE 2
  39. #define RTL_PCI_MAX_RX_COUNT 64
  40. #define RTL_PCI_MAX_TX_QUEUE_COUNT 9
  41. #define RT_TXDESC_NUM 128
  42. #define RT_TXDESC_NUM_BE_QUEUE 256
  43. #define BK_QUEUE 0
  44. #define BE_QUEUE 1
  45. #define VI_QUEUE 2
  46. #define VO_QUEUE 3
  47. #define BEACON_QUEUE 4
  48. #define TXCMD_QUEUE 5
  49. #define MGNT_QUEUE 6
  50. #define HIGH_QUEUE 7
  51. #define HCCA_QUEUE 8
  52. #define RTL_PCI_DEVICE(vend, dev, cfg) \
  53. .vendor = (vend), \
  54. .device = (dev), \
  55. .subvendor = PCI_ANY_ID, \
  56. .subdevice = PCI_ANY_ID,\
  57. .driver_data = (kernel_ulong_t)&(cfg)
  58. #define INTEL_VENDOR_ID 0x8086
  59. #define SIS_VENDOR_ID 0x1039
  60. #define ATI_VENDOR_ID 0x1002
  61. #define ATI_DEVICE_ID 0x7914
  62. #define AMD_VENDOR_ID 0x1022
  63. #define PCI_MAX_BRIDGE_NUMBER 255
  64. #define PCI_MAX_DEVICES 32
  65. #define PCI_MAX_FUNCTION 8
  66. #define PCI_CONF_ADDRESS 0x0CF8 /*PCI Configuration Space Address */
  67. #define PCI_CONF_DATA 0x0CFC /*PCI Configuration Space Data */
  68. #define PCI_CLASS_BRIDGE_DEV 0x06
  69. #define PCI_SUBCLASS_BR_PCI_TO_PCI 0x04
  70. #define PCI_CAPABILITY_ID_PCI_EXPRESS 0x10
  71. #define PCI_CAP_ID_EXP 0x10
  72. #define U1DONTCARE 0xFF
  73. #define U2DONTCARE 0xFFFF
  74. #define U4DONTCARE 0xFFFFFFFF
  75. #define RTL_PCI_8192_DID 0x8192 /*8192 PCI-E */
  76. #define RTL_PCI_8192SE_DID 0x8192 /*8192 SE */
  77. #define RTL_PCI_8174_DID 0x8174 /*8192 SE */
  78. #define RTL_PCI_8173_DID 0x8173 /*8191 SE Crab */
  79. #define RTL_PCI_8172_DID 0x8172 /*8191 SE RE */
  80. #define RTL_PCI_8171_DID 0x8171 /*8191 SE Unicron */
  81. #define RTL_PCI_0045_DID 0x0045 /*8190 PCI for Ceraga */
  82. #define RTL_PCI_0046_DID 0x0046 /*8190 Cardbus for Ceraga */
  83. #define RTL_PCI_0044_DID 0x0044 /*8192e PCIE for Ceraga */
  84. #define RTL_PCI_0047_DID 0x0047 /*8192e Express Card for Ceraga */
  85. #define RTL_PCI_700F_DID 0x700F
  86. #define RTL_PCI_701F_DID 0x701F
  87. #define RTL_PCI_DLINK_DID 0x3304
  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 0x092D /*8192ce */
  94. #define RTL_PCI_8192DU_DID 0x092D /*8192ce */
  95. /*8192 support 16 pages of IO registers*/
  96. #define RTL_MEM_MAPPED_IO_RANGE_8190PCI 0x1000
  97. #define RTL_MEM_MAPPED_IO_RANGE_8192PCIE 0x4000
  98. #define RTL_MEM_MAPPED_IO_RANGE_8192SE 0x4000
  99. #define RTL_MEM_MAPPED_IO_RANGE_8192CE 0x4000
  100. #define RTL_MEM_MAPPED_IO_RANGE_8192DE 0x4000
  101. #define RTL_PCI_REVISION_ID_8190PCI 0x00
  102. #define RTL_PCI_REVISION_ID_8192PCIE 0x01
  103. #define RTL_PCI_REVISION_ID_8192SE 0x10
  104. #define RTL_PCI_REVISION_ID_8192CE 0x1
  105. #define RTL_PCI_REVISION_ID_8192DE 0x0
  106. #define RTL_DEFAULT_HARDWARE_TYPE HARDWARE_TYPE_RTL8192CE
  107. enum pci_bridge_vendor {
  108. PCI_BRIDGE_VENDOR_INTEL = 0x0, /*0b'0000,0001 */
  109. PCI_BRIDGE_VENDOR_ATI, /*0b'0000,0010*/
  110. PCI_BRIDGE_VENDOR_AMD, /*0b'0000,0100*/
  111. PCI_BRIDGE_VENDOR_SIS, /*0b'0000,1000*/
  112. PCI_BRIDGE_VENDOR_UNKNOWN, /*0b'0100,0000*/
  113. PCI_BRIDGE_VENDOR_MAX,
  114. };
  115. struct rtl_rx_desc {
  116. u32 dword[8];
  117. } __packed;
  118. struct rtl_tx_desc {
  119. u32 dword[16];
  120. } __packed;
  121. struct rtl_tx_cmd_desc {
  122. u32 dword[16];
  123. } __packed;
  124. struct rtl8192_tx_ring {
  125. struct rtl_tx_desc *desc;
  126. dma_addr_t dma;
  127. unsigned int idx;
  128. unsigned int entries;
  129. struct sk_buff_head queue;
  130. };
  131. struct rtl8192_rx_ring {
  132. struct rtl_rx_desc *desc;
  133. dma_addr_t dma;
  134. unsigned int idx;
  135. struct sk_buff *rx_buf[RTL_PCI_MAX_RX_COUNT];
  136. };
  137. struct rtl_pci {
  138. struct pci_dev *pdev;
  139. bool driver_is_goingto_unload;
  140. bool up_first_time;
  141. bool being_init_adapter;
  142. bool irq_enabled;
  143. /*Tx */
  144. struct rtl8192_tx_ring tx_ring[RTL_PCI_MAX_TX_QUEUE_COUNT];
  145. int txringcount[RTL_PCI_MAX_TX_QUEUE_COUNT];
  146. u32 transmit_config;
  147. /*Rx */
  148. struct rtl8192_rx_ring rx_ring[RTL_PCI_MAX_RX_QUEUE];
  149. int rxringcount;
  150. u16 rxbuffersize;
  151. u32 receive_config;
  152. /*irq */
  153. u8 irq_alloc;
  154. u32 irq_mask[2];
  155. /*Bcn control register setting */
  156. u32 reg_bcn_ctrl_val;
  157. /*ASPM*/ u8 const_pci_aspm;
  158. u8 const_amdpci_aspm;
  159. u8 const_hwsw_rfoff_d3;
  160. u8 const_support_pciaspm;
  161. /*pci-e bridge */
  162. u8 const_hostpci_aspm_setting;
  163. /*pci-e device */
  164. u8 const_devicepci_aspm_setting;
  165. /*If it supports ASPM, Offset[560h] = 0x40,
  166. otherwise Offset[560h] = 0x00. */
  167. bool b_support_aspm;
  168. bool b_support_backdoor;
  169. /*QOS & EDCA */
  170. enum acm_method acm_method;
  171. };
  172. struct mp_adapter {
  173. u8 linkctrl_reg;
  174. u8 busnumber;
  175. u8 devnumber;
  176. u8 funcnumber;
  177. u8 pcibridge_busnum;
  178. u8 pcibridge_devnum;
  179. u8 pcibridge_funcnum;
  180. u8 pcibridge_vendor;
  181. u16 pcibridge_vendorid;
  182. u16 pcibridge_deviceid;
  183. u32 pcicfg_addrport;
  184. u8 num4bytes;
  185. u8 pcibridge_pciehdr_offset;
  186. u8 pcibridge_linkctrlreg;
  187. bool amd_l1_patch;
  188. };
  189. struct rtl_pci_priv {
  190. struct rtl_pci dev;
  191. struct mp_adapter ndis_adapter;
  192. struct rtl_led_ctl ledctl;
  193. };
  194. #define rtl_pcipriv(hw) (((struct rtl_pci_priv *)(rtl_priv(hw))->priv))
  195. #define rtl_pcidev(pcipriv) (&((pcipriv)->dev))
  196. int rtl_pci_reset_trx_ring(struct ieee80211_hw *hw);
  197. extern struct rtl_intf_ops rtl_pci_ops;
  198. int __devinit rtl_pci_probe(struct pci_dev *pdev,
  199. const struct pci_device_id *id);
  200. void rtl_pci_disconnect(struct pci_dev *pdev);
  201. int rtl_pci_suspend(struct pci_dev *pdev, pm_message_t state);
  202. int rtl_pci_resume(struct pci_dev *pdev);
  203. static inline u8 pci_read8_sync(struct rtl_priv *rtlpriv, u32 addr)
  204. {
  205. return readb((u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
  206. }
  207. static inline u16 pci_read16_sync(struct rtl_priv *rtlpriv, u32 addr)
  208. {
  209. return readw((u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
  210. }
  211. static inline u32 pci_read32_sync(struct rtl_priv *rtlpriv, u32 addr)
  212. {
  213. return readl((u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
  214. }
  215. static inline void pci_write8_async(struct rtl_priv *rtlpriv, u32 addr, u8 val)
  216. {
  217. writeb(val, (u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
  218. }
  219. static inline void pci_write16_async(struct rtl_priv *rtlpriv,
  220. u32 addr, u16 val)
  221. {
  222. writew(val, (u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
  223. }
  224. static inline void pci_write32_async(struct rtl_priv *rtlpriv,
  225. u32 addr, u32 val)
  226. {
  227. writel(val, (u8 __iomem *) rtlpriv->io.pci_mem_start + addr);
  228. }
  229. static inline void rtl_pci_raw_write_port_ulong(u32 port, u32 val)
  230. {
  231. outl(val, port);
  232. }
  233. static inline void rtl_pci_raw_write_port_uchar(u32 port, u8 val)
  234. {
  235. outb(val, port);
  236. }
  237. static inline void rtl_pci_raw_read_port_uchar(u32 port, u8 *pval)
  238. {
  239. *pval = inb(port);
  240. }
  241. static inline void rtl_pci_raw_read_port_ushort(u32 port, u16 *pval)
  242. {
  243. *pval = inw(port);
  244. }
  245. static inline void rtl_pci_raw_read_port_ulong(u32 port, u32 *pval)
  246. {
  247. *pval = inl(port);
  248. }
  249. #endif