ntb_hw_intel.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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) 2012 Intel Corporation. All rights reserved.
  8. * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of version 2 of the GNU General Public License as
  12. * published by the Free Software Foundation.
  13. *
  14. * BSD LICENSE
  15. *
  16. * Copyright(c) 2012 Intel Corporation. All rights reserved.
  17. * Copyright (C) 2015 EMC Corporation. All Rights Reserved.
  18. *
  19. * Redistribution and use in source and binary forms, with or without
  20. * modification, are permitted provided that the following conditions
  21. * are met:
  22. *
  23. * * Redistributions of source code must retain the above copyright
  24. * notice, this list of conditions and the following disclaimer.
  25. * * Redistributions in binary form must reproduce the above copy
  26. * notice, this list of conditions and the following disclaimer in
  27. * the documentation and/or other materials provided with the
  28. * distribution.
  29. * * Neither the name of Intel Corporation nor the names of its
  30. * contributors may be used to endorse or promote products derived
  31. * from this software without specific prior written permission.
  32. *
  33. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  34. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  35. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  36. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  37. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  39. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  40. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  41. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  43. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. *
  45. * Intel PCIe NTB Linux driver
  46. *
  47. * Contact Information:
  48. * Jon Mason <jon.mason@intel.com>
  49. */
  50. #ifndef NTB_HW_INTEL_H
  51. #define NTB_HW_INTEL_H
  52. #include <linux/ntb.h>
  53. #include <linux/pci.h>
  54. /* PCI device IDs */
  55. #define PCI_DEVICE_ID_INTEL_NTB_B2B_JSF 0x3725
  56. #define PCI_DEVICE_ID_INTEL_NTB_PS_JSF 0x3726
  57. #define PCI_DEVICE_ID_INTEL_NTB_SS_JSF 0x3727
  58. #define PCI_DEVICE_ID_INTEL_NTB_B2B_SNB 0x3C0D
  59. #define PCI_DEVICE_ID_INTEL_NTB_PS_SNB 0x3C0E
  60. #define PCI_DEVICE_ID_INTEL_NTB_SS_SNB 0x3C0F
  61. #define PCI_DEVICE_ID_INTEL_NTB_B2B_IVT 0x0E0D
  62. #define PCI_DEVICE_ID_INTEL_NTB_PS_IVT 0x0E0E
  63. #define PCI_DEVICE_ID_INTEL_NTB_SS_IVT 0x0E0F
  64. #define PCI_DEVICE_ID_INTEL_NTB_B2B_HSX 0x2F0D
  65. #define PCI_DEVICE_ID_INTEL_NTB_PS_HSX 0x2F0E
  66. #define PCI_DEVICE_ID_INTEL_NTB_SS_HSX 0x2F0F
  67. #define PCI_DEVICE_ID_INTEL_NTB_B2B_BDX 0x6F0D
  68. #define PCI_DEVICE_ID_INTEL_NTB_PS_BDX 0x6F0E
  69. #define PCI_DEVICE_ID_INTEL_NTB_SS_BDX 0x6F0F
  70. #define PCI_DEVICE_ID_INTEL_NTB_B2B_SKX 0x201C
  71. /* Ntb control and link status */
  72. #define NTB_CTL_CFG_LOCK BIT(0)
  73. #define NTB_CTL_DISABLE BIT(1)
  74. #define NTB_CTL_S2P_BAR2_SNOOP BIT(2)
  75. #define NTB_CTL_P2S_BAR2_SNOOP BIT(4)
  76. #define NTB_CTL_S2P_BAR4_SNOOP BIT(6)
  77. #define NTB_CTL_P2S_BAR4_SNOOP BIT(8)
  78. #define NTB_CTL_S2P_BAR5_SNOOP BIT(12)
  79. #define NTB_CTL_P2S_BAR5_SNOOP BIT(14)
  80. #define NTB_LNK_STA_ACTIVE_BIT 0x2000
  81. #define NTB_LNK_STA_SPEED_MASK 0x000f
  82. #define NTB_LNK_STA_WIDTH_MASK 0x03f0
  83. #define NTB_LNK_STA_ACTIVE(x) (!!((x) & NTB_LNK_STA_ACTIVE_BIT))
  84. #define NTB_LNK_STA_SPEED(x) ((x) & NTB_LNK_STA_SPEED_MASK)
  85. #define NTB_LNK_STA_WIDTH(x) (((x) & NTB_LNK_STA_WIDTH_MASK) >> 4)
  86. /* flags to indicate unsafe api */
  87. #define NTB_UNSAFE_DB BIT_ULL(0)
  88. #define NTB_UNSAFE_SPAD BIT_ULL(1)
  89. #define NTB_BAR_MASK_64 ~(0xfull)
  90. #define NTB_BAR_MASK_32 ~(0xfu)
  91. struct intel_ntb_dev;
  92. struct intel_ntb_reg {
  93. int (*poll_link)(struct intel_ntb_dev *ndev);
  94. int (*link_is_up)(struct intel_ntb_dev *ndev);
  95. u64 (*db_ioread)(void __iomem *mmio);
  96. void (*db_iowrite)(u64 db_bits, void __iomem *mmio);
  97. unsigned long ntb_ctl;
  98. resource_size_t db_size;
  99. int mw_bar[];
  100. };
  101. struct intel_ntb_alt_reg {
  102. unsigned long db_bell;
  103. unsigned long db_mask;
  104. unsigned long db_clear;
  105. unsigned long spad;
  106. };
  107. struct intel_ntb_xlat_reg {
  108. unsigned long bar0_base;
  109. unsigned long bar2_xlat;
  110. unsigned long bar2_limit;
  111. };
  112. struct intel_b2b_addr {
  113. phys_addr_t bar0_addr;
  114. phys_addr_t bar2_addr64;
  115. phys_addr_t bar4_addr64;
  116. phys_addr_t bar4_addr32;
  117. phys_addr_t bar5_addr32;
  118. };
  119. struct intel_ntb_vec {
  120. struct intel_ntb_dev *ndev;
  121. int num;
  122. };
  123. struct intel_ntb_dev {
  124. struct ntb_dev ntb;
  125. /* offset of peer bar0 in b2b bar */
  126. unsigned long b2b_off;
  127. /* mw idx used to access peer bar0 */
  128. unsigned int b2b_idx;
  129. /* BAR45 is split into BAR4 and BAR5 */
  130. bool bar4_split;
  131. u32 ntb_ctl;
  132. u32 lnk_sta;
  133. unsigned char mw_count;
  134. unsigned char spad_count;
  135. unsigned char db_count;
  136. unsigned char db_vec_count;
  137. unsigned char db_vec_shift;
  138. u64 db_valid_mask;
  139. u64 db_link_mask;
  140. u64 db_mask;
  141. /* synchronize rmw access of db_mask and hw reg */
  142. spinlock_t db_mask_lock;
  143. struct msix_entry *msix;
  144. struct intel_ntb_vec *vec;
  145. const struct intel_ntb_reg *reg;
  146. const struct intel_ntb_alt_reg *self_reg;
  147. const struct intel_ntb_alt_reg *peer_reg;
  148. const struct intel_ntb_xlat_reg *xlat_reg;
  149. void __iomem *self_mmio;
  150. void __iomem *peer_mmio;
  151. phys_addr_t peer_addr;
  152. unsigned long last_ts;
  153. struct delayed_work hb_timer;
  154. unsigned long hwerr_flags;
  155. unsigned long unsafe_flags;
  156. unsigned long unsafe_flags_ignore;
  157. struct dentry *debugfs_dir;
  158. struct dentry *debugfs_info;
  159. };
  160. #define ntb_ndev(__ntb) container_of(__ntb, struct intel_ntb_dev, ntb)
  161. #define hb_ndev(__work) container_of(__work, struct intel_ntb_dev, \
  162. hb_timer.work)
  163. static inline int pdev_is_gen1(struct pci_dev *pdev)
  164. {
  165. switch (pdev->device) {
  166. case PCI_DEVICE_ID_INTEL_NTB_SS_JSF:
  167. case PCI_DEVICE_ID_INTEL_NTB_SS_SNB:
  168. case PCI_DEVICE_ID_INTEL_NTB_SS_IVT:
  169. case PCI_DEVICE_ID_INTEL_NTB_SS_HSX:
  170. case PCI_DEVICE_ID_INTEL_NTB_SS_BDX:
  171. case PCI_DEVICE_ID_INTEL_NTB_PS_JSF:
  172. case PCI_DEVICE_ID_INTEL_NTB_PS_SNB:
  173. case PCI_DEVICE_ID_INTEL_NTB_PS_IVT:
  174. case PCI_DEVICE_ID_INTEL_NTB_PS_HSX:
  175. case PCI_DEVICE_ID_INTEL_NTB_PS_BDX:
  176. case PCI_DEVICE_ID_INTEL_NTB_B2B_JSF:
  177. case PCI_DEVICE_ID_INTEL_NTB_B2B_SNB:
  178. case PCI_DEVICE_ID_INTEL_NTB_B2B_IVT:
  179. case PCI_DEVICE_ID_INTEL_NTB_B2B_HSX:
  180. case PCI_DEVICE_ID_INTEL_NTB_B2B_BDX:
  181. return 1;
  182. }
  183. return 0;
  184. }
  185. static inline int pdev_is_gen3(struct pci_dev *pdev)
  186. {
  187. if (pdev->device == PCI_DEVICE_ID_INTEL_NTB_B2B_SKX)
  188. return 1;
  189. return 0;
  190. }
  191. #ifndef ioread64
  192. #ifdef readq
  193. #define ioread64 readq
  194. #else
  195. #define ioread64 _ioread64
  196. static inline u64 _ioread64(void __iomem *mmio)
  197. {
  198. u64 low, high;
  199. low = ioread32(mmio);
  200. high = ioread32(mmio + sizeof(u32));
  201. return low | (high << 32);
  202. }
  203. #endif
  204. #endif
  205. #ifndef iowrite64
  206. #ifdef writeq
  207. #define iowrite64 writeq
  208. #else
  209. #define iowrite64 _iowrite64
  210. static inline void _iowrite64(u64 val, void __iomem *mmio)
  211. {
  212. iowrite32(val, mmio);
  213. iowrite32(val >> 32, mmio + sizeof(u32));
  214. }
  215. #endif
  216. #endif
  217. #endif