1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use crate::channel::Channel;
use crate::channel::pending_work::PendingWork;
use crate::ibverbs::error::IbvResult;
use crate::ibverbs::work::{
ReadWorkRequest, ReceiveWorkRequest, SendWorkRequest, WriteWorkRequest,
};
impl Channel {
/// Posts a send operation without polling for completion.
///
/// # Safety
/// The returned [`PendingWork`] must not be leaked (e.g. via [`mem::forget`](std::mem::forget)),
/// as this would end the borrow without dropping while the hardware may still access the memory.
/// Prefer [`scope`](Channel::scope) or [`manual_scope`](Channel::manual_scope) which prevent this.
pub unsafe fn send_unpolled<'data>(
&mut self,
wr: SendWorkRequest<'_, 'data>,
) -> IbvResult<PendingWork<'data>> {
let wr_id = self.get_and_advance_wr_id();
unsafe { self.qp.post_send(wr, wr_id)? };
Ok(unsafe { PendingWork::new(wr_id, self.cq.clone()) })
}
/// Posts a receive operation without polling for completion.
///
/// # Safety
/// The returned [`PendingWork`] must not be leaked (e.g. via [`mem::forget`](std::mem::forget)),
/// as this would end the borrow without dropping while the hardware may still access the memory.
/// Prefer [`scope`](Channel::scope) or [`manual_scope`](Channel::manual_scope) which prevent this.
pub unsafe fn receive_unpolled<'data>(
&mut self,
wr: ReceiveWorkRequest<'_, 'data>,
) -> IbvResult<PendingWork<'data>> {
let wr_id = self.get_and_advance_wr_id();
unsafe { self.qp.post_receive(wr, wr_id)? };
Ok(unsafe { PendingWork::new(wr_id, self.cq.clone()) })
}
/// Posts an RDMA write operation without polling for completion.
///
/// # Safety
/// The returned [`PendingWork`] must not be leaked (e.g. via [`mem::forget`](std::mem::forget)),
/// as this would end the borrow without dropping while the hardware may still access the memory.
/// Prefer [`scope`](Channel::scope) or [`manual_scope`](Channel::manual_scope) which prevent this.
pub unsafe fn write_unpolled<'data>(
&mut self,
wr: WriteWorkRequest<'_, 'data>,
) -> IbvResult<PendingWork<'data>> {
let wr_id = self.get_and_advance_wr_id();
unsafe { self.qp.post_write(wr, wr_id)? };
Ok(unsafe { PendingWork::new(wr_id, self.cq.clone()) })
}
/// Posts an RDMA read operation without polling for completion.
///
/// # Safety
/// The returned [`PendingWork`] must not be leaked (e.g. via [`mem::forget`](std::mem::forget)),
/// as this would end the borrow without dropping while the hardware may still access the memory.
/// Prefer [`scope`](Channel::scope) or [`manual_scope`](Channel::manual_scope) which prevent this.
pub unsafe fn read_unpolled<'data>(
&mut self,
wr: ReadWorkRequest<'_, 'data>,
) -> IbvResult<PendingWork<'data>> {
let wr_id = self.get_and_advance_wr_id();
unsafe { self.qp.post_read(wr, wr_id)? };
Ok(unsafe { PendingWork::new(wr_id, self.cq.clone()) })
}
fn get_and_advance_wr_id(&mut self) -> u64 {
let wr_id = self.next_wr_id;
self.next_wr_id += 1;
wr_id
}
}