scif_main.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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_MAIN_H
  19. #define SCIF_MAIN_H
  20. #include <linux/sched.h>
  21. #include <linux/pci.h>
  22. #include <linux/miscdevice.h>
  23. #include <linux/dmaengine.h>
  24. #include <linux/file.h>
  25. #include <linux/scif.h>
  26. #include "../common/mic_dev.h"
  27. #define SCIF_MGMT_NODE 0
  28. #define SCIF_DEFAULT_WATCHDOG_TO 30
  29. #define SCIF_NODE_ACCEPT_TIMEOUT (3 * HZ)
  30. #define SCIF_NODE_ALIVE_TIMEOUT (SCIF_DEFAULT_WATCHDOG_TO * HZ)
  31. /*
  32. * Generic state used for certain node QP message exchanges
  33. * like Unregister, Alloc etc.
  34. */
  35. enum scif_msg_state {
  36. OP_IDLE = 1,
  37. OP_IN_PROGRESS,
  38. OP_COMPLETED,
  39. OP_FAILED
  40. };
  41. /*
  42. * struct scif_info - Global SCIF information
  43. *
  44. * @nodeid: Node ID this node is to others
  45. * @maxid: Max known node ID
  46. * @total: Total number of SCIF nodes
  47. * @nr_zombies: number of zombie endpoints
  48. * @eplock: Lock to synchronize listening, zombie endpoint lists
  49. * @connlock: Lock to synchronize connected and disconnected lists
  50. * @nb_connect_lock: Synchronize non blocking connect operations
  51. * @port_lock: Synchronize access to SCIF ports
  52. * @uaccept: List of user acceptreq waiting for acceptreg
  53. * @listen: List of listening end points
  54. * @zombie: List of zombie end points with pending RMA's
  55. * @connected: List of end points in connected state
  56. * @disconnected: List of end points in disconnected state
  57. * @nb_connect_list: List for non blocking connections
  58. * @misc_work: miscellaneous SCIF tasks
  59. * @conflock: Lock to synchronize SCIF node configuration changes
  60. * @en_msg_log: Enable debug message logging
  61. * @p2p_enable: Enable P2P SCIF network
  62. * @mdev: The MISC device
  63. * @conn_work: Work for workqueue handling all connections
  64. * @exitwq: Wait queue for waiting for an EXIT node QP message response
  65. * @loopb_dev: Dummy SCIF device used for loopback
  66. * @loopb_wq: Workqueue used for handling loopback messages
  67. * @loopb_wqname[16]: Name of loopback workqueue
  68. * @loopb_work: Used for submitting work to loopb_wq
  69. * @loopb_recv_q: List of messages received on the loopb_wq
  70. * @card_initiated_exit: set when the card has initiated the exit
  71. */
  72. struct scif_info {
  73. u8 nodeid;
  74. u8 maxid;
  75. u8 total;
  76. u32 nr_zombies;
  77. spinlock_t eplock;
  78. struct mutex connlock;
  79. spinlock_t nb_connect_lock;
  80. spinlock_t port_lock;
  81. struct list_head uaccept;
  82. struct list_head listen;
  83. struct list_head zombie;
  84. struct list_head connected;
  85. struct list_head disconnected;
  86. struct list_head nb_connect_list;
  87. struct work_struct misc_work;
  88. struct mutex conflock;
  89. u8 en_msg_log;
  90. u8 p2p_enable;
  91. struct miscdevice mdev;
  92. struct work_struct conn_work;
  93. wait_queue_head_t exitwq;
  94. struct scif_dev *loopb_dev;
  95. struct workqueue_struct *loopb_wq;
  96. char loopb_wqname[16];
  97. struct work_struct loopb_work;
  98. struct list_head loopb_recv_q;
  99. bool card_initiated_exit;
  100. };
  101. /*
  102. * struct scif_p2p_info - SCIF mapping information used for P2P
  103. *
  104. * @ppi_peer_id - SCIF peer node id
  105. * @ppi_sg - Scatter list for bar information (One for mmio and one for aper)
  106. * @sg_nentries - Number of entries in the scatterlist
  107. * @ppi_da: DMA address for MMIO and APER bars
  108. * @ppi_len: Length of MMIO and APER bars
  109. * @ppi_list: Link in list of mapping information
  110. */
  111. struct scif_p2p_info {
  112. u8 ppi_peer_id;
  113. struct scatterlist *ppi_sg[2];
  114. u64 sg_nentries[2];
  115. dma_addr_t ppi_da[2];
  116. u64 ppi_len[2];
  117. #define SCIF_PPI_MMIO 0
  118. #define SCIF_PPI_APER 1
  119. struct list_head ppi_list;
  120. };
  121. /*
  122. * struct scif_dev - SCIF remote device specific fields
  123. *
  124. * @node: Node id
  125. * @p2p: List of P2P mapping information
  126. * @qpairs: The node queue pair for exchanging control messages
  127. * @intr_wq: Workqueue for handling Node QP messages
  128. * @intr_wqname: Name of node QP workqueue for handling interrupts
  129. * @intr_bh: Used for submitting work to intr_wq
  130. * @lock: Lock used for synchronizing access to the scif device
  131. * @sdev: SCIF hardware device on the SCIF hardware bus
  132. * @db: doorbell the peer will trigger to generate an interrupt on self
  133. * @rdb: Doorbell to trigger on the peer to generate an interrupt on the peer
  134. * @cookie: Cookie received while registering the interrupt handler
  135. * init_msg_work: work scheduled for SCIF_INIT message processing
  136. * @p2p_dwork: Delayed work to enable polling for P2P state
  137. * @qp_dwork: Delayed work for enabling polling for remote QP information
  138. * @p2p_retry: Number of times to retry polling of P2P state
  139. * @base_addr: P2P aperture bar base address
  140. * @mic_mw mmio: The peer MMIO information used for P2P
  141. * @spdev: SCIF peer device on the SCIF peer bus
  142. * @node_remove_ack_pending: True if a node_remove_ack is pending
  143. * @exit_ack_pending: true if an exit_ack is pending
  144. * @disconn_wq: Used while waiting for a node remove response
  145. * @disconn_rescnt: Keeps track of number of node remove requests sent
  146. * @exit: Status of exit message
  147. * @qp_dma_addr: Queue pair DMA address passed to the peer
  148. */
  149. struct scif_dev {
  150. u8 node;
  151. struct list_head p2p;
  152. struct scif_qp *qpairs;
  153. struct workqueue_struct *intr_wq;
  154. char intr_wqname[16];
  155. struct work_struct intr_bh;
  156. struct mutex lock;
  157. struct scif_hw_dev *sdev;
  158. int db;
  159. int rdb;
  160. struct mic_irq *cookie;
  161. struct work_struct init_msg_work;
  162. struct delayed_work p2p_dwork;
  163. struct delayed_work qp_dwork;
  164. int p2p_retry;
  165. dma_addr_t base_addr;
  166. struct mic_mw mmio;
  167. struct scif_peer_dev __rcu *spdev;
  168. bool node_remove_ack_pending;
  169. bool exit_ack_pending;
  170. wait_queue_head_t disconn_wq;
  171. atomic_t disconn_rescnt;
  172. enum scif_msg_state exit;
  173. dma_addr_t qp_dma_addr;
  174. };
  175. extern struct scif_info scif_info;
  176. extern struct idr scif_ports;
  177. extern struct scif_dev *scif_dev;
  178. extern const struct file_operations scif_fops;
  179. /* Size of the RB for the Node QP */
  180. #define SCIF_NODE_QP_SIZE 0x10000
  181. #include "scif_nodeqp.h"
  182. /*
  183. * scifdev_self:
  184. * @dev: The remote SCIF Device
  185. *
  186. * Returns true if the SCIF Device passed is the self aka Loopback SCIF device.
  187. */
  188. static inline int scifdev_self(struct scif_dev *dev)
  189. {
  190. return dev->node == scif_info.nodeid;
  191. }
  192. static inline bool scif_is_mgmt_node(void)
  193. {
  194. return !scif_info.nodeid;
  195. }
  196. /*
  197. * scifdev_is_p2p:
  198. * @dev: The remote SCIF Device
  199. *
  200. * Returns true if the SCIF Device is a MIC Peer to Peer SCIF device.
  201. */
  202. static inline bool scifdev_is_p2p(struct scif_dev *dev)
  203. {
  204. if (scif_is_mgmt_node())
  205. return false;
  206. else
  207. return dev != &scif_dev[SCIF_MGMT_NODE] &&
  208. !scifdev_self(dev);
  209. }
  210. /*
  211. * scifdev_alive:
  212. * @scifdev: The remote SCIF Device
  213. *
  214. * Returns true if the remote SCIF Device is running or sleeping for
  215. * this endpoint.
  216. */
  217. static inline int _scifdev_alive(struct scif_dev *scifdev)
  218. {
  219. struct scif_peer_dev *spdev;
  220. rcu_read_lock();
  221. spdev = rcu_dereference(scifdev->spdev);
  222. rcu_read_unlock();
  223. return !!spdev;
  224. }
  225. #include "scif_epd.h"
  226. void __init scif_init_debugfs(void);
  227. void scif_exit_debugfs(void);
  228. int scif_setup_intr_wq(struct scif_dev *scifdev);
  229. void scif_destroy_intr_wq(struct scif_dev *scifdev);
  230. void scif_cleanup_scifdev(struct scif_dev *dev);
  231. void scif_handle_remove_node(int node);
  232. void scif_disconnect_node(u32 node_id, bool mgmt_initiated);
  233. void scif_free_qp(struct scif_dev *dev);
  234. void scif_misc_handler(struct work_struct *work);
  235. void scif_stop(struct scif_dev *scifdev);
  236. irqreturn_t scif_intr_handler(int irq, void *data);
  237. #endif /* SCIF_MAIN_H */