pci.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /* SPDX-License-Identifier: BSD-3-Clause-Clear */
  2. /*
  3. * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
  4. * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
  5. */
  6. #ifndef ATH12K_PCI_H
  7. #define ATH12K_PCI_H
  8. #include <linux/mhi.h>
  9. #include <linux/pci.h>
  10. #include "core.h"
  11. #define PCIE_SOC_GLOBAL_RESET 0x3008
  12. #define PCIE_SOC_GLOBAL_RESET_V 1
  13. #define WLAON_WARM_SW_ENTRY 0x1f80504
  14. #define WLAON_SOC_RESET_CAUSE_REG 0x01f8060c
  15. #define PCIE_Q6_COOKIE_ADDR 0x01f80500
  16. #define PCIE_Q6_COOKIE_DATA 0xc0000000
  17. /* register to wake the UMAC from power collapse */
  18. #define PCIE_SCRATCH_0_SOC_PCIE_REG 0x4040
  19. /* register used for handshake mechanism to validate UMAC is awake */
  20. #define PCIE_SOC_WAKE_PCIE_LOCAL_REG 0x3004
  21. #define PCIE_PCIE_PARF_LTSSM 0x1e081b0
  22. #define PARM_LTSSM_VALUE 0x111
  23. #define GCC_GCC_PCIE_HOT_RST(ab) \
  24. ((ab)->hal.regs->gcc_gcc_pcie_hot_rst)
  25. #define GCC_GCC_PCIE_HOT_RST_VAL 0x10
  26. #define PCIE_PCIE_INT_ALL_CLEAR 0x1e08228
  27. #define PCIE_SMLH_REQ_RST_LINK_DOWN 0x2
  28. #define PCIE_INT_CLEAR_ALL 0xffffffff
  29. #define PCIE_QSERDES_COM_SYSCLK_EN_SEL_REG(ab) \
  30. ((ab)->hal.regs->pcie_qserdes_sysclk_en_sel)
  31. #define PCIE_QSERDES_COM_SYSCLK_EN_SEL_VAL 0x10
  32. #define PCIE_QSERDES_COM_SYSCLK_EN_SEL_MSK 0xffffffff
  33. #define PCIE_PCS_OSC_DTCT_CONFIG1_REG(ab) \
  34. ((ab)->hal.regs->pcie_pcs_osc_dtct_config_base)
  35. #define PCIE_PCS_OSC_DTCT_CONFIG1_VAL 0x02
  36. #define PCIE_PCS_OSC_DTCT_CONFIG2_REG(ab) \
  37. ((ab)->hal.regs->pcie_pcs_osc_dtct_config_base + 0x4)
  38. #define PCIE_PCS_OSC_DTCT_CONFIG2_VAL 0x52
  39. #define PCIE_PCS_OSC_DTCT_CONFIG4_REG(ab) \
  40. ((ab)->hal.regs->pcie_pcs_osc_dtct_config_base + 0xc)
  41. #define PCIE_PCS_OSC_DTCT_CONFIG4_VAL 0xff
  42. #define PCIE_PCS_OSC_DTCT_CONFIG_MSK 0x000000ff
  43. #define WLAON_QFPROM_PWR_CTRL_REG 0x01f8031c
  44. #define QFPROM_PWR_CTRL_VDD4BLOW_MASK 0x4
  45. #define QCN9274_QFPROM_RAW_RFA_PDET_ROW13_LSB 0x1E20338
  46. #define OTP_BOARD_ID_MASK GENMASK(15, 0)
  47. #define PCIE_LOCAL_REG_QRTR_NODE_ID(ab) \
  48. ((ab)->hal.regs->qrtr_node_id)
  49. #define DOMAIN_NUMBER_MASK GENMASK(7, 4)
  50. #define BUS_NUMBER_MASK GENMASK(3, 0)
  51. #define PCI_BAR_WINDOW0_BASE 0x1E00000
  52. #define PCI_BAR_WINDOW0_END 0x1E7FFFC
  53. #define PCI_SOC_RANGE_MASK 0x3FFF
  54. #define PCI_SOC_PCI_REG_BASE 0x1E04000
  55. #define PCI_SOC_PCI_REG_END 0x1E07FFC
  56. #define PCI_PARF_BASE 0x1E08000
  57. #define PCI_PARF_END 0x1E0BFFC
  58. #define PCI_MHIREGLEN_REG 0x1E0E100
  59. #define PCI_MHI_REGION_END 0x1E0EFFC
  60. #define QRTR_PCI_DOMAIN_NR_MASK GENMASK(7, 4)
  61. #define QRTR_PCI_BUS_NUMBER_MASK GENMASK(3, 0)
  62. struct ath12k_msi_user {
  63. const char *name;
  64. int num_vectors;
  65. u32 base_vector;
  66. };
  67. struct ath12k_msi_config {
  68. int total_vectors;
  69. int total_users;
  70. const struct ath12k_msi_user *users;
  71. };
  72. enum ath12k_pci_flags {
  73. ATH12K_PCI_FLAG_INIT_DONE,
  74. ATH12K_PCI_FLAG_IS_MSI_64,
  75. ATH12K_PCI_ASPM_RESTORE,
  76. ATH12K_PCI_FLAG_MULTI_MSI_VECTORS,
  77. };
  78. struct ath12k_pci_ops {
  79. int (*wakeup)(struct ath12k_base *ab);
  80. void (*release)(struct ath12k_base *ab);
  81. };
  82. struct ath12k_pci_device_family_ops {
  83. int (*probe)(struct pci_dev *pdev, const struct pci_device_id *pci_dev);
  84. int (*arch_init)(struct ath12k_base *ab);
  85. void (*arch_deinit)(struct ath12k_base *ab);
  86. };
  87. struct ath12k_pci_reg_base {
  88. u32 umac_base;
  89. u32 ce_reg_base;
  90. };
  91. struct ath12k_pci {
  92. struct pci_dev *pdev;
  93. struct ath12k_base *ab;
  94. u16 dev_id;
  95. char amss_path[100];
  96. u32 msi_ep_base_data;
  97. struct mhi_controller *mhi_ctrl;
  98. const struct ath12k_msi_config *msi_config;
  99. unsigned long mhi_state;
  100. enum mhi_callback mhi_pre_cb;
  101. u32 register_window;
  102. /* protects register_window above */
  103. spinlock_t window_lock;
  104. /* enum ath12k_pci_flags */
  105. unsigned long flags;
  106. u16 link_ctl;
  107. unsigned long irq_flags;
  108. const struct ath12k_pci_ops *pci_ops;
  109. u32 qmi_instance;
  110. u64 dma_mask;
  111. const struct ath12k_pci_device_family_ops *device_family_ops;
  112. const struct ath12k_pci_reg_base *reg_base;
  113. u32 window_reg_addr;
  114. };
  115. struct ath12k_pci_driver {
  116. const char *name;
  117. const struct pci_device_id *id_table;
  118. struct ath12k_pci_device_family_ops ops;
  119. struct pci_driver driver;
  120. const struct ath12k_pci_reg_base *reg_base;
  121. };
  122. static inline struct ath12k_pci *ath12k_pci_priv(struct ath12k_base *ab)
  123. {
  124. return (struct ath12k_pci *)ab->drv_priv;
  125. }
  126. int ath12k_pci_get_user_msi_assignment(struct ath12k_base *ab, char *user_name,
  127. int *num_vectors, u32 *user_base_data,
  128. u32 *base_vector);
  129. int ath12k_pci_get_msi_irq(struct device *dev, unsigned int vector);
  130. void ath12k_pci_write32(struct ath12k_base *ab, u32 offset, u32 value);
  131. u32 ath12k_pci_read32(struct ath12k_base *ab, u32 offset);
  132. int ath12k_pci_map_service_to_pipe(struct ath12k_base *ab, u16 service_id,
  133. u8 *ul_pipe, u8 *dl_pipe);
  134. void ath12k_pci_get_msi_address(struct ath12k_base *ab, u32 *msi_addr_lo,
  135. u32 *msi_addr_hi);
  136. void ath12k_pci_get_ce_msi_idx(struct ath12k_base *ab, u32 ce_id,
  137. u32 *msi_idx);
  138. void ath12k_pci_hif_ce_irq_enable(struct ath12k_base *ab);
  139. void ath12k_pci_hif_ce_irq_disable(struct ath12k_base *ab);
  140. void ath12k_pci_ext_irq_enable(struct ath12k_base *ab);
  141. void ath12k_pci_ext_irq_disable(struct ath12k_base *ab);
  142. int ath12k_pci_hif_suspend(struct ath12k_base *ab);
  143. int ath12k_pci_hif_resume(struct ath12k_base *ab);
  144. void ath12k_pci_stop(struct ath12k_base *ab);
  145. int ath12k_pci_start(struct ath12k_base *ab);
  146. int ath12k_pci_power_up(struct ath12k_base *ab);
  147. void ath12k_pci_power_down(struct ath12k_base *ab, bool is_suspend);
  148. int ath12k_pci_register_driver(const enum ath12k_device_family device_id,
  149. struct ath12k_pci_driver *driver);
  150. void ath12k_pci_unregister_driver(const enum ath12k_device_family device_id);
  151. #endif /* ATH12K_PCI_H */