scif_epd.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Intel MIC Platform Software Stack (MPSS)
  3. *
  4. * Copyright(c) 2014 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License, version 2, as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * Intel SCIF driver.
  16. *
  17. */
  18. #ifndef SCIF_EPD_H
  19. #define SCIF_EPD_H
  20. #include <linux/delay.h>
  21. #include <linux/scif.h>
  22. #include <linux/scif_ioctl.h>
  23. #define SCIF_EPLOCK_HELD true
  24. enum scif_epd_state {
  25. SCIFEP_UNBOUND,
  26. SCIFEP_BOUND,
  27. SCIFEP_LISTENING,
  28. SCIFEP_CONNECTED,
  29. SCIFEP_CONNECTING,
  30. SCIFEP_MAPPING,
  31. SCIFEP_CLOSING,
  32. SCIFEP_CLLISTEN,
  33. SCIFEP_DISCONNECTED,
  34. SCIFEP_ZOMBIE
  35. };
  36. /*
  37. * struct scif_conreq - Data structure added to the connection list.
  38. *
  39. * @msg: connection request message received
  40. * @list: link to list of connection requests
  41. */
  42. struct scif_conreq {
  43. struct scifmsg msg;
  44. struct list_head list;
  45. };
  46. /* Size of the RB for the Endpoint QP */
  47. #define SCIF_ENDPT_QP_SIZE 0x1000
  48. /*
  49. * scif_endpt_qp_info - SCIF endpoint queue pair
  50. *
  51. * @qp - Qpair for this endpoint
  52. * @qp_offset - DMA address of the QP
  53. * @gnt_pld - Payload in a SCIF_CNCT_GNT message containing the
  54. * physical address of the remote_qp.
  55. */
  56. struct scif_endpt_qp_info {
  57. struct scif_qp *qp;
  58. dma_addr_t qp_offset;
  59. dma_addr_t gnt_pld;
  60. };
  61. /*
  62. * struct scif_endpt - The SCIF endpoint data structure
  63. *
  64. * @state: end point state
  65. * @lock: lock synchronizing access to endpoint fields like state etc
  66. * @port: self port information
  67. * @peer: peer port information
  68. * @backlog: maximum pending connection requests
  69. * @qp_info: Endpoint QP information for SCIF messaging
  70. * @remote_dev: scifdev used by this endpt to communicate with remote node.
  71. * @remote_ep: remote endpoint
  72. * @conreqcnt: Keep track of number of connection requests.
  73. * @files: Open file information used to match the id passed in with
  74. * the flush routine.
  75. * @conlist: list of connection requests
  76. * @conwq: waitqueue for connection processing
  77. * @discon: completion used during disconnection
  78. * @sendwq: waitqueue used during sending messages
  79. * @recvwq: waitqueue used during message receipt
  80. * @sendlock: Synchronize ordering of messages sent
  81. * @recvlock: Synchronize ordering of messages received
  82. * @list: link to list of various endpoints like connected, listening etc
  83. * @li_accept: pending ACCEPTREG
  84. * @acceptcnt: pending ACCEPTREG cnt
  85. * @liacceptlist: link to listen accept
  86. * @miacceptlist: link to uaccept
  87. * @listenep: associated listen ep
  88. * @conn_work: Non blocking connect work
  89. * @conn_port: Connection port
  90. * @conn_err: Errors during connection
  91. * @conn_async_state: Async connection
  92. * @conn_list: List of async connection requests
  93. */
  94. struct scif_endpt {
  95. enum scif_epd_state state;
  96. spinlock_t lock;
  97. struct scif_port_id port;
  98. struct scif_port_id peer;
  99. int backlog;
  100. struct scif_endpt_qp_info qp_info;
  101. struct scif_dev *remote_dev;
  102. u64 remote_ep;
  103. int conreqcnt;
  104. struct files_struct *files;
  105. struct list_head conlist;
  106. wait_queue_head_t conwq;
  107. struct completion discon;
  108. wait_queue_head_t sendwq;
  109. wait_queue_head_t recvwq;
  110. struct mutex sendlock;
  111. struct mutex recvlock;
  112. struct list_head list;
  113. struct list_head li_accept;
  114. int acceptcnt;
  115. struct list_head liacceptlist;
  116. struct list_head miacceptlist;
  117. struct scif_endpt *listenep;
  118. struct scif_port_id conn_port;
  119. int conn_err;
  120. int conn_async_state;
  121. struct list_head conn_list;
  122. };
  123. static inline int scifdev_alive(struct scif_endpt *ep)
  124. {
  125. return _scifdev_alive(ep->remote_dev);
  126. }
  127. void scif_cleanup_zombie_epd(void);
  128. void scif_teardown_ep(void *endpt);
  129. void scif_cleanup_ep_qp(struct scif_endpt *ep);
  130. void scif_add_epd_to_zombie_list(struct scif_endpt *ep, bool eplock_held);
  131. void scif_get_node_info(void);
  132. void scif_send_acks(struct scif_dev *dev);
  133. void scif_conn_handler(struct work_struct *work);
  134. int scif_rsrv_port(u16 port);
  135. void scif_get_port(u16 port);
  136. int scif_get_new_port(void);
  137. void scif_put_port(u16 port);
  138. int scif_user_send(scif_epd_t epd, void __user *msg, int len, int flags);
  139. int scif_user_recv(scif_epd_t epd, void __user *msg, int len, int flags);
  140. void scif_cnctreq(struct scif_dev *scifdev, struct scifmsg *msg);
  141. void scif_cnctgnt(struct scif_dev *scifdev, struct scifmsg *msg);
  142. void scif_cnctgnt_ack(struct scif_dev *scifdev, struct scifmsg *msg);
  143. void scif_cnctgnt_nack(struct scif_dev *scifdev, struct scifmsg *msg);
  144. void scif_cnctrej(struct scif_dev *scifdev, struct scifmsg *msg);
  145. void scif_discnct(struct scif_dev *scifdev, struct scifmsg *msg);
  146. void scif_discnt_ack(struct scif_dev *scifdev, struct scifmsg *msg);
  147. void scif_clientsend(struct scif_dev *scifdev, struct scifmsg *msg);
  148. void scif_clientrcvd(struct scif_dev *scifdev, struct scifmsg *msg);
  149. int __scif_connect(scif_epd_t epd, struct scif_port_id *dst, bool non_block);
  150. int __scif_flush(scif_epd_t epd);
  151. #endif /* SCIF_EPD_H */