pci.h 7.9 KB

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