scif_nodeqp.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * This file is provided under a dual BSD/GPLv2 license. When using or
  5. * redistributing this file, you may do so under either license.
  6. *
  7. * GPL LICENSE SUMMARY
  8. *
  9. * Copyright(c) 2014 Intel Corporation.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of version 2 of the GNU General Public License as
  13. * published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful, but
  16. * WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * BSD LICENSE
  21. *
  22. * Copyright(c) 2014 Intel Corporation.
  23. *
  24. * Redistribution and use in source and binary forms, with or without
  25. * modification, are permitted provided that the following conditions
  26. * are met:
  27. *
  28. * * Redistributions of source code must retain the above copyright
  29. * notice, this list of conditions and the following disclaimer.
  30. * * Redistributions in binary form must reproduce the above copyright
  31. * notice, this list of conditions and the following disclaimer in
  32. * the documentation and/or other materials provided with the
  33. * distribution.
  34. * * Neither the name of Intel Corporation nor the names of its
  35. * contributors may be used to endorse or promote products derived
  36. * from this software without specific prior written permission.
  37. *
  38. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  39. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  40. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  41. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  42. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  43. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  44. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  45. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  46. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  47. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  48. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49. *
  50. * Intel SCIF driver.
  51. *
  52. */
  53. #ifndef SCIF_NODEQP
  54. #define SCIF_NODEQP
  55. #include "scif_rb.h"
  56. #include "scif_peer_bus.h"
  57. #define SCIF_INIT 1 /* First message sent to the peer node for discovery */
  58. #define SCIF_EXIT 2 /* Last message from the peer informing intent to exit */
  59. #define SCIF_EXIT_ACK 3 /* Response to SCIF_EXIT message */
  60. #define SCIF_NODE_ADD 4 /* Tell Online nodes a new node exits */
  61. #define SCIF_NODE_ADD_ACK 5 /* Confirm to mgmt node sequence is finished */
  62. #define SCIF_NODE_ADD_NACK 6 /* SCIF_NODE_ADD failed */
  63. #define SCIF_NODE_REMOVE 7 /* Request to deactivate a SCIF node */
  64. #define SCIF_NODE_REMOVE_ACK 8 /* Response to a SCIF_NODE_REMOVE message */
  65. #define SCIF_CNCT_REQ 9 /* Phys addr of Request connection to a port */
  66. #define SCIF_CNCT_GNT 10 /* Phys addr of new Grant connection request */
  67. #define SCIF_CNCT_GNTACK 11 /* Error type Reject a connection request */
  68. #define SCIF_CNCT_GNTNACK 12 /* Error type Reject a connection request */
  69. #define SCIF_CNCT_REJ 13 /* Error type Reject a connection request */
  70. #define SCIF_DISCNCT 14 /* Notify peer that connection is being terminated */
  71. #define SCIF_DISCNT_ACK 15 /* Notify peer that connection is being terminated */
  72. #define SCIF_CLIENT_SENT 16 /* Notify the peer that data has been written */
  73. #define SCIF_CLIENT_RCVD 17 /* Notify the peer that data has been read */
  74. #define SCIF_GET_NODE_INFO 18 /* Get current node mask from the mgmt node*/
  75. #define SCIF_REGISTER 19 /* Tell peer about a new registered window */
  76. #define SCIF_REGISTER_ACK 20 /* Notify peer about unregistration success */
  77. #define SCIF_REGISTER_NACK 21 /* Notify peer about registration success */
  78. #define SCIF_UNREGISTER 22 /* Tell peer about unregistering a window */
  79. #define SCIF_UNREGISTER_ACK 23 /* Notify peer about registration failure */
  80. #define SCIF_UNREGISTER_NACK 24 /* Notify peer about unregistration failure */
  81. #define SCIF_ALLOC_REQ 25 /* Request a mapped buffer */
  82. #define SCIF_ALLOC_GNT 26 /* Notify peer about allocation success */
  83. #define SCIF_ALLOC_REJ 27 /* Notify peer about allocation failure */
  84. #define SCIF_FREE_VIRT 28 /* Free previously allocated virtual memory */
  85. #define SCIF_MUNMAP 29 /* Acknowledgment for a SCIF_MMAP request */
  86. #define SCIF_MARK 30 /* SCIF Remote Fence Mark Request */
  87. #define SCIF_MARK_ACK 31 /* SCIF Remote Fence Mark Success */
  88. #define SCIF_MARK_NACK 32 /* SCIF Remote Fence Mark Failure */
  89. #define SCIF_WAIT 33 /* SCIF Remote Fence Wait Request */
  90. #define SCIF_WAIT_ACK 34 /* SCIF Remote Fence Wait Success */
  91. #define SCIF_WAIT_NACK 35 /* SCIF Remote Fence Wait Failure */
  92. #define SCIF_SIG_LOCAL 36 /* SCIF Remote Fence Local Signal Request */
  93. #define SCIF_SIG_REMOTE 37 /* SCIF Remote Fence Remote Signal Request */
  94. #define SCIF_SIG_ACK 38 /* SCIF Remote Fence Remote Signal Success */
  95. #define SCIF_SIG_NACK 39 /* SCIF Remote Fence Remote Signal Failure */
  96. #define SCIF_MAX_MSG SCIF_SIG_NACK
  97. /*
  98. * struct scifmsg - Node QP message format
  99. *
  100. * @src: Source information
  101. * @dst: Destination information
  102. * @uop: The message opcode
  103. * @payload: Unique payload format for each message
  104. */
  105. struct scifmsg {
  106. struct scif_port_id src;
  107. struct scif_port_id dst;
  108. u32 uop;
  109. u64 payload[4];
  110. } __packed;
  111. /*
  112. * struct scif_allocmsg - Used with SCIF_ALLOC_REQ to request
  113. * the remote note to allocate memory
  114. *
  115. * phys_addr: Physical address of the buffer
  116. * vaddr: Virtual address of the buffer
  117. * size: Size of the buffer
  118. * state: Current state
  119. * allocwq: wait queue for status
  120. */
  121. struct scif_allocmsg {
  122. dma_addr_t phys_addr;
  123. unsigned long vaddr;
  124. size_t size;
  125. enum scif_msg_state state;
  126. wait_queue_head_t allocwq;
  127. };
  128. /*
  129. * struct scif_qp - Node Queue Pair
  130. *
  131. * Interesting structure -- a little difficult because we can only
  132. * write across the PCIe, so any r/w pointer we need to read is
  133. * local. We only need to read the read pointer on the inbound_q
  134. * and read the write pointer in the outbound_q
  135. *
  136. * @magic: Magic value to ensure the peer sees the QP correctly
  137. * @outbound_q: The outbound ring buffer for sending messages
  138. * @inbound_q: The inbound ring buffer for receiving messages
  139. * @local_write: Local write index
  140. * @local_read: Local read index
  141. * @remote_qp: The remote queue pair
  142. * @local_buf: DMA address of local ring buffer
  143. * @local_qp: DMA address of the local queue pair data structure
  144. * @remote_buf: DMA address of remote ring buffer
  145. * @qp_state: QP state i.e. online or offline used for P2P
  146. * @send_lock: synchronize access to outbound queue
  147. * @recv_lock: Synchronize access to inbound queue
  148. */
  149. struct scif_qp {
  150. u64 magic;
  151. #define SCIFEP_MAGIC 0x5c1f000000005c1fULL
  152. struct scif_rb outbound_q;
  153. struct scif_rb inbound_q;
  154. u32 local_write __aligned(64);
  155. u32 local_read __aligned(64);
  156. struct scif_qp *remote_qp;
  157. dma_addr_t local_buf;
  158. dma_addr_t local_qp;
  159. dma_addr_t remote_buf;
  160. u32 qp_state;
  161. #define SCIF_QP_OFFLINE 0xdead
  162. #define SCIF_QP_ONLINE 0xc0de
  163. spinlock_t send_lock;
  164. spinlock_t recv_lock;
  165. };
  166. /*
  167. * struct scif_loopb_msg - An element in the loopback Node QP message list.
  168. *
  169. * @msg - The SCIF node QP message
  170. * @list - link in the list of messages
  171. */
  172. struct scif_loopb_msg {
  173. struct scifmsg msg;
  174. struct list_head list;
  175. };
  176. int scif_nodeqp_send(struct scif_dev *scifdev, struct scifmsg *msg);
  177. int _scif_nodeqp_send(struct scif_dev *scifdev, struct scifmsg *msg);
  178. void scif_nodeqp_intrhandler(struct scif_dev *scifdev, struct scif_qp *qp);
  179. int scif_loopb_msg_handler(struct scif_dev *scifdev, struct scif_qp *qp);
  180. int scif_setup_qp(struct scif_dev *scifdev);
  181. int scif_qp_response(phys_addr_t phys, struct scif_dev *dev);
  182. int scif_setup_qp_connect(struct scif_qp *qp, dma_addr_t *qp_offset,
  183. int local_size, struct scif_dev *scifdev);
  184. int scif_setup_qp_accept(struct scif_qp *qp, dma_addr_t *qp_offset,
  185. dma_addr_t phys, int local_size,
  186. struct scif_dev *scifdev);
  187. int scif_setup_qp_connect_response(struct scif_dev *scifdev,
  188. struct scif_qp *qp, u64 payload);
  189. int scif_setup_loopback_qp(struct scif_dev *scifdev);
  190. int scif_destroy_loopback_qp(struct scif_dev *scifdev);
  191. void scif_poll_qp_state(struct work_struct *work);
  192. void scif_destroy_p2p(struct scif_dev *scifdev);
  193. void scif_send_exit(struct scif_dev *scifdev);
  194. static inline struct device *scif_get_peer_dev(struct scif_dev *scifdev)
  195. {
  196. struct scif_peer_dev *spdev;
  197. struct device *spdev_ret;
  198. rcu_read_lock();
  199. spdev = rcu_dereference(scifdev->spdev);
  200. if (spdev)
  201. spdev_ret = get_device(&spdev->dev);
  202. else
  203. spdev_ret = ERR_PTR(-ENODEV);
  204. rcu_read_unlock();
  205. return spdev_ret;
  206. }
  207. static inline void scif_put_peer_dev(struct device *dev)
  208. {
  209. put_device(dev);
  210. }
  211. #endif /* SCIF_NODEQP */