Skip to content

Commit

Permalink
Merge pull request #26 from YtvwlD/gid
Browse files Browse the repository at this point in the history
Make the Endpoint fields accessible and the Gid optional
  • Loading branch information
jonhoo authored Jan 28, 2024
2 parents e6fc6dd + 5598ab8 commit dbb3bd3
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions ibverbs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ pub struct PreparedQueuePair<'res> {
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Default, Copy, Clone, Debug, Eq, PartialEq, Hash)]
#[repr(transparent)]
struct Gid {
pub struct Gid {
raw: [u8; 16],
}

Expand Down Expand Up @@ -914,9 +914,12 @@ impl AsMut<ffi::ibv_gid> for Gid {
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct QueuePairEndpoint {
num: u32,
lid: u16,
gid: Gid,
/// the `QueuePair`'s `qp_num`
pub num: u32,
/// the context's `lid`
pub lid: u16,
/// the context's `gid`, used for global routing
pub gid: Option<Gid>,
}

impl<'res> PreparedQueuePair<'res> {
Expand All @@ -929,7 +932,7 @@ impl<'res> PreparedQueuePair<'res> {
QueuePairEndpoint {
num,
lid: self.ctx.port_attr.lid,
gid: self.ctx.gid,
gid: Some(self.ctx.gid),
}
}

Expand All @@ -939,6 +942,12 @@ impl<'res> PreparedQueuePair<'res> {
/// (`IBV_QPS_INIT`), ready to receive (`IBV_QPS_RTR`), and ready to send (`IBV_QPS_RTS`).
/// Further discussion of the protocol can be found on [RDMAmojo].
///
/// If the endpoint contains a Gid, the routing will be global. This means:
/// ```text,ignore
/// ah_attr.is_global = 1;
/// ah_attr.grh.hop_limit = 0xff;
/// ```
///
/// The handshake also sets the following parameters, which are currently not configurable:
///
/// # Examples
Expand All @@ -953,9 +962,7 @@ impl<'res> PreparedQueuePair<'res> {
/// max_rd_atomic = 1;
///
/// ah_attr.sl = 0;
/// ah_attr.is_global = 1;
/// ah_attr.src_path_bits = 0;
/// ah_attr.grh.hop_limit = 0xff;
/// ```
///
/// # Errors
Expand Down Expand Up @@ -991,20 +998,20 @@ impl<'res> PreparedQueuePair<'res> {
max_dest_rd_atomic: 1,
min_rnr_timer: self.min_rnr_timer,
ah_attr: ffi::ibv_ah_attr {
is_global: 1,
dlid: remote.lid,
sl: 0,
src_path_bits: 0,
port_num: PORT_NUM,
grh: ffi::ibv_global_route {
dgid: remote.gid.into(),
hop_limit: 0xff,
..Default::default()
},
grh: Default::default(),
..Default::default()
},
..Default::default()
};
if let Some(gid) = remote.gid {
attr.ah_attr.is_global = 1;
attr.ah_attr.grh.dgid = gid.into();
attr.ah_attr.grh.hop_limit = 0xff;
}
let mask = ffi::ibv_qp_attr_mask::IBV_QP_STATE
| ffi::ibv_qp_attr_mask::IBV_QP_AV
| ffi::ibv_qp_attr_mask::IBV_QP_PATH_MTU
Expand Down Expand Up @@ -1399,16 +1406,17 @@ mod test_serde {
let qpe_default = QueuePairEndpoint {
num: 72,
lid: 9,
gid: Default::default(),
gid: Some(Default::default()),
};

let mut qpe = qpe_default;
qpe.gid.raw = unsafe { std::mem::transmute([87_u64.to_be(), 192_u64.to_be()]) };
qpe.gid.as_mut().unwrap().raw =
unsafe { std::mem::transmute([87_u64.to_be(), 192_u64.to_be()]) };
let encoded = bincode::serialize(&qpe).unwrap();

let decoded: QueuePairEndpoint = bincode::deserialize(&encoded).unwrap();
assert_eq!(decoded.gid.subnet_prefix(), 87);
assert_eq!(decoded.gid.interface_id(), 192);
assert_eq!(decoded.gid.unwrap().subnet_prefix(), 87);
assert_eq!(decoded.gid.unwrap().interface_id(), 192);
assert_eq!(qpe, decoded);
assert_ne!(qpe, qpe_default);
}
Expand Down

0 comments on commit dbb3bd3

Please sign in to comment.