ntb_hw_amd.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * This file is provided under a dual BSD/GPLv2 license. When using or
  3. * redistributing this file, you may do so under either license.
  4. *
  5. * GPL LICENSE SUMMARY
  6. *
  7. * Copyright (C) 2016 Advanced Micro Devices, Inc. All Rights Reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * BSD LICENSE
  14. *
  15. * Copyright (C) 2016 Advanced Micro Devices, Inc. All Rights Reserved.
  16. *
  17. * Redistribution and use in source and binary forms, with or without
  18. * modification, are permitted provided that the following conditions
  19. * are met:
  20. *
  21. * * Redistributions of source code must retain the above copyright
  22. * notice, this list of conditions and the following disclaimer.
  23. * * Redistributions in binary form must reproduce the above copy
  24. * notice, this list of conditions and the following disclaimer in
  25. * the documentation and/or other materials provided with the
  26. * distribution.
  27. * * Neither the name of AMD Corporation nor the names of its
  28. * contributors may be used to endorse or promote products derived
  29. * from this software without specific prior written permission.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  37. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  38. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  39. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  41. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. * AMD PCIe NTB Linux driver
  44. *
  45. * Contact Information:
  46. * Xiangliang Yu <Xiangliang.Yu@amd.com>
  47. */
  48. #ifndef NTB_HW_AMD_H
  49. #define NTB_HW_AMD_H
  50. #include <linux/ntb.h>
  51. #include <linux/pci.h>
  52. #define AMD_LINK_HB_TIMEOUT msecs_to_jiffies(1000)
  53. #define NTB_LNK_STA_SPEED_MASK 0x000F0000
  54. #define NTB_LNK_STA_WIDTH_MASK 0x03F00000
  55. #define NTB_LNK_STA_SPEED(x) (((x) & NTB_LNK_STA_SPEED_MASK) >> 16)
  56. #define NTB_LNK_STA_WIDTH(x) (((x) & NTB_LNK_STA_WIDTH_MASK) >> 20)
  57. #ifndef read64
  58. #ifdef readq
  59. #define read64 readq
  60. #else
  61. #define read64 _read64
  62. static inline u64 _read64(void __iomem *mmio)
  63. {
  64. u64 low, high;
  65. low = readl(mmio);
  66. high = readl(mmio + sizeof(u32));
  67. return low | (high << 32);
  68. }
  69. #endif
  70. #endif
  71. #ifndef write64
  72. #ifdef writeq
  73. #define write64 writeq
  74. #else
  75. #define write64 _write64
  76. static inline void _write64(u64 val, void __iomem *mmio)
  77. {
  78. writel(val, mmio);
  79. writel(val >> 32, mmio + sizeof(u32));
  80. }
  81. #endif
  82. #endif
  83. enum {
  84. /* AMD NTB Capability */
  85. AMD_DB_CNT = 16,
  86. AMD_MSIX_VECTOR_CNT = 24,
  87. AMD_SPADS_CNT = 16,
  88. /* AMD NTB register offset */
  89. AMD_CNTL_OFFSET = 0x200,
  90. /* NTB control register bits */
  91. PMM_REG_CTL = BIT(21),
  92. SMM_REG_CTL = BIT(20),
  93. SMM_REG_ACC_PATH = BIT(18),
  94. PMM_REG_ACC_PATH = BIT(17),
  95. NTB_CLK_EN = BIT(16),
  96. AMD_STA_OFFSET = 0x204,
  97. AMD_PGSLV_OFFSET = 0x208,
  98. AMD_SPAD_MUX_OFFSET = 0x20C,
  99. AMD_SPAD_OFFSET = 0x210,
  100. AMD_RSMU_HCID = 0x250,
  101. AMD_RSMU_SIID = 0x254,
  102. AMD_PSION_OFFSET = 0x300,
  103. AMD_SSION_OFFSET = 0x330,
  104. AMD_MMINDEX_OFFSET = 0x400,
  105. AMD_MMDATA_OFFSET = 0x404,
  106. AMD_SIDEINFO_OFFSET = 0x408,
  107. AMD_SIDE_MASK = BIT(0),
  108. AMD_SIDE_READY = BIT(1),
  109. /* limit register */
  110. AMD_ROMBARLMT_OFFSET = 0x410,
  111. AMD_BAR1LMT_OFFSET = 0x414,
  112. AMD_BAR23LMT_OFFSET = 0x418,
  113. AMD_BAR45LMT_OFFSET = 0x420,
  114. /* xlat address */
  115. AMD_POMBARXLAT_OFFSET = 0x428,
  116. AMD_BAR1XLAT_OFFSET = 0x430,
  117. AMD_BAR23XLAT_OFFSET = 0x438,
  118. AMD_BAR45XLAT_OFFSET = 0x440,
  119. /* doorbell and interrupt */
  120. AMD_DBFM_OFFSET = 0x450,
  121. AMD_DBREQ_OFFSET = 0x454,
  122. AMD_MIRRDBSTAT_OFFSET = 0x458,
  123. AMD_DBMASK_OFFSET = 0x45C,
  124. AMD_DBSTAT_OFFSET = 0x460,
  125. AMD_INTMASK_OFFSET = 0x470,
  126. AMD_INTSTAT_OFFSET = 0x474,
  127. /* event type */
  128. AMD_PEER_FLUSH_EVENT = BIT(0),
  129. AMD_PEER_RESET_EVENT = BIT(1),
  130. AMD_PEER_D3_EVENT = BIT(2),
  131. AMD_PEER_PMETO_EVENT = BIT(3),
  132. AMD_PEER_D0_EVENT = BIT(4),
  133. AMD_LINK_UP_EVENT = BIT(5),
  134. AMD_LINK_DOWN_EVENT = BIT(6),
  135. AMD_EVENT_INTMASK = (AMD_PEER_FLUSH_EVENT |
  136. AMD_PEER_RESET_EVENT | AMD_PEER_D3_EVENT |
  137. AMD_PEER_PMETO_EVENT | AMD_PEER_D0_EVENT |
  138. AMD_LINK_UP_EVENT | AMD_LINK_DOWN_EVENT),
  139. AMD_PMESTAT_OFFSET = 0x480,
  140. AMD_PMSGTRIG_OFFSET = 0x490,
  141. AMD_LTRLATENCY_OFFSET = 0x494,
  142. AMD_FLUSHTRIG_OFFSET = 0x498,
  143. /* SMU register*/
  144. AMD_SMUACK_OFFSET = 0x4A0,
  145. AMD_SINRST_OFFSET = 0x4A4,
  146. AMD_RSPNUM_OFFSET = 0x4A8,
  147. AMD_SMU_SPADMUTEX = 0x4B0,
  148. AMD_SMU_SPADOFFSET = 0x4B4,
  149. AMD_PEER_OFFSET = 0x400,
  150. };
  151. struct ntb_dev_data {
  152. const unsigned char mw_count;
  153. const unsigned int mw_idx;
  154. const bool is_endpoint;
  155. };
  156. struct amd_ntb_dev;
  157. struct amd_ntb_vec {
  158. struct amd_ntb_dev *ndev;
  159. int num;
  160. };
  161. struct amd_ntb_dev {
  162. struct ntb_dev ntb;
  163. u32 ntb_side;
  164. u32 lnk_sta;
  165. u32 cntl_sta;
  166. u32 peer_sta;
  167. struct ntb_dev_data *dev_data;
  168. unsigned char mw_count;
  169. unsigned char spad_count;
  170. unsigned char db_count;
  171. unsigned char msix_vec_count;
  172. u64 db_valid_mask;
  173. u64 db_mask;
  174. u64 db_last_bit;
  175. u32 int_mask;
  176. struct msix_entry *msix;
  177. struct amd_ntb_vec *vec;
  178. /* synchronize rmw access of db_mask and hw reg */
  179. spinlock_t db_mask_lock;
  180. void __iomem *self_mmio;
  181. void __iomem *peer_mmio;
  182. unsigned int self_spad;
  183. unsigned int peer_spad;
  184. struct delayed_work hb_timer;
  185. struct dentry *debugfs_dir;
  186. struct dentry *debugfs_info;
  187. };
  188. #define ntb_ndev(__ntb) container_of(__ntb, struct amd_ntb_dev, ntb)
  189. #define hb_ndev(__work) container_of(__work, struct amd_ntb_dev, hb_timer.work)
  190. static void amd_set_side_info_reg(struct amd_ntb_dev *ndev, bool peer);
  191. static void amd_clear_side_info_reg(struct amd_ntb_dev *ndev, bool peer);
  192. static int amd_poll_link(struct amd_ntb_dev *ndev);
  193. #endif