Initial commit

This commit is contained in:
redclawsystems
2026-03-04 00:08:42 +00:00
commit 4d88dc0584
4449 changed files with 1556714 additions and 0 deletions
@@ -0,0 +1,414 @@
//! IBverbs FFI bindings for RDMA operations
use std::ffi::c_void;
/// Opaque device context handle
pub type IbvContext = *mut c_void;
/// Opaque protection domain handle
pub type IbvPd = *mut c_void;
/// Opaque completion queue handle
pub type IbvCq = *mut c_void;
/// Opaque queue pair handle
pub type IbvQp = *mut c_void;
/// Opaque memory region handle
pub type IbvMr = *mut c_void;
/// Opaque device handle
pub type IbvDevice = *mut c_void;
/// Opaque address handle
pub type IbvAh = *mut c_void;
/// IBverbs device attributes
#[repr(C)]
#[derive(Debug, Clone)]
pub struct IbvDeviceAttr {
pub fw_ver: [u8; 64],
pub node_guid: u64,
pub sys_image_guid: u64,
pub max_mr_size: u64,
pub page_size_cap: u64,
pub vendor_id: u32,
pub vendor_part_id: u32,
pub hw_ver: u32,
pub max_qp: i32,
pub max_qp_wr: i32,
pub device_cap_flags: u64,
pub max_sge: i32,
pub max_sge_rd: i32,
pub max_cq: i32,
pub max_cqe: i32,
pub max_mr: i32,
pub max_pd: i32,
pub max_qp_rd_atom: i32,
pub max_ee_rd_atom: i32,
pub max_res_rd_atom: i32,
pub max_qp_init_rd_atom: i32,
pub max_ee_init_rd_atom: i32,
pub atomic_cap: i32,
pub max_ee: i32,
pub max_rdd: i32,
pub max_mw: i32,
pub max_raw_ipv6_qp: i32,
pub max_raw_ethy_qp: i32,
pub max_mcast_grp: i32,
pub max_mcast_qp_attach: i32,
pub max_total_mcast_qp_attach: i32,
pub max_ah: i32,
pub max_fmr: i32,
pub max_map_per_fmr: i32,
pub max_srq: i32,
pub max_srq_wr: i32,
pub max_srq_sge: i32,
pub max_pkeys: u16,
pub local_ca_ack_delay: u8,
pub phys_port_cnt: u8,
}
impl Default for IbvDeviceAttr {
fn default() -> Self {
Self {
fw_ver: [0u8; 64],
node_guid: 0,
sys_image_guid: 0,
max_mr_size: 0,
page_size_cap: 0,
vendor_id: 0,
vendor_part_id: 0,
hw_ver: 0,
max_qp: 0,
max_qp_wr: 0,
device_cap_flags: 0,
max_sge: 0,
max_sge_rd: 0,
max_cq: 0,
max_cqe: 0,
max_mr: 0,
max_pd: 0,
max_qp_rd_atom: 0,
max_ee_rd_atom: 0,
max_res_rd_atom: 0,
max_qp_init_rd_atom: 0,
max_ee_init_rd_atom: 0,
atomic_cap: 0,
max_ee: 0,
max_rdd: 0,
max_mw: 0,
max_raw_ipv6_qp: 0,
max_raw_ethy_qp: 0,
max_mcast_grp: 0,
max_mcast_qp_attach: 0,
max_total_mcast_qp_attach: 0,
max_ah: 0,
max_fmr: 0,
max_map_per_fmr: 0,
max_srq: 0,
max_srq_wr: 0,
max_srq_sge: 0,
max_pkeys: 0,
local_ca_ack_delay: 0,
phys_port_cnt: 0,
}
}
}
/// IBverbs port attributes
#[repr(C)]
#[derive(Debug, Clone, Default)]
pub struct IbvPortAttr {
pub state: u32,
pub max_mtu: u32,
pub active_mtu: u32,
pub gid_tbl_len: i32,
pub port_cap_flags: u32,
pub max_msg_sz: u32,
pub bad_pkey_cntr: u32,
pub qkey_viol_cntr: u32,
pub pkey_tbl_len: u16,
pub lid: u16,
pub sm_lid: u16,
pub lmc: u8,
pub max_vl_num: u8,
pub sm_sl: u8,
pub subnet_timeout: u8,
pub init_type_reply: u8,
pub active_width: u8,
pub active_speed: u8,
pub phys_state: u8,
pub link_layer: u8,
pub flags: u8,
pub port_cap_flags2: u16,
}
/// IBverbs GID
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct IbvGid {
pub raw: [u8; 16],
}
/// IBverbs queue pair initialization attributes
#[repr(C)]
#[derive(Debug, Clone)]
pub struct IbvQpInitAttr {
pub qp_context: *mut c_void,
pub send_cq: IbvCq,
pub recv_cq: IbvCq,
pub srq: *mut c_void,
pub cap: IbvQpCap,
pub qp_type: i32,
pub sq_sig_all: i32,
}
/// IBverbs QP capabilities
#[repr(C)]
#[derive(Debug, Clone, Default)]
pub struct IbvQpCap {
pub max_send_wr: u32,
pub max_recv_wr: u32,
pub max_send_sge: u32,
pub max_recv_sge: u32,
pub max_inline_data: u32,
}
/// IBverbs QP attributes for modification
#[repr(C)]
#[derive(Debug, Clone)]
pub struct IbvQpAttr {
pub qp_state: i32,
pub cur_qp_state: i32,
pub path_mtu: i32,
pub path_mig_state: i32,
pub qkey: u32,
pub rq_psn: u32,
pub sq_psn: u32,
pub dest_qp_num: u32,
pub qp_access_flags: i32,
pub cap: IbvQpCap,
pub ah_attr: IbvAhAttr,
pub alt_ah_attr: IbvAhAttr,
pub pkey_index: u16,
pub alt_pkey_index: u16,
pub en_sqd_async_notify: u8,
pub sq_draining: u8,
pub max_rd_atomic: u8,
pub max_dest_rd_atomic: u8,
pub min_rnr_timer: u8,
pub port_num: u8,
pub timeout: u8,
pub retry_cnt: u8,
pub rnr_retry: u8,
pub alt_port_num: u8,
pub alt_timeout: u8,
pub rate_limit: u32,
}
/// IBverbs Address Handle attributes
#[repr(C)]
#[derive(Debug, Clone, Default)]
pub struct IbvAhAttr {
pub grh: IbvGlobalRoute,
pub dlid: u16,
pub sl: u8,
pub src_path_bits: u8,
pub static_rate: u8,
pub is_global: u8,
pub port_num: u8,
}
/// IBverbs Global Route Header
#[repr(C)]
#[derive(Debug, Clone, Default)]
pub struct IbvGlobalRoute {
pub dgid: IbvGid,
pub flow_label: u32,
pub sgid_index: u8,
pub hop_limit: u8,
pub traffic_class: u8,
}
/// IBverbs Send Work Request
#[repr(C)]
#[derive(Debug, Clone)]
pub struct IbvSendWr {
pub wr_id: u64,
pub next: *mut IbvSendWr,
pub sg_list: *mut IbvSge,
pub num_sge: i32,
pub opcode: i32,
pub send_flags: u32,
pub imm_data_invalidated_rkey: u32,
// Union fields for different operations
pub wr: IbvWrUnion,
}
/// Union for work request specific data
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct IbvWrUnion {
pub rdma_remote_addr: u64,
pub rdma_rkey: u32,
pub _padding: u32,
}
/// IBverbs Receive Work Request
#[repr(C)]
#[derive(Debug, Clone)]
pub struct IbvRecvWr {
pub wr_id: u64,
pub next: *mut IbvRecvWr,
pub sg_list: *mut IbvSge,
pub num_sge: i32,
}
/// IBverbs Scatter/Gather Entry
#[repr(C)]
#[derive(Debug, Clone, Copy, Default)]
pub struct IbvSge {
pub addr: u64,
pub length: u32,
pub lkey: u32,
}
/// IBverbs Work Completion
#[repr(C)]
#[derive(Debug, Clone, Default)]
pub struct IbvWc {
pub wr_id: u64,
pub status: i32,
pub opcode: i32,
pub vendor_err: u32,
pub byte_len: u32,
pub imm_data_invalidated_rkey: u32,
pub qp_num: u32,
pub src_qp: u32,
pub wc_flags: u32,
pub pkey_index: u16,
pub slid: u16,
pub sl: u8,
pub dlid_path_bits: u8,
}
/// Work completion status codes
pub mod wc_status {
pub const IBV_WC_SUCCESS: i32 = 0;
pub const IBV_WC_LOC_LEN_ERR: i32 = 1;
pub const IBV_WC_LOC_QP_OP_ERR: i32 = 2;
pub const IBV_WC_LOC_EEC_OP_ERR: i32 = 3;
pub const IBV_WC_LOC_PROT_ERR: i32 = 4;
pub const IBV_WC_WR_FLUSH_ERR: i32 = 5;
pub const IBV_WC_MW_BIND_ERR: i32 = 6;
pub const IBV_WC_BAD_RESP_ERR: i32 = 7;
pub const IBV_WC_LOC_ACCESS_ERR: i32 = 8;
pub const IBV_WC_REM_INV_REQ_ERR: i32 = 9;
pub const IBV_WC_REM_ACCESS_ERR: i32 = 10;
pub const IBV_WC_REM_OP_ERR: i32 = 11;
pub const IBV_WC_RETRY_EXC_ERR: i32 = 12;
pub const IBV_WC_RNR_RETRY_EXC_ERR: i32 = 13;
}
/// QP state constants
pub mod qp_state {
pub const IBV_QPS_RESET: i32 = 0;
pub const IBV_QPS_INIT: i32 = 1;
pub const IBV_QPS_RTR: i32 = 2;
pub const IBV_QPS_RTS: i32 = 3;
pub const IBV_QPS_SQD: i32 = 4;
pub const IBV_QPS_SQE: i32 = 5;
pub const IBV_QPS_ERR: i32 = 6;
}
/// QP type constants
pub mod qp_type {
pub const IBV_QPT_RC: i32 = 2;
pub const IBV_QPT_UC: i32 = 3;
pub const IBV_QPT_UD: i32 = 4;
}
/// WR opcode constants
pub mod wr_opcode {
pub const IBV_WR_RDMA_WRITE: i32 = 0;
pub const IBV_WR_RDMA_WRITE_WITH_IMM: i32 = 1;
pub const IBV_WR_SEND: i32 = 2;
pub const IBV_WR_SEND_WITH_IMM: i32 = 3;
pub const IBV_WR_RDMA_READ: i32 = 4;
pub const IBV_WR_ATOMIC_CMP_AND_SWP: i32 = 5;
pub const IBV_WR_ATOMIC_FETCH_AND_ADD: i32 = 6;
}
/// Send flags
pub mod send_flags {
pub const IBV_SEND_FENCE: u32 = 1;
pub const IBV_SEND_SIGNALED: u32 = 2;
pub const IBV_SEND_SOLICITED: u32 = 4;
pub const IBV_SEND_INLINE: u32 = 8;
}
/// Access flags for memory registration
pub mod access_flags {
pub const IBV_ACCESS_LOCAL_WRITE: i32 = 1;
pub const IBV_ACCESS_REMOTE_WRITE: i32 = 2;
pub const IBV_ACCESS_REMOTE_READ: i32 = 4;
pub const IBV_ACCESS_REMOTE_ATOMIC: i32 = 8;
}
/// QP attribute mask
pub mod qp_attr_mask {
pub const IBV_QP_STATE: i32 = 1 << 0;
pub const IBV_QP_CUR_STATE: i32 = 1 << 1;
pub const IBV_QP_EN_SQD_ASYNC_NOTIFY: i32 = 1 << 2;
pub const IBV_QP_ACCESS_FLAGS: i32 = 1 << 3;
pub const IBV_QP_PKEY_INDEX: i32 = 1 << 4;
pub const IBV_QP_PORT: i32 = 1 << 5;
pub const IBV_QP_QKEY: i32 = 1 << 6;
pub const IBV_QP_AV: i32 = 1 << 7;
pub const IBV_QP_PATH_MTU: i32 = 1 << 8;
pub const IBV_QP_TIMEOUT: i32 = 1 << 9;
pub const IBV_QP_RETRY_CNT: i32 = 1 << 10;
pub const IBV_QP_RNR_RETRY: i32 = 1 << 11;
pub const IBV_QP_RQ_PSN: i32 = 1 << 12;
pub const IBV_QP_MAX_QP_RD_ATOMIC: i32 = 1 << 13;
pub const IBV_QP_ALT_PATH: i32 = 1 << 14;
pub const IBV_QP_MIN_RNR_TIMER: i32 = 1 << 15;
pub const IBV_QP_SQ_PSN: i32 = 1 << 16;
pub const IBV_QP_MAX_DEST_RD_ATOMIC: i32 = 1 << 17;
pub const IBV_QP_PATH_MIG_STATE: i32 = 1 << 18;
pub const IBV_QP_CAP: i32 = 1 << 19;
pub const IBV_QP_DEST_QPN: i32 = 1 << 20;
pub const IBV_QP_RATE_LIMIT: i32 = 1 << 25;
}
// FFI function declarations
#[cfg(feature = "rdma")]
unsafe extern "C" {
pub fn ibv_get_device_list(num_devices: *mut i32) -> *mut *mut IbvDevice;
pub fn ibv_free_device_list(list: *mut *mut IbvDevice);
pub fn ibv_get_device_name(device: IbvDevice) -> *const i8;
pub fn ibv_open_device(device: IbvDevice) -> IbvContext;
pub fn ibv_close_device(context: IbvContext) -> i32;
pub fn ibv_query_device(context: IbvContext, device_attr: *mut IbvDeviceAttr) -> i32;
pub fn ibv_query_port(context: IbvContext, port_num: u8, port_attr: *mut IbvPortAttr) -> i32;
pub fn ibv_query_gid(context: IbvContext, port_num: u8, index: i32, gid: *mut IbvGid) -> i32;
pub fn ibv_alloc_pd(context: IbvContext) -> IbvPd;
pub fn ibv_dealloc_pd(pd: IbvPd) -> i32;
pub fn ibv_create_cq(
context: IbvContext,
cqe: i32,
cq_context: *mut c_void,
channel: *mut c_void,
comp_vector: i32,
) -> IbvCq;
pub fn ibv_destroy_cq(cq: IbvCq) -> i32;
pub fn ibv_create_qp(pd: IbvPd, qp_init_attr: *mut IbvQpInitAttr) -> IbvQp;
pub fn ibv_destroy_qp(qp: IbvQp) -> i32;
pub fn ibv_modify_qp(qp: IbvQp, attr: *mut IbvQpAttr, attr_mask: i32) -> i32;
pub fn ibv_reg_mr(pd: IbvPd, addr: *mut c_void, length: usize, access: i32) -> IbvMr;
pub fn ibv_dereg_mr(mr: IbvMr) -> i32;
pub fn ibv_post_send(qp: IbvQp, wr: *mut IbvSendWr, bad_wr: *mut *mut IbvSendWr) -> i32;
pub fn ibv_post_recv(qp: IbvQp, wr: *mut IbvRecvWr, bad_wr: *mut *mut IbvRecvWr) -> i32;
pub fn ibv_poll_cq(cq: IbvCq, num_entries: i32, wc: *mut IbvWc) -> i32;
}