ntb_hw.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. *
  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) 2012 Intel Corporation. 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 Intel 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. * Intel PCIe NTB Linux driver
  44. *
  45. * Contact Information:
  46. * Jon Mason <jon.mason@intel.com>
  47. */
  48. #define PCI_DEVICE_ID_INTEL_NTB_B2B_JSF 0x3725
  49. #define PCI_DEVICE_ID_INTEL_NTB_CLASSIC_JSF 0x3726
  50. #define PCI_DEVICE_ID_INTEL_NTB_RP_JSF 0x3727
  51. #define PCI_DEVICE_ID_INTEL_NTB_RP_SNB 0x3C08
  52. #define PCI_DEVICE_ID_INTEL_NTB_B2B_SNB 0x3C0D
  53. #define PCI_DEVICE_ID_INTEL_NTB_CLASSIC_SNB 0x3C0E
  54. #define PCI_DEVICE_ID_INTEL_NTB_2ND_SNB 0x3C0F
  55. #define PCI_DEVICE_ID_INTEL_NTB_B2B_BWD 0x0C4E
  56. #define msix_table_size(control) ((control & PCI_MSIX_FLAGS_QSIZE)+1)
  57. #define NTB_BAR_MMIO 0
  58. #define NTB_BAR_23 2
  59. #define NTB_BAR_45 4
  60. #define NTB_BAR_MASK ((1 << NTB_BAR_MMIO) | (1 << NTB_BAR_23) |\
  61. (1 << NTB_BAR_45))
  62. #define NTB_LINK_DOWN 0
  63. #define NTB_LINK_UP 1
  64. #define NTB_HB_TIMEOUT msecs_to_jiffies(1000)
  65. #define NTB_NUM_MW 2
  66. enum ntb_hw_event {
  67. NTB_EVENT_SW_EVENT0 = 0,
  68. NTB_EVENT_SW_EVENT1,
  69. NTB_EVENT_SW_EVENT2,
  70. NTB_EVENT_HW_ERROR,
  71. NTB_EVENT_HW_LINK_UP,
  72. NTB_EVENT_HW_LINK_DOWN,
  73. };
  74. struct ntb_mw {
  75. dma_addr_t phys_addr;
  76. void __iomem *vbase;
  77. resource_size_t bar_sz;
  78. };
  79. struct ntb_db_cb {
  80. void (*callback) (void *data, int db_num);
  81. unsigned int db_num;
  82. void *data;
  83. struct ntb_device *ndev;
  84. };
  85. struct ntb_device {
  86. struct pci_dev *pdev;
  87. struct msix_entry *msix_entries;
  88. void __iomem *reg_base;
  89. struct ntb_mw mw[NTB_NUM_MW];
  90. struct {
  91. unsigned int max_spads;
  92. unsigned int max_db_bits;
  93. unsigned int msix_cnt;
  94. } limits;
  95. struct {
  96. void __iomem *pdb;
  97. void __iomem *pdb_mask;
  98. void __iomem *sdb;
  99. void __iomem *sbar2_xlat;
  100. void __iomem *sbar4_xlat;
  101. void __iomem *spad_write;
  102. void __iomem *spad_read;
  103. void __iomem *lnk_cntl;
  104. void __iomem *lnk_stat;
  105. void __iomem *spci_cmd;
  106. } reg_ofs;
  107. struct ntb_transport *ntb_transport;
  108. void (*event_cb)(void *handle, enum ntb_hw_event event);
  109. struct ntb_db_cb *db_cb;
  110. unsigned char hw_type;
  111. unsigned char conn_type;
  112. unsigned char dev_type;
  113. unsigned char num_msix;
  114. unsigned char bits_per_vector;
  115. unsigned char max_cbs;
  116. unsigned char link_status;
  117. struct delayed_work hb_timer;
  118. unsigned long last_ts;
  119. };
  120. /**
  121. * ntb_hw_link_status() - return the hardware link status
  122. * @ndev: pointer to ntb_device instance
  123. *
  124. * Returns true if the hardware is connected to the remote system
  125. *
  126. * RETURNS: true or false based on the hardware link state
  127. */
  128. static inline bool ntb_hw_link_status(struct ntb_device *ndev)
  129. {
  130. return ndev->link_status == NTB_LINK_UP;
  131. }
  132. /**
  133. * ntb_query_pdev() - return the pci_dev pointer
  134. * @ndev: pointer to ntb_device instance
  135. *
  136. * Given the ntb pointer return the pci_dev pointerfor the NTB hardware device
  137. *
  138. * RETURNS: a pointer to the ntb pci_dev
  139. */
  140. static inline struct pci_dev *ntb_query_pdev(struct ntb_device *ndev)
  141. {
  142. return ndev->pdev;
  143. }
  144. struct ntb_device *ntb_register_transport(struct pci_dev *pdev,
  145. void *transport);
  146. void ntb_unregister_transport(struct ntb_device *ndev);
  147. void ntb_set_mw_addr(struct ntb_device *ndev, unsigned int mw, u64 addr);
  148. int ntb_register_db_callback(struct ntb_device *ndev, unsigned int idx,
  149. void *data, void (*db_cb_func) (void *data,
  150. int db_num));
  151. void ntb_unregister_db_callback(struct ntb_device *ndev, unsigned int idx);
  152. int ntb_register_event_callback(struct ntb_device *ndev,
  153. void (*event_cb_func) (void *handle,
  154. enum ntb_hw_event event));
  155. void ntb_unregister_event_callback(struct ntb_device *ndev);
  156. int ntb_get_max_spads(struct ntb_device *ndev);
  157. int ntb_write_local_spad(struct ntb_device *ndev, unsigned int idx, u32 val);
  158. int ntb_read_local_spad(struct ntb_device *ndev, unsigned int idx, u32 *val);
  159. int ntb_write_remote_spad(struct ntb_device *ndev, unsigned int idx, u32 val);
  160. int ntb_read_remote_spad(struct ntb_device *ndev, unsigned int idx, u32 *val);
  161. void __iomem *ntb_get_mw_vbase(struct ntb_device *ndev, unsigned int mw);
  162. resource_size_t ntb_get_mw_size(struct ntb_device *ndev, unsigned int mw);
  163. void ntb_ring_sdb(struct ntb_device *ndev, unsigned int idx);
  164. void *ntb_find_transport(struct pci_dev *pdev);
  165. int ntb_transport_init(struct pci_dev *pdev);
  166. void ntb_transport_free(void *transport);