scif_main.h 8.7 KB

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