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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! Queue pair — the communication endpoint for RDMA operations.
//!
//! # The Communication Endpoint
//!
//! A [`QueuePair`] is the fundamental object used to send and receive data in RDMA.
//!
//! # Key Relationships
//!
//! * **Protection Domain (PD)** — A QP is created within a specific [`ProtectionDomain`].
//! **Crucial Rule**: You can only use [`MemoryRegion`](crate::ibverbs::memory::MemoryRegion)s
//! that were registered in the *same* PD. Mixing PDs will cause immediate errors.
//!
//! * **Completion Queues (CQ)** — A QP is associated with two Completion Queues (which can be the same object):
//! * **Send CQ** — Receives completions for outgoing operations (Send, Write, Read).
//! * **Recv CQ** — Receives completions for incoming operations (Receive).
//! * *Note*: When an operation finishes, the hardware places a [`WorkCompletion`](crate::ibverbs::work::WorkCompletion)
//! into the corresponding CQ. You must poll that CQ to see the result.
//!
//! # Usage: The Post-and-Poll Model
//!
//! Using a Queue Pair follows a strict asynchronous pattern:
//!
//! 1. **Post**: You submit a work request using methods like [`post_send`](QueuePair::post_send).
//! This method returns immediately (non-blocking).
//! 2. **Execute**: The hardware processes the request asynchronously in the background.
//! 3. **Complete**: Eventually, a completion event appears in the associated CQ. You poll the CQ
//! using the `wr_id` you assigned to retrieve the result.
//!
//! # Safety Model
//!
//! The `post_*` methods are **`unsafe`** because they do not enforce buffer lifetime safety automatically.
//!
//! ## The Contract
//!
//! When you create a [`WorkRequest`](crate::ibverbs::work), the [`GatherElement`](crate::ibverbs::memory::GatherElement)
//! and [`ScatterElement`](crate::ibverbs::memory::ScatterElement) types capture the lifetime of your data buffers
//! through Rust's borrow checker. However, **the `QueuePair` does not return a handle** that ties this
//! lifetime to the completion of the operation.
//!
//! **It is your responsibility to**:
//! 1. Keep the data buffers alive until the operation completes.
//! 2. Not mutate (for Send/Write) or access (for Receive/Read) the buffers while the hardware owns them.
//! 3. Poll the appropriate Completion Queue using the `wr_id` to know when the operation finishes.
//!
//! Only after you receive the [`WorkCompletion`](crate::ibverbs::work::WorkCompletion) is it safe to
//! alias, drop, reuse, or modify the buffers.
//!
//! ## Safe Abstractions
//!
//! A higher-level abstraction [`Channel`](crate::channel::Channel) wraps these `unsafe` methods and enforces
//! the lifetime contract by returning a future or handle that must be awaited/polled before the
//! buffers are released.
use crateCompletionQueue;
use crateIbvError;
use crateProtectionDomain;
use ;
use Debug;
/// An RDMA Queue Pair.
///
/// This struct manages the lifecycle of the QP resource. It holds strong references to its
/// dependencies ([`ProtectionDomain`] and [`CompletionQueue`]) to ensure they remain
/// allocated as long as this QP exists.
/// SAFETY: libibverbs resources are thread-safe.
unsafe
/// SAFETY: libibverbs resources are thread-safe.
unsafe