rdmavt_qp.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. #ifndef DEF_RDMAVT_INCQP_H
  2. #define DEF_RDMAVT_INCQP_H
  3. /*
  4. * Copyright(c) 2016 - 2018 Intel Corporation.
  5. *
  6. * This file is provided under a dual BSD/GPLv2 license. When using or
  7. * redistributing this file, you may do so under either license.
  8. *
  9. * GPL LICENSE SUMMARY
  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. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. *
  26. * - Redistributions of source code must retain the above copyright
  27. * notice, this list of conditions and the following disclaimer.
  28. * - Redistributions in binary form must reproduce the above copyright
  29. * notice, this list of conditions and the following disclaimer in
  30. * the documentation and/or other materials provided with the
  31. * distribution.
  32. * - Neither the name of Intel Corporation nor the names of its
  33. * contributors may be used to endorse or promote products derived
  34. * from this software without specific prior written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  37. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  39. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  40. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  43. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  44. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  45. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  46. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. *
  48. */
  49. #include <rdma/rdma_vt.h>
  50. #include <rdma/ib_pack.h>
  51. #include <rdma/ib_verbs.h>
  52. #include <rdma/rdmavt_cq.h>
  53. /*
  54. * Atomic bit definitions for r_aflags.
  55. */
  56. #define RVT_R_WRID_VALID 0
  57. #define RVT_R_REWIND_SGE 1
  58. /*
  59. * Bit definitions for r_flags.
  60. */
  61. #define RVT_R_REUSE_SGE 0x01
  62. #define RVT_R_RDMAR_SEQ 0x02
  63. #define RVT_R_RSP_NAK 0x04
  64. #define RVT_R_RSP_SEND 0x08
  65. #define RVT_R_COMM_EST 0x10
  66. /*
  67. * Bit definitions for s_flags.
  68. *
  69. * RVT_S_SIGNAL_REQ_WR - set if QP send WRs contain completion signaled
  70. * RVT_S_BUSY - send tasklet is processing the QP
  71. * RVT_S_TIMER - the RC retry timer is active
  72. * RVT_S_ACK_PENDING - an ACK is waiting to be sent after RDMA read/atomics
  73. * RVT_S_WAIT_FENCE - waiting for all prior RDMA read or atomic SWQEs
  74. * before processing the next SWQE
  75. * RVT_S_WAIT_RDMAR - waiting for a RDMA read or atomic SWQE to complete
  76. * before processing the next SWQE
  77. * RVT_S_WAIT_RNR - waiting for RNR timeout
  78. * RVT_S_WAIT_SSN_CREDIT - waiting for RC credits to process next SWQE
  79. * RVT_S_WAIT_DMA - waiting for send DMA queue to drain before generating
  80. * next send completion entry not via send DMA
  81. * RVT_S_WAIT_PIO - waiting for a send buffer to be available
  82. * RVT_S_WAIT_PIO_DRAIN - waiting for a qp to drain pio packets
  83. * RVT_S_WAIT_TX - waiting for a struct verbs_txreq to be available
  84. * RVT_S_WAIT_DMA_DESC - waiting for DMA descriptors to be available
  85. * RVT_S_WAIT_KMEM - waiting for kernel memory to be available
  86. * RVT_S_WAIT_PSN - waiting for a packet to exit the send DMA queue
  87. * RVT_S_WAIT_ACK - waiting for an ACK packet before sending more requests
  88. * RVT_S_SEND_ONE - send one packet, request ACK, then wait for ACK
  89. * RVT_S_ECN - a BECN was queued to the send engine
  90. * RVT_S_MAX_BIT_MASK - The max bit that can be used by rdmavt
  91. */
  92. #define RVT_S_SIGNAL_REQ_WR 0x0001
  93. #define RVT_S_BUSY 0x0002
  94. #define RVT_S_TIMER 0x0004
  95. #define RVT_S_RESP_PENDING 0x0008
  96. #define RVT_S_ACK_PENDING 0x0010
  97. #define RVT_S_WAIT_FENCE 0x0020
  98. #define RVT_S_WAIT_RDMAR 0x0040
  99. #define RVT_S_WAIT_RNR 0x0080
  100. #define RVT_S_WAIT_SSN_CREDIT 0x0100
  101. #define RVT_S_WAIT_DMA 0x0200
  102. #define RVT_S_WAIT_PIO 0x0400
  103. #define RVT_S_WAIT_TX 0x0800
  104. #define RVT_S_WAIT_DMA_DESC 0x1000
  105. #define RVT_S_WAIT_KMEM 0x2000
  106. #define RVT_S_WAIT_PSN 0x4000
  107. #define RVT_S_WAIT_ACK 0x8000
  108. #define RVT_S_SEND_ONE 0x10000
  109. #define RVT_S_UNLIMITED_CREDIT 0x20000
  110. #define RVT_S_ECN 0x40000
  111. #define RVT_S_MAX_BIT_MASK 0x800000
  112. /*
  113. * Drivers should use s_flags starting with bit 31 down to the bit next to
  114. * RVT_S_MAX_BIT_MASK
  115. */
  116. /*
  117. * Wait flags that would prevent any packet type from being sent.
  118. */
  119. #define RVT_S_ANY_WAIT_IO \
  120. (RVT_S_WAIT_PIO | RVT_S_WAIT_TX | \
  121. RVT_S_WAIT_DMA_DESC | RVT_S_WAIT_KMEM)
  122. /*
  123. * Wait flags that would prevent send work requests from making progress.
  124. */
  125. #define RVT_S_ANY_WAIT_SEND (RVT_S_WAIT_FENCE | RVT_S_WAIT_RDMAR | \
  126. RVT_S_WAIT_RNR | RVT_S_WAIT_SSN_CREDIT | RVT_S_WAIT_DMA | \
  127. RVT_S_WAIT_PSN | RVT_S_WAIT_ACK)
  128. #define RVT_S_ANY_WAIT (RVT_S_ANY_WAIT_IO | RVT_S_ANY_WAIT_SEND)
  129. /* Number of bits to pay attention to in the opcode for checking qp type */
  130. #define RVT_OPCODE_QP_MASK 0xE0
  131. /* Flags for checking QP state (see ib_rvt_state_ops[]) */
  132. #define RVT_POST_SEND_OK 0x01
  133. #define RVT_POST_RECV_OK 0x02
  134. #define RVT_PROCESS_RECV_OK 0x04
  135. #define RVT_PROCESS_SEND_OK 0x08
  136. #define RVT_PROCESS_NEXT_SEND_OK 0x10
  137. #define RVT_FLUSH_SEND 0x20
  138. #define RVT_FLUSH_RECV 0x40
  139. #define RVT_PROCESS_OR_FLUSH_SEND \
  140. (RVT_PROCESS_SEND_OK | RVT_FLUSH_SEND)
  141. #define RVT_SEND_OR_FLUSH_OR_RECV_OK \
  142. (RVT_PROCESS_SEND_OK | RVT_FLUSH_SEND | RVT_PROCESS_RECV_OK)
  143. /*
  144. * Internal send flags
  145. */
  146. #define RVT_SEND_RESERVE_USED IB_SEND_RESERVED_START
  147. #define RVT_SEND_COMPLETION_ONLY (IB_SEND_RESERVED_START << 1)
  148. /*
  149. * Send work request queue entry.
  150. * The size of the sg_list is determined when the QP is created and stored
  151. * in qp->s_max_sge.
  152. */
  153. struct rvt_swqe {
  154. union {
  155. struct ib_send_wr wr; /* don't use wr.sg_list */
  156. struct ib_ud_wr ud_wr;
  157. struct ib_reg_wr reg_wr;
  158. struct ib_rdma_wr rdma_wr;
  159. struct ib_atomic_wr atomic_wr;
  160. };
  161. u32 psn; /* first packet sequence number */
  162. u32 lpsn; /* last packet sequence number */
  163. u32 ssn; /* send sequence number */
  164. u32 length; /* total length of data in sg_list */
  165. struct rvt_sge sg_list[0];
  166. };
  167. /*
  168. * Receive work request queue entry.
  169. * The size of the sg_list is determined when the QP (or SRQ) is created
  170. * and stored in qp->r_rq.max_sge (or srq->rq.max_sge).
  171. */
  172. struct rvt_rwqe {
  173. u64 wr_id;
  174. u8 num_sge;
  175. struct ib_sge sg_list[0];
  176. };
  177. /*
  178. * This structure is used to contain the head pointer, tail pointer,
  179. * and receive work queue entries as a single memory allocation so
  180. * it can be mmap'ed into user space.
  181. * Note that the wq array elements are variable size so you can't
  182. * just index into the array to get the N'th element;
  183. * use get_rwqe_ptr() instead.
  184. */
  185. struct rvt_rwq {
  186. u32 head; /* new work requests posted to the head */
  187. u32 tail; /* receives pull requests from here. */
  188. struct rvt_rwqe wq[0];
  189. };
  190. struct rvt_rq {
  191. struct rvt_rwq *wq;
  192. u32 size; /* size of RWQE array */
  193. u8 max_sge;
  194. /* protect changes in this struct */
  195. spinlock_t lock ____cacheline_aligned_in_smp;
  196. };
  197. /*
  198. * This structure is used by rvt_mmap() to validate an offset
  199. * when an mmap() request is made. The vm_area_struct then uses
  200. * this as its vm_private_data.
  201. */
  202. struct rvt_mmap_info {
  203. struct list_head pending_mmaps;
  204. struct ib_ucontext *context;
  205. void *obj;
  206. __u64 offset;
  207. struct kref ref;
  208. unsigned size;
  209. };
  210. /*
  211. * This structure holds the information that the send tasklet needs
  212. * to send a RDMA read response or atomic operation.
  213. */
  214. struct rvt_ack_entry {
  215. struct rvt_sge rdma_sge;
  216. u64 atomic_data;
  217. u32 psn;
  218. u32 lpsn;
  219. u8 opcode;
  220. u8 sent;
  221. };
  222. #define RC_QP_SCALING_INTERVAL 5
  223. #define RVT_OPERATION_PRIV 0x00000001
  224. #define RVT_OPERATION_ATOMIC 0x00000002
  225. #define RVT_OPERATION_ATOMIC_SGE 0x00000004
  226. #define RVT_OPERATION_LOCAL 0x00000008
  227. #define RVT_OPERATION_USE_RESERVE 0x00000010
  228. #define RVT_OPERATION_MAX (IB_WR_RESERVED10 + 1)
  229. /**
  230. * rvt_operation_params - op table entry
  231. * @length - the length to copy into the swqe entry
  232. * @qpt_support - a bit mask indicating QP type support
  233. * @flags - RVT_OPERATION flags (see above)
  234. *
  235. * This supports table driven post send so that
  236. * the driver can have differing an potentially
  237. * different sets of operations.
  238. *
  239. **/
  240. struct rvt_operation_params {
  241. size_t length;
  242. u32 qpt_support;
  243. u32 flags;
  244. };
  245. /*
  246. * Common variables are protected by both r_rq.lock and s_lock in that order
  247. * which only happens in modify_qp() or changing the QP 'state'.
  248. */
  249. struct rvt_qp {
  250. struct ib_qp ibqp;
  251. void *priv; /* Driver private data */
  252. /* read mostly fields above and below */
  253. struct rdma_ah_attr remote_ah_attr;
  254. struct rdma_ah_attr alt_ah_attr;
  255. struct rvt_qp __rcu *next; /* link list for QPN hash table */
  256. struct rvt_swqe *s_wq; /* send work queue */
  257. struct rvt_mmap_info *ip;
  258. unsigned long timeout_jiffies; /* computed from timeout */
  259. int srate_mbps; /* s_srate (below) converted to Mbit/s */
  260. pid_t pid; /* pid for user mode QPs */
  261. u32 remote_qpn;
  262. u32 qkey; /* QKEY for this QP (for UD or RD) */
  263. u32 s_size; /* send work queue size */
  264. u16 pmtu; /* decoded from path_mtu */
  265. u8 log_pmtu; /* shift for pmtu */
  266. u8 state; /* QP state */
  267. u8 allowed_ops; /* high order bits of allowed opcodes */
  268. u8 qp_access_flags;
  269. u8 alt_timeout; /* Alternate path timeout for this QP */
  270. u8 timeout; /* Timeout for this QP */
  271. u8 s_srate;
  272. u8 s_mig_state;
  273. u8 port_num;
  274. u8 s_pkey_index; /* PKEY index to use */
  275. u8 s_alt_pkey_index; /* Alternate path PKEY index to use */
  276. u8 r_max_rd_atomic; /* max number of RDMA read/atomic to receive */
  277. u8 s_max_rd_atomic; /* max number of RDMA read/atomic to send */
  278. u8 s_retry_cnt; /* number of times to retry */
  279. u8 s_rnr_retry_cnt;
  280. u8 r_min_rnr_timer; /* retry timeout value for RNR NAKs */
  281. u8 s_max_sge; /* size of s_wq->sg_list */
  282. u8 s_draining;
  283. /* start of read/write fields */
  284. atomic_t refcount ____cacheline_aligned_in_smp;
  285. wait_queue_head_t wait;
  286. struct rvt_ack_entry *s_ack_queue;
  287. struct rvt_sge_state s_rdma_read_sge;
  288. spinlock_t r_lock ____cacheline_aligned_in_smp; /* used for APM */
  289. u32 r_psn; /* expected rcv packet sequence number */
  290. unsigned long r_aflags;
  291. u64 r_wr_id; /* ID for current receive WQE */
  292. u32 r_ack_psn; /* PSN for next ACK or atomic ACK */
  293. u32 r_len; /* total length of r_sge */
  294. u32 r_rcv_len; /* receive data len processed */
  295. u32 r_msn; /* message sequence number */
  296. u8 r_state; /* opcode of last packet received */
  297. u8 r_flags;
  298. u8 r_head_ack_queue; /* index into s_ack_queue[] */
  299. u8 r_adefered; /* defered ack count */
  300. struct list_head rspwait; /* link for waiting to respond */
  301. struct rvt_sge_state r_sge; /* current receive data */
  302. struct rvt_rq r_rq; /* receive work queue */
  303. /* post send line */
  304. spinlock_t s_hlock ____cacheline_aligned_in_smp;
  305. u32 s_head; /* new entries added here */
  306. u32 s_next_psn; /* PSN for next request */
  307. u32 s_avail; /* number of entries avail */
  308. u32 s_ssn; /* SSN of tail entry */
  309. atomic_t s_reserved_used; /* reserved entries in use */
  310. spinlock_t s_lock ____cacheline_aligned_in_smp;
  311. u32 s_flags;
  312. struct rvt_sge_state *s_cur_sge;
  313. struct rvt_swqe *s_wqe;
  314. struct rvt_sge_state s_sge; /* current send request data */
  315. struct rvt_mregion *s_rdma_mr;
  316. u32 s_len; /* total length of s_sge */
  317. u32 s_rdma_read_len; /* total length of s_rdma_read_sge */
  318. u32 s_last_psn; /* last response PSN processed */
  319. u32 s_sending_psn; /* lowest PSN that is being sent */
  320. u32 s_sending_hpsn; /* highest PSN that is being sent */
  321. u32 s_psn; /* current packet sequence number */
  322. u32 s_ack_rdma_psn; /* PSN for sending RDMA read responses */
  323. u32 s_ack_psn; /* PSN for acking sends and RDMA writes */
  324. u32 s_tail; /* next entry to process */
  325. u32 s_cur; /* current work queue entry */
  326. u32 s_acked; /* last un-ACK'ed entry */
  327. u32 s_last; /* last completed entry */
  328. u32 s_lsn; /* limit sequence number (credit) */
  329. u32 s_ahgpsn; /* set to the psn in the copy of the header */
  330. u16 s_cur_size; /* size of send packet in bytes */
  331. u16 s_rdma_ack_cnt;
  332. u8 s_hdrwords; /* size of s_hdr in 32 bit words */
  333. s8 s_ahgidx;
  334. u8 s_state; /* opcode of last packet sent */
  335. u8 s_ack_state; /* opcode of packet to ACK */
  336. u8 s_nak_state; /* non-zero if NAK is pending */
  337. u8 r_nak_state; /* non-zero if NAK is pending */
  338. u8 s_retry; /* requester retry counter */
  339. u8 s_rnr_retry; /* requester RNR retry counter */
  340. u8 s_num_rd_atomic; /* number of RDMA read/atomic pending */
  341. u8 s_tail_ack_queue; /* index into s_ack_queue[] */
  342. struct rvt_sge_state s_ack_rdma_sge;
  343. struct timer_list s_timer;
  344. struct hrtimer s_rnr_timer;
  345. atomic_t local_ops_pending; /* number of fast_reg/local_inv reqs */
  346. /*
  347. * This sge list MUST be last. Do not add anything below here.
  348. */
  349. struct rvt_sge r_sg_list[0] /* verified SGEs */
  350. ____cacheline_aligned_in_smp;
  351. };
  352. struct rvt_srq {
  353. struct ib_srq ibsrq;
  354. struct rvt_rq rq;
  355. struct rvt_mmap_info *ip;
  356. /* send signal when number of RWQEs < limit */
  357. u32 limit;
  358. };
  359. #define RVT_QPN_MAX BIT(24)
  360. #define RVT_QPNMAP_ENTRIES (RVT_QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
  361. #define RVT_BITS_PER_PAGE (PAGE_SIZE * BITS_PER_BYTE)
  362. #define RVT_BITS_PER_PAGE_MASK (RVT_BITS_PER_PAGE - 1)
  363. #define RVT_QPN_MASK IB_QPN_MASK
  364. /*
  365. * QPN-map pages start out as NULL, they get allocated upon
  366. * first use and are never deallocated. This way,
  367. * large bitmaps are not allocated unless large numbers of QPs are used.
  368. */
  369. struct rvt_qpn_map {
  370. void *page;
  371. };
  372. struct rvt_qpn_table {
  373. spinlock_t lock; /* protect changes to the qp table */
  374. unsigned flags; /* flags for QP0/1 allocated for each port */
  375. u32 last; /* last QP number allocated */
  376. u32 nmaps; /* size of the map table */
  377. u16 limit;
  378. u8 incr;
  379. /* bit map of free QP numbers other than 0/1 */
  380. struct rvt_qpn_map map[RVT_QPNMAP_ENTRIES];
  381. };
  382. struct rvt_qp_ibdev {
  383. u32 qp_table_size;
  384. u32 qp_table_bits;
  385. struct rvt_qp __rcu **qp_table;
  386. spinlock_t qpt_lock; /* qptable lock */
  387. struct rvt_qpn_table qpn_table;
  388. };
  389. /*
  390. * There is one struct rvt_mcast for each multicast GID.
  391. * All attached QPs are then stored as a list of
  392. * struct rvt_mcast_qp.
  393. */
  394. struct rvt_mcast_qp {
  395. struct list_head list;
  396. struct rvt_qp *qp;
  397. };
  398. struct rvt_mcast_addr {
  399. union ib_gid mgid;
  400. u16 lid;
  401. };
  402. struct rvt_mcast {
  403. struct rb_node rb_node;
  404. struct rvt_mcast_addr mcast_addr;
  405. struct list_head qp_list;
  406. wait_queue_head_t wait;
  407. atomic_t refcount;
  408. int n_attached;
  409. };
  410. /*
  411. * Since struct rvt_swqe is not a fixed size, we can't simply index into
  412. * struct rvt_qp.s_wq. This function does the array index computation.
  413. */
  414. static inline struct rvt_swqe *rvt_get_swqe_ptr(struct rvt_qp *qp,
  415. unsigned n)
  416. {
  417. return (struct rvt_swqe *)((char *)qp->s_wq +
  418. (sizeof(struct rvt_swqe) +
  419. qp->s_max_sge *
  420. sizeof(struct rvt_sge)) * n);
  421. }
  422. /*
  423. * Since struct rvt_rwqe is not a fixed size, we can't simply index into
  424. * struct rvt_rwq.wq. This function does the array index computation.
  425. */
  426. static inline struct rvt_rwqe *rvt_get_rwqe_ptr(struct rvt_rq *rq, unsigned n)
  427. {
  428. return (struct rvt_rwqe *)
  429. ((char *)rq->wq->wq +
  430. (sizeof(struct rvt_rwqe) +
  431. rq->max_sge * sizeof(struct ib_sge)) * n);
  432. }
  433. /**
  434. * rvt_is_user_qp - return if this is user mode QP
  435. * @qp - the target QP
  436. */
  437. static inline bool rvt_is_user_qp(struct rvt_qp *qp)
  438. {
  439. return !!qp->pid;
  440. }
  441. /**
  442. * rvt_get_qp - get a QP reference
  443. * @qp - the QP to hold
  444. */
  445. static inline void rvt_get_qp(struct rvt_qp *qp)
  446. {
  447. atomic_inc(&qp->refcount);
  448. }
  449. /**
  450. * rvt_put_qp - release a QP reference
  451. * @qp - the QP to release
  452. */
  453. static inline void rvt_put_qp(struct rvt_qp *qp)
  454. {
  455. if (qp && atomic_dec_and_test(&qp->refcount))
  456. wake_up(&qp->wait);
  457. }
  458. /**
  459. * rvt_put_swqe - drop mr refs held by swqe
  460. * @wqe - the send wqe
  461. *
  462. * This drops any mr references held by the swqe
  463. */
  464. static inline void rvt_put_swqe(struct rvt_swqe *wqe)
  465. {
  466. int i;
  467. for (i = 0; i < wqe->wr.num_sge; i++) {
  468. struct rvt_sge *sge = &wqe->sg_list[i];
  469. rvt_put_mr(sge->mr);
  470. }
  471. }
  472. /**
  473. * rvt_qp_wqe_reserve - reserve operation
  474. * @qp - the rvt qp
  475. * @wqe - the send wqe
  476. *
  477. * This routine used in post send to record
  478. * a wqe relative reserved operation use.
  479. */
  480. static inline void rvt_qp_wqe_reserve(
  481. struct rvt_qp *qp,
  482. struct rvt_swqe *wqe)
  483. {
  484. atomic_inc(&qp->s_reserved_used);
  485. }
  486. /**
  487. * rvt_qp_wqe_unreserve - clean reserved operation
  488. * @qp - the rvt qp
  489. * @wqe - the send wqe
  490. *
  491. * This decrements the reserve use count.
  492. *
  493. * This call MUST precede the change to
  494. * s_last to insure that post send sees a stable
  495. * s_avail.
  496. *
  497. * An smp_mp__after_atomic() is used to insure
  498. * the compiler does not juggle the order of the s_last
  499. * ring index and the decrementing of s_reserved_used.
  500. */
  501. static inline void rvt_qp_wqe_unreserve(
  502. struct rvt_qp *qp,
  503. struct rvt_swqe *wqe)
  504. {
  505. if (unlikely(wqe->wr.send_flags & RVT_SEND_RESERVE_USED)) {
  506. atomic_dec(&qp->s_reserved_used);
  507. /* insure no compiler re-order up to s_last change */
  508. smp_mb__after_atomic();
  509. }
  510. }
  511. extern const enum ib_wc_opcode ib_rvt_wc_opcode[];
  512. /**
  513. * rvt_qp_swqe_complete() - insert send completion
  514. * @qp - the qp
  515. * @wqe - the send wqe
  516. * @status - completion status
  517. *
  518. * Insert a send completion into the completion
  519. * queue if the qp indicates it should be done.
  520. *
  521. * See IBTA 10.7.3.1 for info on completion
  522. * control.
  523. */
  524. static inline void rvt_qp_swqe_complete(
  525. struct rvt_qp *qp,
  526. struct rvt_swqe *wqe,
  527. enum ib_wc_opcode opcode,
  528. enum ib_wc_status status)
  529. {
  530. if (unlikely(wqe->wr.send_flags & RVT_SEND_RESERVE_USED))
  531. return;
  532. if (!(qp->s_flags & RVT_S_SIGNAL_REQ_WR) ||
  533. (wqe->wr.send_flags & IB_SEND_SIGNALED) ||
  534. status != IB_WC_SUCCESS) {
  535. struct ib_wc wc;
  536. memset(&wc, 0, sizeof(wc));
  537. wc.wr_id = wqe->wr.wr_id;
  538. wc.status = status;
  539. wc.opcode = opcode;
  540. wc.qp = &qp->ibqp;
  541. wc.byte_len = wqe->length;
  542. rvt_cq_enter(ibcq_to_rvtcq(qp->ibqp.send_cq), &wc,
  543. status != IB_WC_SUCCESS);
  544. }
  545. }
  546. /*
  547. * Compare the lower 24 bits of the msn values.
  548. * Returns an integer <, ==, or > than zero.
  549. */
  550. static inline int rvt_cmp_msn(u32 a, u32 b)
  551. {
  552. return (((int)a) - ((int)b)) << 8;
  553. }
  554. /**
  555. * rvt_compute_aeth - compute the AETH (syndrome + MSN)
  556. * @qp: the queue pair to compute the AETH for
  557. *
  558. * Returns the AETH.
  559. */
  560. __be32 rvt_compute_aeth(struct rvt_qp *qp);
  561. /**
  562. * rvt_get_credit - flush the send work queue of a QP
  563. * @qp: the qp who's send work queue to flush
  564. * @aeth: the Acknowledge Extended Transport Header
  565. *
  566. * The QP s_lock should be held.
  567. */
  568. void rvt_get_credit(struct rvt_qp *qp, u32 aeth);
  569. /**
  570. * @qp - the qp pair
  571. * @len - the length
  572. *
  573. * Perform a shift based mtu round up divide
  574. */
  575. static inline u32 rvt_div_round_up_mtu(struct rvt_qp *qp, u32 len)
  576. {
  577. return (len + qp->pmtu - 1) >> qp->log_pmtu;
  578. }
  579. /**
  580. * @qp - the qp pair
  581. * @len - the length
  582. *
  583. * Perform a shift based mtu divide
  584. */
  585. static inline u32 rvt_div_mtu(struct rvt_qp *qp, u32 len)
  586. {
  587. return len >> qp->log_pmtu;
  588. }
  589. /**
  590. * rvt_timeout_to_jiffies - Convert a ULP timeout input into jiffies
  591. * @timeout - timeout input(0 - 31).
  592. *
  593. * Return a timeout value in jiffies.
  594. */
  595. static inline unsigned long rvt_timeout_to_jiffies(u8 timeout)
  596. {
  597. if (timeout > 31)
  598. timeout = 31;
  599. return usecs_to_jiffies(1U << timeout) * 4096UL / 1000UL;
  600. }
  601. extern const int ib_rvt_state_ops[];
  602. struct rvt_dev_info;
  603. int rvt_get_rwqe(struct rvt_qp *qp, bool wr_id_only);
  604. void rvt_comm_est(struct rvt_qp *qp);
  605. int rvt_error_qp(struct rvt_qp *qp, enum ib_wc_status err);
  606. void rvt_rc_error(struct rvt_qp *qp, enum ib_wc_status err);
  607. unsigned long rvt_rnr_tbl_to_usec(u32 index);
  608. enum hrtimer_restart rvt_rc_rnr_retry(struct hrtimer *t);
  609. void rvt_add_rnr_timer(struct rvt_qp *qp, u32 aeth);
  610. void rvt_del_timers_sync(struct rvt_qp *qp);
  611. void rvt_stop_rc_timers(struct rvt_qp *qp);
  612. void rvt_add_retry_timer(struct rvt_qp *qp);
  613. /**
  614. * struct rvt_qp_iter - the iterator for QPs
  615. * @qp - the current QP
  616. *
  617. * This structure defines the current iterator
  618. * state for sequenced access to all QPs relative
  619. * to an rvt_dev_info.
  620. */
  621. struct rvt_qp_iter {
  622. struct rvt_qp *qp;
  623. /* private: backpointer */
  624. struct rvt_dev_info *rdi;
  625. /* private: callback routine */
  626. void (*cb)(struct rvt_qp *qp, u64 v);
  627. /* private: for arg to callback routine */
  628. u64 v;
  629. /* private: number of SMI,GSI QPs for device */
  630. int specials;
  631. /* private: current iterator index */
  632. int n;
  633. };
  634. struct rvt_qp_iter *rvt_qp_iter_init(struct rvt_dev_info *rdi,
  635. u64 v,
  636. void (*cb)(struct rvt_qp *qp, u64 v));
  637. int rvt_qp_iter_next(struct rvt_qp_iter *iter);
  638. void rvt_qp_iter(struct rvt_dev_info *rdi,
  639. u64 v,
  640. void (*cb)(struct rvt_qp *qp, u64 v));
  641. void rvt_qp_mr_clean(struct rvt_qp *qp, u32 lkey);
  642. #endif /* DEF_RDMAVT_INCQP_H */