Debian Codegraph @

libibverbs/man/ibv_wr_post.3.md

raw symbols SCIP
1 ---
2 date: 2018-11-27
3 footer: libibverbs
4 header: "Libibverbs Programmer's Manual"
5 layout: page
6 license: 'Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md'
7 section: 3
8 title: IBV_WR API
9 ---
10
11 # NAME
12
13 ibv_wr_abort, ibv_wr_complete, ibv_wr_start - Manage regions allowed to post work
14
15 ibv_wr_atomic_cmp_swp, ibv_wr_atomic_fetch_add - Post remote atomic operation work requests
16
17 ibv_wr_bind_mw, ibv_wr_local_inv - Post work requests for memory windows
18
19 ibv_wr_rdma_read, ibv_wr_rdma_write, ibv_wr_rdma_write_imm, ibv_wr_flush - Post RDMA work requests
20
21 ibv_wr_send, ibv_wr_send_imm, ibv_wr_send_inv - Post send work requests
22
23 ibv_wr_send_tso - Post segmentation offload work requests
24
25 ibv_wr_set_inline_data, ibv_wr_set_inline_data_list - Attach inline data to the last work request
26
27 ibv_wr_set_sge, ibv_wr_set_sge_list - Attach data to the last work request
28
29 ibv_wr_set_ud_addr - Attach UD addressing info to the last work request
30
31 ibv_wr_set_xrc_srqn - Attach an XRC SRQN to the last work request
32
33 # SYNOPSIS
34
35 ```c
36 #include <infiniband/verbs.h>
37
38 void ibv_wr_abort(struct ibv_qp_ex *qp);
39 int ibv_wr_complete(struct ibv_qp_ex *qp);
40 void ibv_wr_start(struct ibv_qp_ex *qp);
41
42 void ibv_wr_atomic_cmp_swp(struct ibv_qp_ex *qp, uint32_t rkey,
43 uint64_t remote_addr, uint64_t compare,
44 uint64_t swap);
45 void ibv_wr_atomic_fetch_add(struct ibv_qp_ex *qp, uint32_t rkey,
46 uint64_t remote_addr, uint64_t add);
47
48 void ibv_wr_bind_mw(struct ibv_qp_ex *qp, struct ibv_mw *mw, uint32_t rkey,
49 const struct ibv_mw_bind_info *bind_info);
50 void ibv_wr_local_inv(struct ibv_qp_ex *qp, uint32_t invalidate_rkey);
51
52 void ibv_wr_rdma_read(struct ibv_qp_ex *qp, uint32_t rkey,
53 uint64_t remote_addr);
54 void ibv_wr_rdma_write(struct ibv_qp_ex *qp, uint32_t rkey,
55 uint64_t remote_addr);
56 void ibv_wr_rdma_write_imm(struct ibv_qp_ex *qp, uint32_t rkey,
57 uint64_t remote_addr, __be32 imm_data);
58
59 void ibv_wr_send(struct ibv_qp_ex *qp);
60 void ibv_wr_send_imm(struct ibv_qp_ex *qp, __be32 imm_data);
61 void ibv_wr_send_inv(struct ibv_qp_ex *qp, uint32_t invalidate_rkey);
62 void ibv_wr_send_tso(struct ibv_qp_ex *qp, void *hdr, uint16_t hdr_sz,
63 uint16_t mss);
64
65 void ibv_wr_set_inline_data(struct ibv_qp_ex *qp, void *addr, size_t length);
66 void ibv_wr_set_inline_data_list(struct ibv_qp_ex *qp, size_t num_buf,
67 const struct ibv_data_buf *buf_list);
68 void ibv_wr_set_sge(struct ibv_qp_ex *qp, uint32_t lkey, uint64_t addr,
69 uint32_t length);
70 void ibv_wr_set_sge_list(struct ibv_qp_ex *qp, size_t num_sge,
71 const struct ibv_sge *sg_list);
72
73 void ibv_wr_set_ud_addr(struct ibv_qp_ex *qp, struct ibv_ah *ah,
74 uint32_t remote_qpn, uint32_t remote_qkey);
75 void ibv_wr_set_xrc_srqn(struct ibv_qp_ex *qp, uint32_t remote_srqn);
76 void ibv_wr_flush(struct ibv_qp_ex *qp, uint32_t rkey, uint64_t remote_addr,
77 size_t len, uint8_t type, uint8_t level);
78 ```
79
80 # DESCRIPTION
81
82 The verbs work request API (ibv_wr_\*) allows efficient posting of work to a send
83 queue using function calls instead of the struct based *ibv_post_send()*
84 scheme. This approach is designed to minimize CPU branching and locking during
85 the posting process.
86
87 This API is intended to be used to access additional functionality beyond
88 what is provided by *ibv_post_send()*.
89
90 WRs batches of *ibv_post_send()* and this API WRs batches can interleave
91 together just if they are not posted within the critical region of each other.
92 (A critical region in this API formed by *ibv_wr_start()* and
93 *ibv_wr_complete()*/*ibv_wr_abort()*)
94
95 # USAGE
96
97 To use these APIs the QP must be created using ibv_create_qp_ex() which allows
98 setting the **IBV_QP_INIT_ATTR_SEND_OPS_FLAGS** in *comp_mask*. The
99 *send_ops_flags* should be set to the OR of the work request types that will
100 be posted to the QP.
101
102 If the QP does not support all the requested work request types then QP
103 creation will fail.
104
105 Posting work requests to the QP is done within the critical region formed by
106 *ibv_wr_start()* and *ibv_wr_complete()*/*ibv_wr_abort()* (see CONCURRENCY below).
107
108 Each work request is created by calling a WR builder function (see the table
109 column WR builder below) to start creating the work request, followed by
110 allowed/required setter functions described below.
111
112 The WR builder and setter combination can be called multiple times to
113 efficiently post multiple work requests within a single critical region.
114
115 Each WR builder will use the *wr_id* member of *struct ibv_qp_ex* to set the
116 value to be returned in the completion. Some operations will also use the
117 *wr_flags* member to influence operation (see Flags below). These values
118 should be set before invoking the WR builder function.
119
120 For example a simple send could be formed as follows:
121
122 ```C
123 qpx->wr_id = 1;
124 ibv_wr_send(qpx);
125 ibv_wr_set_sge(qpx, lkey, &data, sizeof(data));
126 ```
127
128 The section WORK REQUESTS describes the various WR builders and setters in
129 details.
130
131 Posting work is completed by calling *ibv_wr_complete()* or *ibv_wr_abort()*.
132 No work is executed to the queue until *ibv_wr_complete()* returns
133 success. *ibv_wr_abort()* will discard all work prepared since *ibv_wr_start()*.
134
135 # WORK REQUESTS
136
137 Many of the operations match the opcodes available for *ibv_post_send()*. Each
138 operation has a WR builder function, a list of allowed setters, and a flag bit
139 to request the operation with *send_ops_flags* in *struct
140 ibv_qp_init_attr_ex* (see the EXAMPLE below).
141
142 | Operation | WR builder | QP Type Supported | setters |
143 |----------------------|---------------------------|----------------------------------|----------|
144 | ATOMIC_CMP_AND_SWP | ibv_wr_atomic_cmp_swp() | RC, XRC_SEND | DATA, QP |
145 | ATOMIC_FETCH_AND_ADD | ibv_wr_atomic_fetch_add() | RC, XRC_SEND | DATA, QP |
146 | BIND_MW | ibv_wr_bind_mw() | UC, RC, XRC_SEND | NONE |
147 | LOCAL_INV | ibv_wr_local_inv() | UC, RC, XRC_SEND | NONE |
148 | RDMA_READ | ibv_wr_rdma_read() | RC, XRC_SEND | DATA, QP |
149 | RDMA_WRITE | ibv_wr_rdma_write() | UC, RC, XRC_SEND | DATA, QP |
150 | FLUSH | ibv_wr_flush() | RC, RD, XRC_SEND | DATA, QP |
151 | RDMA_WRITE_WITH_IMM | ibv_wr_rdma_write_imm() | UC, RC, XRC_SEND | DATA, QP |
152 | SEND | ibv_wr_send() | UD, UC, RC, XRC_SEND, RAW_PACKET | DATA, QP |
153 | SEND_WITH_IMM | ibv_wr_send_imm() | UD, UC, RC, SRC SEND | DATA, QP |
154 | SEND_WITH_INV | ibv_wr_send_inv() | UC, RC, XRC_SEND | DATA, QP |
155 | TSO | ibv_wr_send_tso() | UD, RAW_PACKET | DATA, QP |
156
157
158 ## Atomic operations
159
160 Atomic operations are only atomic so long as all writes to memory go only
161 through the same RDMA hardware. It is not atomic with writes performed by the
162 CPU, or by other RDMA hardware in the system.
163
164 *ibv_wr_atomic_cmp_swp()*
165 : If the remote 64 bit memory location specified by *rkey* and *remote_addr*
166 equals *compare* then set it to *swap*.
167
168 *ibv_wr_atomic_fetch_add()*
169 : Add *add* to the 64 bit memory location specified *rkey* and *remote_addr*.
170
171 ## Memory Windows
172
173 Memory window type 2 operations (See man page for ibv_alloc_mw).
174
175 *ibv_wr_bind_mw()*
176 : Bind a MW type 2 specified by **mw**, set a new **rkey** and set its
177 properties by **bind_info**.
178
179 *ibv_wr_local_inv()*
180 : Invalidate a MW type 2 which is associated with **rkey**.
181
182 ## RDMA
183
184 *ibv_wr_rdma_read()*
185 : Read from the remote memory location specified *rkey* and
186 *remote_addr*. The number of bytes to read, and the local location to
187 store the data, is determined by the DATA buffers set after this call.
188
189 *ibv_wr_rdma_write()*, *ibv_wr_rdma_write_imm()*
190 : Write to the remote memory location specified *rkey* and
191 *remote_addr*. The number of bytes to read, and the local location to get
192 the data, is determined by the DATA buffers set after this call.
193
194 The _imm version causes the remote side to get a IBV_WC_RECV_RDMA_WITH_IMM
195 containing the 32 bits of immediate data.
196
197 ## Message Send
198
199 *ibv_wr_send()*, *ibv_wr_send_imm()*
200 : Send a message. The number of bytes to send, and the local location to get
201 the data, is determined by the DATA buffers set after this call.
202
203 The _imm version causes the remote side to get a IBV_WC_RECV_RDMA_WITH_IMM
204 containing the 32 bits of immediate data.
205
206 *ibv_wr_send_inv()*
207 : The data transfer is the same as for *ibv_wr_send()*, however the remote
208 side will invalidate the MR specified by *invalidate_rkey* before
209 delivering a completion.
210
211 *ibv_wr_send_tso()*
212 : Produce multiple SEND messages using TCP Segmentation Offload. The SGE
213 points to a TCP Stream buffer which will be segmented into
214 MSS size SENDs. The hdr includes the entire network headers up to and
215 including the TCP header and is prefixed before each segment.
216
217 ## QP Specific setters
218
219 Certain QP types require each post to be accompanied by additional setters,
220 these setters are mandatory for any operation listing a QP setter in the above
221 table.
222
223 *UD* QPs
224 : *ibv_wr_set_ud_addr()* must be called to set the destination address of
225 the work.
226
227 *XRC_SEND* QPs
228 : *ibv_wr_set_xrc_srqn()* must be called to set the destination SRQN field.
229
230 ## DATA transfer setters
231
232 For work that requires to transfer data one of the following setters should
233 be called once after the WR builder:
234
235 *ibv_wr_set_sge()*
236 : Transfer data to/from a single buffer given by the lkey, addr and
237 length. This is equivalent to *ibv_wr_set_sge_list()* with a single
238 element.
239
240 *ibv_wr_set_sge_list()*
241 : Transfer data to/from a list of buffers, logically concatenated
242 together. Each buffer is specified by an element in an array of *struct
243 ibv_sge*.
244
245 Inline setters will copy the send data during the setter and allows the caller
246 to immediately re-use the buffer. This behavior is identical to the
247 IBV_SEND_INLINE flag. Generally this copy is done in a way that optimizes
248 SEND latency and is suitable for small messages. The provider will limit the
249 amount of data it can support in a single operation. This limit is requested
250 in the *max_inline_data* member of *struct ibv_qp_init_attr*. Valid only
251 for SEND and RDMA_WRITE.
252
253 *ibv_wr_set_inline_data()*
254 : Copy send data from a single buffer given by the addr and length.
255 This is equivalent to *ibv_wr_set_inline_data_list()* with a single
256 element.
257
258 *ibv_wr_set_inline_data_list()*
259 : Copy send data from a list of buffers, logically concatenated
260 together. Each buffer is specified by an element in an array of *struct
261 ibv_inl_data*.
262
263 ## Flags
264
265 A bit mask of flags may be specified in *wr_flags* to control the behavior of
266 the work request.
267
268 **IBV_SEND_FENCE**
269 : Do not start this work request until prior work has completed.
270
271 **IBV_SEND_IP_CSUM**
272 : Offload the IPv4 and TCP/UDP checksum calculation
273
274 **IBV_SEND_SIGNALED**
275 : A completion will be generated in the completion queue for the operation.
276
277 **IBV_SEND_SOLICITED**
278 : Set the solicited bit in the RDMA packet. This informs the other side to
279 generate a completion event upon receiving the RDMA operation.
280
281 # CONCURRENCY
282
283 The provider will provide locking to ensure that *ibv_wr_start()* and
284 *ibv_wr_complete()/abort()* form a per-QP critical section where no other
285 threads can enter.
286
287 If an *ibv_td* is provided during QP creation then no locking will be performed
288 and it is up to the caller to ensure that only one thread can be within the
289 critical region at a time.
290
291 # RETURN VALUE
292
293 Applications should use this API in a way that does not create failures. The
294 individual APIs do not return a failure indication to avoid branching.
295
296 If a failure is detected during operation, for instance due to an invalid
297 argument, then *ibv_wr_complete()* will return failure and the entire posting
298 will be aborted.
299
300 # EXAMPLE
301
302 ```c
303 /* create RC QP type and specify the required send opcodes */
304 qp_init_attr_ex.qp_type = IBV_QPT_RC;
305 qp_init_attr_ex.comp_mask |= IBV_QP_INIT_ATTR_SEND_OPS_FLAGS;
306 qp_init_attr_ex.send_ops_flags |= IBV_QP_EX_WITH_RDMA_WRITE;
307 qp_init_attr_ex.send_ops_flags |= IBV_QP_EX_WITH_RDMA_WRITE_WITH_IMM;
308
309 ibv_qp *qp = ibv_create_qp_ex(ctx, qp_init_attr_ex);
310 ibv_qp_ex *qpx = ibv_qp_to_qp_ex(qp);
311
312 ibv_wr_start(qpx);
313
314 /* create 1st WRITE WR entry */
315 qpx->wr_id = my_wr_id_1;
316 ibv_wr_rdma_write(qpx, rkey, remote_addr_1);
317 ibv_wr_set_sge(qpx, lkey, local_addr_1, length_1);
318
319 /* create 2nd WRITE_WITH_IMM WR entry */
320 qpx->wr_id = my_wr_id_2;
321 qpx->wr_flags = IBV_SEND_SIGNALED;
322 ibv_wr_rdma_write_imm(qpx, rkey, remote_addr_2, htonl(0x1234));
323 ibv_set_wr_sge(qpx, lkey, local_addr_2, length_2);
324
325 /* Begin processing WRs */
326 ret = ibv_wr_complete(qpx);
327 ```
328
329 # SEE ALSO
330
331 **ibv_post_send**(3), **ibv_create_qp_ex(3)**.
332
333 # AUTHOR
334
335 Jason Gunthorpe <[email protected]>
336 Guy Levi <[email protected]>