pci.h 8.2 KB

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