verbs.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. /* SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause */
  2. /*
  3. * Copyright(c) 2015 - 2018 Intel Corporation.
  4. */
  5. #ifndef HFI1_VERBS_H
  6. #define HFI1_VERBS_H
  7. #include <linux/types.h>
  8. #include <linux/seqlock.h>
  9. #include <linux/kernel.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/kref.h>
  12. #include <linux/workqueue.h>
  13. #include <linux/kthread.h>
  14. #include <linux/completion.h>
  15. #include <linux/slab.h>
  16. #include <rdma/ib_pack.h>
  17. #include <rdma/ib_user_verbs.h>
  18. #include <rdma/ib_mad.h>
  19. #include <rdma/ib_hdrs.h>
  20. #include <rdma/rdma_vt.h>
  21. #include <rdma/rdmavt_qp.h>
  22. #include <rdma/rdmavt_cq.h>
  23. struct hfi1_ctxtdata;
  24. struct hfi1_pportdata;
  25. struct hfi1_devdata;
  26. struct hfi1_packet;
  27. #include "iowait.h"
  28. #include "tid_rdma.h"
  29. #include "opfn.h"
  30. #define HFI1_MAX_RDMA_ATOMIC 16
  31. /*
  32. * Increment this value if any changes that break userspace ABI
  33. * compatibility are made.
  34. */
  35. #define HFI1_UVERBS_ABI_VERSION 2
  36. /* IB Performance Manager status values */
  37. #define IB_PMA_SAMPLE_STATUS_DONE 0x00
  38. #define IB_PMA_SAMPLE_STATUS_STARTED 0x01
  39. #define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
  40. /* Mandatory IB performance counter select values. */
  41. #define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001)
  42. #define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002)
  43. #define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003)
  44. #define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004)
  45. #define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005)
  46. #define HFI1_VENDOR_IPG cpu_to_be16(0xFFA0)
  47. #define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL)
  48. #define OPA_BTH_MIG_REQ BIT(31)
  49. #define RC_OP(x) IB_OPCODE_RC_##x
  50. #define UC_OP(x) IB_OPCODE_UC_##x
  51. /* flags passed by hfi1_ib_rcv() */
  52. enum {
  53. HFI1_HAS_GRH = (1 << 0),
  54. };
  55. #define LRH_16B_BYTES (sizeof_field(struct hfi1_16b_header, lrh))
  56. #define LRH_16B_DWORDS (LRH_16B_BYTES / sizeof(u32))
  57. #define LRH_9B_BYTES (sizeof_field(struct ib_header, lrh))
  58. #define LRH_9B_DWORDS (LRH_9B_BYTES / sizeof(u32))
  59. /* 24Bits for qpn, upper 8Bits reserved */
  60. struct opa_16b_mgmt {
  61. __be32 dest_qpn;
  62. __be32 src_qpn;
  63. };
  64. struct hfi1_16b_header {
  65. u32 lrh[4];
  66. union {
  67. struct {
  68. struct ib_grh grh;
  69. struct ib_other_headers oth;
  70. } l;
  71. struct ib_other_headers oth;
  72. struct opa_16b_mgmt mgmt;
  73. } u;
  74. } __packed;
  75. struct hfi1_opa_header {
  76. union {
  77. struct ib_header ibh; /* 9B header */
  78. struct hfi1_16b_header opah; /* 16B header */
  79. };
  80. u8 hdr_type; /* 9B or 16B */
  81. } __packed;
  82. struct hfi1_ahg_info {
  83. u32 ahgdesc[2];
  84. u16 tx_flags;
  85. u8 ahgcount;
  86. u8 ahgidx;
  87. };
  88. struct hfi1_sdma_header {
  89. __le64 pbc;
  90. struct hfi1_opa_header hdr;
  91. } __packed;
  92. /*
  93. * hfi1 specific data structures that will be hidden from rvt after the queue
  94. * pair is made common
  95. */
  96. struct hfi1_qp_priv {
  97. struct hfi1_ahg_info *s_ahg; /* ahg info for next header */
  98. struct sdma_engine *s_sde; /* current sde */
  99. struct send_context *s_sendcontext; /* current sendcontext */
  100. struct hfi1_ctxtdata *rcd; /* QP's receive context */
  101. struct page **pages; /* for TID page scan */
  102. u32 tid_enqueue; /* saved when tid waited */
  103. u8 s_sc; /* SC[0..4] for next packet */
  104. struct iowait s_iowait;
  105. struct timer_list s_tid_timer; /* for timing tid wait */
  106. struct timer_list s_tid_retry_timer; /* for timing tid ack */
  107. struct list_head tid_wait; /* for queueing tid space */
  108. struct hfi1_opfn_data opfn;
  109. struct tid_flow_state flow_state;
  110. struct tid_rdma_qp_params tid_rdma;
  111. struct rvt_qp *owner;
  112. u16 s_running_pkt_size;
  113. u8 hdr_type; /* 9B or 16B */
  114. struct rvt_sge_state tid_ss; /* SGE state pointer for 2nd leg */
  115. atomic_t n_requests; /* # of TID RDMA requests in the */
  116. /* queue */
  117. atomic_t n_tid_requests; /* # of sent TID RDMA requests */
  118. unsigned long tid_timer_timeout_jiffies;
  119. unsigned long tid_retry_timeout_jiffies;
  120. /* variables for the TID RDMA SE state machine */
  121. u8 s_state;
  122. u8 s_retry;
  123. u8 rnr_nak_state; /* RNR NAK state */
  124. u8 s_nak_state;
  125. u32 s_nak_psn;
  126. u32 s_flags;
  127. u32 s_tid_cur;
  128. u32 s_tid_head;
  129. u32 s_tid_tail;
  130. u32 r_tid_head; /* Most recently added TID RDMA request */
  131. u32 r_tid_tail; /* the last completed TID RDMA request */
  132. u32 r_tid_ack; /* the TID RDMA request to be ACK'ed */
  133. u32 r_tid_alloc; /* Request for which we are allocating resources */
  134. u32 pending_tid_w_segs; /* Num of pending tid write segments */
  135. u32 pending_tid_w_resp; /* Num of pending tid write responses */
  136. u32 alloc_w_segs; /* Number of segments for which write */
  137. /* resources have been allocated for this QP */
  138. /* For TID RDMA READ */
  139. u32 tid_r_reqs; /* Num of tid reads requested */
  140. u32 tid_r_comp; /* Num of tid reads completed */
  141. u32 pending_tid_r_segs; /* Num of pending tid read segments */
  142. u16 pkts_ps; /* packets per segment */
  143. u8 timeout_shift; /* account for number of packets per segment */
  144. u32 r_next_psn_kdeth;
  145. u32 r_next_psn_kdeth_save;
  146. u32 s_resync_psn;
  147. u8 sync_pt; /* Set when QP reaches sync point */
  148. u8 resync;
  149. };
  150. #define HFI1_QP_WQE_INVALID ((u32)-1)
  151. struct hfi1_swqe_priv {
  152. struct tid_rdma_request tid_req;
  153. struct rvt_sge_state ss; /* Used for TID RDMA READ Request */
  154. };
  155. struct hfi1_ack_priv {
  156. struct rvt_sge_state ss; /* used for TID WRITE RESP */
  157. struct tid_rdma_request tid_req;
  158. };
  159. /*
  160. * This structure is used to hold commonly lookedup and computed values during
  161. * the send engine progress.
  162. */
  163. struct iowait_work;
  164. struct hfi1_pkt_state {
  165. struct hfi1_ibdev *dev;
  166. struct hfi1_ibport *ibp;
  167. struct hfi1_pportdata *ppd;
  168. struct verbs_txreq *s_txreq;
  169. struct iowait_work *wait;
  170. unsigned long flags;
  171. unsigned long timeout;
  172. unsigned long timeout_int;
  173. int cpu;
  174. u8 opcode;
  175. bool in_thread;
  176. bool pkts_sent;
  177. };
  178. #define HFI1_PSN_CREDIT 16
  179. struct hfi1_opcode_stats {
  180. u64 n_packets; /* number of packets */
  181. u64 n_bytes; /* total number of bytes */
  182. };
  183. struct hfi1_opcode_stats_perctx {
  184. struct hfi1_opcode_stats stats[256];
  185. };
  186. static inline void inc_opstats(
  187. u32 tlen,
  188. struct hfi1_opcode_stats *stats)
  189. {
  190. #ifdef CONFIG_DEBUG_FS
  191. stats->n_bytes += tlen;
  192. stats->n_packets++;
  193. #endif
  194. }
  195. struct hfi1_ibport {
  196. struct rvt_qp __rcu *qp[2];
  197. struct rvt_ibport rvp;
  198. /* the first 16 entries are sl_to_vl for !OPA */
  199. u8 sl_to_sc[32];
  200. u8 sc_to_sl[32];
  201. };
  202. struct hfi1_ibdev {
  203. struct rvt_dev_info rdi; /* Must be first */
  204. /* QP numbers are shared by all IB ports */
  205. /* protect txwait list */
  206. seqlock_t txwait_lock ____cacheline_aligned_in_smp;
  207. struct list_head txwait; /* list for wait verbs_txreq */
  208. struct list_head memwait; /* list for wait kernel memory */
  209. struct kmem_cache *verbs_txreq_cache;
  210. u64 n_txwait;
  211. u64 n_kmem_wait;
  212. u64 n_tidwait;
  213. /* protect iowait lists */
  214. seqlock_t iowait_lock ____cacheline_aligned_in_smp;
  215. u64 n_piowait;
  216. u64 n_piodrain;
  217. struct timer_list mem_timer;
  218. #ifdef CONFIG_DEBUG_FS
  219. /* per HFI debugfs */
  220. struct dentry *hfi1_ibdev_dbg;
  221. /* per HFI symlinks to above */
  222. struct dentry *hfi1_ibdev_link;
  223. #ifdef CONFIG_FAULT_INJECTION
  224. struct fault *fault;
  225. #endif
  226. #endif
  227. };
  228. static inline struct hfi1_ibdev *to_idev(struct ib_device *ibdev)
  229. {
  230. struct rvt_dev_info *rdi;
  231. rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
  232. return container_of(rdi, struct hfi1_ibdev, rdi);
  233. }
  234. static inline struct rvt_qp *iowait_to_qp(struct iowait *s_iowait)
  235. {
  236. struct hfi1_qp_priv *priv;
  237. priv = container_of(s_iowait, struct hfi1_qp_priv, s_iowait);
  238. return priv->owner;
  239. }
  240. /*
  241. * This must be called with s_lock held.
  242. */
  243. void hfi1_bad_pkey(struct hfi1_ibport *ibp, u32 key, u32 sl,
  244. u32 qp1, u32 qp2, u32 lid1, u32 lid2);
  245. void hfi1_cap_mask_chg(struct rvt_dev_info *rdi, u32 port_num);
  246. void hfi1_sys_guid_chg(struct hfi1_ibport *ibp);
  247. void hfi1_node_desc_chg(struct hfi1_ibport *ibp);
  248. int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u32 port,
  249. const struct ib_wc *in_wc, const struct ib_grh *in_grh,
  250. const struct ib_mad *in_mad, struct ib_mad *out_mad,
  251. size_t *out_mad_size, u16 *out_mad_pkey_index);
  252. /*
  253. * The PSN_MASK and PSN_SHIFT allow for
  254. * 1) comparing two PSNs
  255. * 2) returning the PSN with any upper bits masked
  256. * 3) returning the difference between to PSNs
  257. *
  258. * The number of significant bits in the PSN must
  259. * necessarily be at least one bit less than
  260. * the container holding the PSN.
  261. */
  262. #define PSN_MASK 0x7FFFFFFF
  263. #define PSN_SHIFT 1
  264. #define PSN_MODIFY_MASK 0xFFFFFF
  265. /*
  266. * Compare two PSNs
  267. * Returns an integer <, ==, or > than zero.
  268. */
  269. static inline int cmp_psn(u32 a, u32 b)
  270. {
  271. return (((int)a) - ((int)b)) << PSN_SHIFT;
  272. }
  273. /*
  274. * Return masked PSN
  275. */
  276. static inline u32 mask_psn(u32 a)
  277. {
  278. return a & PSN_MASK;
  279. }
  280. /*
  281. * Return delta between two PSNs
  282. */
  283. static inline u32 delta_psn(u32 a, u32 b)
  284. {
  285. return (((int)a - (int)b) << PSN_SHIFT) >> PSN_SHIFT;
  286. }
  287. static inline struct tid_rdma_request *wqe_to_tid_req(struct rvt_swqe *wqe)
  288. {
  289. return &((struct hfi1_swqe_priv *)wqe->priv)->tid_req;
  290. }
  291. static inline struct tid_rdma_request *ack_to_tid_req(struct rvt_ack_entry *e)
  292. {
  293. return &((struct hfi1_ack_priv *)e->priv)->tid_req;
  294. }
  295. /*
  296. * Look through all the active flows for a TID RDMA request and find
  297. * the one (if it exists) that contains the specified PSN.
  298. */
  299. static inline u32 __full_flow_psn(struct flow_state *state, u32 psn)
  300. {
  301. return mask_psn((state->generation << HFI1_KDETH_BTH_SEQ_SHIFT) |
  302. (psn & HFI1_KDETH_BTH_SEQ_MASK));
  303. }
  304. static inline u32 full_flow_psn(struct tid_rdma_flow *flow, u32 psn)
  305. {
  306. return __full_flow_psn(&flow->flow_state, psn);
  307. }
  308. struct verbs_txreq;
  309. void hfi1_put_txreq(struct verbs_txreq *tx);
  310. int hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
  311. void hfi1_cnp_rcv(struct hfi1_packet *packet);
  312. void hfi1_uc_rcv(struct hfi1_packet *packet);
  313. void hfi1_rc_rcv(struct hfi1_packet *packet);
  314. void hfi1_rc_hdrerr(
  315. struct hfi1_ctxtdata *rcd,
  316. struct hfi1_packet *packet,
  317. struct rvt_qp *qp);
  318. u8 ah_to_sc(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr);
  319. void hfi1_rc_verbs_aborted(struct rvt_qp *qp, struct hfi1_opa_header *opah);
  320. void hfi1_rc_send_complete(struct rvt_qp *qp, struct hfi1_opa_header *opah);
  321. void hfi1_ud_rcv(struct hfi1_packet *packet);
  322. int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey);
  323. void hfi1_migrate_qp(struct rvt_qp *qp);
  324. int hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
  325. int attr_mask, struct ib_udata *udata);
  326. void hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
  327. int attr_mask, struct ib_udata *udata);
  328. void hfi1_restart_rc(struct rvt_qp *qp, u32 psn, int wait);
  329. int hfi1_setup_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe,
  330. bool *call_send);
  331. int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_packet *packet);
  332. u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr,
  333. const struct ib_global_route *grh, u32 hwords, u32 nwords);
  334. void hfi1_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr,
  335. u32 bth0, u32 bth1, u32 bth2, int middle,
  336. struct hfi1_pkt_state *ps);
  337. bool hfi1_schedule_send_yield(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
  338. bool tid);
  339. void _hfi1_do_send(struct work_struct *work);
  340. void hfi1_do_send_from_rvt(struct rvt_qp *qp);
  341. void hfi1_do_send(struct rvt_qp *qp, bool in_thread);
  342. void hfi1_send_rc_ack(struct hfi1_packet *packet, bool is_fecn);
  343. int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
  344. int hfi1_make_uc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
  345. int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
  346. int hfi1_register_ib_device(struct hfi1_devdata *);
  347. void hfi1_unregister_ib_device(struct hfi1_devdata *);
  348. void hfi1_kdeth_eager_rcv(struct hfi1_packet *packet);
  349. void hfi1_kdeth_expected_rcv(struct hfi1_packet *packet);
  350. void hfi1_ib_rcv(struct hfi1_packet *packet);
  351. void hfi1_16B_rcv(struct hfi1_packet *packet);
  352. unsigned hfi1_get_npkeys(struct hfi1_devdata *);
  353. int hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
  354. u64 pbc);
  355. int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
  356. u64 pbc);
  357. static inline bool opa_bth_is_migration(struct ib_other_headers *ohdr)
  358. {
  359. return ohdr->bth[1] & cpu_to_be32(OPA_BTH_MIG_REQ);
  360. }
  361. void hfi1_wait_kmem(struct rvt_qp *qp);
  362. static inline void hfi1_trdma_send_complete(struct rvt_qp *qp,
  363. struct rvt_swqe *wqe,
  364. enum ib_wc_status status)
  365. {
  366. trdma_clean_swqe(qp, wqe);
  367. rvt_send_complete(qp, wqe, status);
  368. }
  369. extern const enum ib_wc_opcode ib_hfi1_wc_opcode[];
  370. extern const u8 hdr_len_by_opcode[];
  371. extern const int ib_rvt_state_ops[];
  372. extern __be64 ib_hfi1_sys_image_guid; /* in network order */
  373. extern unsigned int hfi1_max_cqes;
  374. extern unsigned int hfi1_max_cqs;
  375. extern unsigned int hfi1_max_qp_wrs;
  376. extern unsigned int hfi1_max_qps;
  377. extern unsigned int hfi1_max_sges;
  378. extern unsigned int hfi1_max_mcast_grps;
  379. extern unsigned int hfi1_max_mcast_qp_attached;
  380. extern unsigned int hfi1_max_srqs;
  381. extern unsigned int hfi1_max_srq_sges;
  382. extern unsigned int hfi1_max_srq_wrs;
  383. extern unsigned short piothreshold;
  384. extern const u32 ib_hfi1_rnr_table[];
  385. #endif /* HFI1_VERBS_H */