分析对象:
- 规范 :《InfiniBandTM Architecture Specification Volume 1 Release 1.4》(2020-04-07)第 3 章 Architectural Overview
- 实现 :MLNX_OFED_SRC-24.10-5.1.6.1 / SOURCES / rdma-core-2410mlnx54
1. 总体映射关系
IB Spec Chapter 3 从宏观上定义了 InfiniBand 架构的:
- 拓扑与组件(Endnode、Switch、Router、SM、SMA)
- 通信模型(Queue Pair、Work Queue、WQE、CQE、WR)
- 分层架构(Physical → Link → Network → Transport → ULP)
- 核心特性(Service Types、Keys、Protection Domains、Partitions、Virtual Lanes、QoS、Multicast、Verbs)
- 管理基础设施(MAD、SMP、GSI、Fabric Initialization、Directed Routing)
在 rdma-core-2410mlnx54 中,这些概念主要分布在:
libibverbs/------ 对应 Verbs API、QP/CQ/PD/MR/MW/AH/SRQ 等核心对象生命周期与操作libibumad/------ 对应管理基础设施(MAD、QP0/QP1、SM/SA 交互、Directed Routing)kernel-headers/------ 对应内核-用户态 ABI,将 IB 架构对象映射为UVERBS_OBJECT_*和 ioctl/write 命令infiniband-diags/------ 对应诊断与管理工具(smpquery、saquery、ibtracert、ibroute等)
2. 拓扑与组件(3.1、3.4)
2.1 规范要点
- IBA 子网由 Endnode(HCA/TCA)、Switch、Router、Link 组成
- **Channel Adapter(CA)**是生成/消费报文的端节点,分为 HCA(处理器节点)和 TCA(I/O 节点)
- Switch基于 DLID 进行单播/组播报文转发
- Router负责跨子网路由,替换 Local Route Header(LRH)
- **Subnet Manager(SM)**负责拓扑发现、LID 分配、转发表配置
- **Subnet Management Agent(SMA)**是每个节点上响应 SMP(QP0)的代理
- **General Service Agent(GSA)**响应 GMP(QP1),包括 SA、CM、PerfMgt 等
2.2 rdma-core 实现映射
| 规范概念 | rdma-core 实现 | 关键文件/结构/函数 |
|---|---|---|
| HCA / Device | struct ibv_device、struct ibv_context |
libibverbs/verbs.h(ibv_device、ibv_context) libibverbs/device.c:ibv_get_device_list()、ibv_open_device() |
| Node Type(CA/Switch/Router) | enum ibv_node_type |
libibverbs/verbs.h:IBV_NODE_CA、IBV_NODE_SWITCH、IBV_NODE_ROUTER |
| 设备发现(sysfs / netlink) | RDMA_NLDEV_CMD_GET |
libibverbs/ibdev_nl.c:find_sysfs_devs_nl()、find_uverbs_nl() kernel-headers/rdma/rdma_netlink.h |
| Switch / Router(管理面) | infiniband-diags 工具 |
ibroute.c:读取 Switch LFT/MFT ibtracert.c:逐跳追踪路径 smpquery.c:查询 NodeInfo/PortInfo/SwitchInfo |
| SM / SMA | libibumad + infiniband-diags |
libibumad/umad.c:umad_open_smi_port()(QP0) infiniband-diags/sminfo.c:查询 SMInfo infiniband-diags/smpdump.c:原始 SMP 收发 |
| GSA / GSI | libibumad + saquery / srp_daemon |
libibumad/umad.c:umad_open_port()(QP1) libibumad/umad_sa.h:umad_sa_packet infiniband-diags/saquery.c:SA 查询工具 |
3. 通信模型与工作队列(3.2、3.5.1、3.6)
3.1 规范要点
- **Queue Pair(QP)**是通信端点,由 Send Queue 和 Receive Queue 组成
- **Work Queue Element(WQE)**是硬件执行的指令,由 Work Request(WR)入队产生
- **Completion Queue Element(CQE)**在 WQE 完成后放入 Completion Queue(CQ),通知消费者
- Channel Semantics:Send/Receive 双边操作
- Memory Semantics:RDMA Read/Write/Atomic 单边操作
- Memory Binding:将 Memory Window 绑定到 Memory Region 的子集,生成 R_Key
3.2 rdma-core 实现映射
3.2.1 Queue Pair(QP)
| 规范概念 | rdma-core 实现 | 关键文件/结构/函数 |
|---|---|---|
| QP 对象 | struct ibv_qp |
libibverbs/verbs.h:含 context、pd、send_cq、recv_cq、srq、qp_num、state、qp_type |
| 扩展 QP | struct ibv_qp_ex |
libibverbs/verbs.h:支持 builder-style WR 构造(wr_start、wr_rdma_write、wr_send、wr_atomic_cmp_swp 等) |
| QP 类型(Service Type) | enum ibv_qp_type |
libibverbs/verbs.h:IBV_QPT_RC、IBV_QPT_UC、IBV_QPT_UD、IBV_QPT_RAW_PACKET、IBV_QPT_XRC_SEND、IBV_QPT_XRC_RECV |
| QP 状态机 | enum ibv_qp_state |
libibverbs/verbs.h:RESET、INIT、RTR、RTS、SQD、SQE、ERR、UNKNOWN |
| 创建 QP | ibv_create_qp() / ibv_create_qp_ex() |
libibverbs/verbs.c(ibv_create_qp) libibverbs/cmd_qp.c:ibv_icmd_create_qp() → UVERBS_OBJECT_QP |
| 修改 QP | ibv_modify_qp() |
libibverbs/verbs.c:ibv_modify_qp(),更新 qp_state、path_mtu、dest_qp_num、ah_attr 等 |
| 销毁 QP | ibv_destroy_qp() |
libibverbs/verbs.c / cmd_qp.c:ibv_cmd_destroy_qp() |
| QP 属性 | struct ibv_qp_attr |
libibverbs/verbs.h:含 qp_state、qkey、psn、dest_qp_num、ah_attr、alt_ah_attr、pkey_index 等 |
| QP 能力 | struct ibv_qp_cap |
libibverbs/verbs.h:max_send_wr、max_recv_wr、max_send_sge、max_recv_sge、max_inline_data |
关联说明 :Spec 3.2.1 指出 WQE 和 CQE 并非架构实体,只有 WR Verbs 是架构化的。rdma-core 中
ibv_send_wr、ibv_recv_wr、ibv_sge正是用户态 WR 的具象化,而 WQE/CQE 隐藏在 HCA 硬件/驱动内部。
3.2.2 Completion Queue(CQ)
| 规范概念 | rdma-core 实现 | 关键文件/结构/函数 |
|---|---|---|
| CQ 对象 | struct ibv_cq / struct ibv_cq_ex |
libibverbs/verbs.h:含 context、cqe、handle;扩展版支持 start_poll/next_poll |
| 创建 CQ | ibv_create_cq() / ibv_create_cq_ex() |
libibverbs/verbs.c / cmd_cq.c:ibv_icmd_create_cq() → UVERBS_OBJECT_CQ |
| 轮询 CQ | ibv_poll_cq() |
libibverbs/verbs.h(inline):分发到 cq->context->ops.poll_cq() |
| 请求通知 | ibv_req_notify_cq() |
libibverbs/verbs.h(inline):分发到 ops.req_notify_cq() |
| 销毁 CQ | ibv_destroy_cq() |
libibverbs/verbs.c / cmd_cq.c:ibv_cmd_destroy_cq() |
3.2.3 Work Request(WR)与操作码
| 规范操作 | WR Opcode(enum ibv_wr_opcode) |
关键说明 |
|---|---|---|
| SEND(Channel) | IBV_WR_SEND / IBV_WR_SEND_WITH_IMM |
libibverbs/verbs.h:ibv_send_wr.opcode |
| RDMA WRITE | IBV_WR_RDMA_WRITE / IBV_WR_RDMA_WRITE_WITH_IMM |
包含 rdma.remote_addr、rdma.rkey |
| RDMA READ | IBV_WR_RDMA_READ |
单边读远程内存 |
| ATOMIC(CmpSwp / FetchAdd) | IBV_WR_ATOMIC_CMP_AND_SWP / IBV_WR_ATOMIC_FETCH_AND_ADD |
Spec 3.6.1 描述的 64-bit 原子操作 |
| Memory Bind(MW) | IBV_WR_BIND_MW |
将 MW 绑定到 MR 子集,生成新 R_Key |
| Post Send/Recv | ibv_post_send() / ibv_post_recv() |
libibverbs/verbs.h(inline)→ ops.post_send() / ops.post_recv() |
| Scatter-Gather Element | struct ibv_sge |
addr、length、lkey;对应 Spec 中的 Gather/Scatter List |
4. IBA 分层架构(3.7)
4.1 规范要点
| 层级 | 功能 |
|---|---|
| Physical Layer | 链路物理传输(光电信号、训练状态机) |
| Link Layer | 本地路由(LRH)、VL、SL、P_Key、流控、ICRC/VCRC |
| Network Layer | 全局路由(GRH)、GID、子网间路由 |
| Transport Layer | BTH、分段/重组、PSN、ACK/NAK、端到端流控、RDMA/Atomic 操作 |
| Upper Layer Protocols | Subnet Management(SMP)、General Services(SA/CM/PerfMgt) |
4.2 rdma-core 实现映射
| 层级 | 规范字段/机制 | rdma-core 实现 | 关键文件/结构 |
|---|---|---|---|
| Physical | Port 速度/宽度、物理状态 | ib_uverbs_query_port_resp |
kernel-headers/rdma/ib_user_verbs.h:active_width、active_speed、phys_state、max_mtu |
| Link | LID、SL、P_Key | struct ibv_ah_attr |
libibverbs/verbs.h:dlid、sl、src_path_bits、static_rate、port_num |
| Link | Partition Key | pkey_index、pkey |
libibverbs/verbs.h:QP/SRQ 属性中的 pkey_index;umad_port_t 中的 pkeys |
| Network | GID、GRH | struct ibv_global_route |
libibverbs/verbs.h:dgid、sgid_index、hop_limit、traffic_class、flow_label |
| Network | GID 表查询 | ib_uverbs_gid_entry |
kernel-headers/rdma/ib_user_verbs.h:gid、gid_index、gid_type(IB/ROCE_V1/ROCE_V2) |
| Transport | BTH 等效字段(QPN、PSN、Opcode) | struct ibv_send_wr、struct ibv_qp_attr |
libibverbs/verbs.h:dest_qp_num、sq_psn、rq_psn、opcode |
| Transport | 分段/重组 | 由 HCA 硬件/内核驱动完成 | 用户态通过 path_mtu、max_inline_data 间接配置 |
| Transport | 可靠服务 ACK/NAK | 由硬件实现 | 用户态通过 qp_state、retry_cnt、rnr_retry、timeout 配置 |
| ULP - SM | SMP(QP0) | libibumad |
umad_sm.h:umad_smp;umad.c:QP0 收发 |
| ULP - GSI | GMP(QP1) | libibumad + saquery |
umad_sa.h:umad_sa_packet;umad.c:QP1 收发 |
5. 核心特性实现(3.5)
5.1 Protection Domains(PD)
- 规范(3.5.5):PD 将 QP 与 Memory Region/Memory Window 关联在同一保护域内,跨 PD 访问无效
- 实现 :
struct ibv_pd:libibverbs/verbs.h(context、handle)ibv_alloc_pd()/ibv_dealloc_pd():libibverbs/verbs.c/cmd_pd.c- MR/MW/QP 均包含
struct ibv_pd *pd指针,确保同 PD 内才能绑定 - 内核 ABI:
UVERBS_OBJECT_PD→ib_uverbs_alloc_pd
5.2 Memory Regions(MR)与 Memory Keys(L_Key / R_Key)
- 规范(3.5.3、3.5.4):消费者注册虚拟内存,CA 返回 L_Key 和 R_Key;L_Key 用于本地 WR,R_Key 用于远程 RDMA
- 实现 :
struct ibv_mr:libibverbs/verbs.h(addr、length、lkey、rkey、pd)ibv_reg_mr()/ibv_reg_mr_iova2():libibverbs/verbs.c/cmd_mr.c- Access Flags:
IBV_ACCESS_LOCAL_WRITE、REMOTE_WRITE、REMOTE_READ、REMOTE_ATOMIC、MW_BIND、ON_DEMAND ibv_dereg_mr():libibverbs/verbs.c/cmd_mr.c→UVERBS_OBJECT_MR
5.3 Memory Windows(MW)
- 规范(3.6.1):Memory Bind 操作将 MW 绑定到 MR 的子集,生成新的 R_Key,用于细粒度远程访问控制
- 实现 :
struct ibv_mw:libibverbs/verbs.h(rkey、handle、type)enum ibv_mw_type:TYPE_1、TYPE_2ibv_alloc_mw()/ibv_dealloc_mw()/ibv_bind_mw():libibverbs/verbs.h(inline)→ provider ops- WR Opcode:
IBV_WR_BIND_MW
5.4 Partitions(P_Key)
- 规范(3.5.6):Partition 用于在共享 Fabric 上隔离系统;每个 Port 有 P_Key 表,QP 配置 P_Key,接收端校验不匹配则丢弃
- 实现 :
- QP 属性:
ibv_qp_attr.pkey_index - Port P_Key 表:通过 sysfs 暴露,
libibumad/sysfs.c读取pkeys umad_port_t:libibumad/umad.h含pkeys数组- Raw Packet / QP0 / QP1 不受 P_Key 限制(Spec 例外规则)
- QP 属性:
5.5 Virtual Lanes(VL)与 Quality of Service(QoS)
- 规范(3.5.7、3.5.8):VL 在单条物理链路上创建多条虚拟链路;SL(Service Level)通过 SL-to-VL 映射表映射到 VL;VL 有独立流控
- 实现 :
- VL 和 SL-to-VL 映射主要由 SM / 内核驱动 / 硬件 管理
- 用户态可见:
ibv_ah_attr.sl(Service Level) ib_uverbs_query_port_resp暴露active_width、active_speed、max_vl_num- QoS 配置(如 VL Arbitration)通常通过 SMP/SA 或 sysfs 进行,非直接 Verbs API
5.6 Multicast(3.5.11)
- 规范:Multicast Group 通过 MGID 标识,加入时 SA 分配 Multicast LID,建立组播转发树
- 实现 :
libibumad/umad_sa_mcm.h:MCMember Record 相关定义infiniband-diags/saquery.c:-m选项查询 MCMemberRecord- 用户态组播加入通常通过
libibverbs+librdmacm(rdma_join_multicast)完成,底层使用 SA 查询
5.7 Verbs(3.5.12)
- 规范:Verbs 是 HCA 与消费者之间的语义接口,非具体 API;描述配置、管理、QP 生命周期、WR 提交、完成状态获取的行为
- 实现 :
libibverbs/verbs.h+verbs.c:完整的用户态 Verbs API 实现libibverbs/driver.h:struct verbs_context_ops------ provider 必须实现的统一 vtablelibibverbs/verbs_api.h:标准化 API 入口- 设计原则:rdma-core 的
libibverbs正是 Spec 中 "Verbs" 语义的具体 API 化实现,允许消费者直接访问 HCA 硬件,绕过内核
6. 管理基础设施(3.9)
6.1 Management Datagrams(MAD)
- 规范(3.9.1) :所有管理报文封装在 MAD 中,24-byte 通用头定义
mgmt_class、method、attr_id、tid - 实现 :
struct umad_hdr:libibumad/umad_types.h(base_version、mgmt_class、class_version、method、status、tid、attr_id、attr_mod)struct umad_packet/umad_rmpp_packet/umad_dm_packet/umad_vendor_packet:不同 MAD 变体umad_send()/umad_recv():libibumad/umad.c
6.2 Management Methods(3.9.2)
| 规范方法 | rdma-core 对应 |
|---|---|
| Get / Set | IB_MAD_METHOD_GET / IB_MAD_METHOD_SET(umad_types.h);smp_query_via() / smp_set_via() |
| GetResp | 内核 ib_umad 驱动自动处理响应匹配 |
| Trap / Notice | IB_MAD_METHOD_TRAP / IB_MAD_METHOD_TRAP_REPRESS;infiniband-diags/ibsendtrap.c |
| Send | IB_MAD_METHOD_SEND;无显式响应 |
| Report / ReportResp | SA 陷阱订阅转发机制;srp_daemon/srp_handle_traps.c |
6.3 Subnet Management Interface(QP0 / SMI)
- 规范(3.9.4) :
- QP0 专用于 SMP
- 永久配置为 Unreliable Datagram
- 属于所有 Partition
- 仅 VL15(不受链路流控)
- 实现 :
umad_register()/umad_register2():libibumad/umad.c------ 当mgmt_class == 0x01 || 0x81时,强制qpn = 0umad_open_smi_port():打开仅限 QP0 的端口struct umad_smp:libibumad/umad_sm.h------ SMP MAD 布局,含mkey、dr_slid、dr_dlid、initial_path[64]、return_path[64]
6.4 Directed Routing(3.9.4.2)
- 规范 :DR SMP(class
0x81)包含initial_path/return_path向量、hop_ptr/hop_cnt、方向位;Switch 根据路径向量转发,无需预先配置 LID - 实现 :
struct umad_smp:libibumad/umad_sm.h(hop_ptr、hop_cnt、initial_path、return_path)infiniband-diags/smpdump.c:drsmp_get_init()------ 构造 DR SMP,mgmt_class = IB_SMI_DIRECT_CLASS,dr_slid = dr_dlid = 0xffffinfiniband-diags/ibdiag_common.c:resolve_portid_str()支持IB_DEST_DRPATH/IB_DEST_DRSLID;str2drpath()解析路径字符串infiniband-diags/ibtracert.c:extend_dpath()逐跳扩展 DR 路径,通过 SMP 读取 LFT 确定下一跳
6.5 General Service Interface(QP1 / GSI)
- 规范(3.9.5) :
- QP1 专用于 General Management(GMP)
- 永久配置为 Unreliable Datagram
- 属于该 Port 的所有 Partition
- 不使用 VL15
- 支持 Redirection:QP1 接收到 GMP 后,可响应新 Port/QP,后续请求直接发往该地址
- 实现 :
umad_register()/umad_register2():libibumad/umad.c------ 非 SMP class 默认qpn = 1umad_open_port():打开通用 MAD 端口(QP1)struct umad_sa_packet:libibumad/umad_sa.h------ SA MAD 格式(含sm_key、attr_offset、comp_mask)struct umad_class_port_info:libibumad/umad_types.h------ GSI ClassPortInfo,用于 Redirection/Trap 参数infiniband-diags/saquery.c:通过 QP1 发送 SAGet/GetTable请求(PathRecord、NodeRecord、MCMemberRecord 等)srp_daemon/srp_daemon.c:通过 QP1 发送 SA 查询发现 SRP 目标
6.6 Fabric Initialization(3.9.4.1)
- 规范:SM 通过 Directed Routing 遍历 Fabric,发现设备拓扑,分配 LID,配置 Switch 转发表;支持多 SM 仲裁
- 实现 :
libibumad/sysfs.c:从/sys/class/infiniband读取本地 Port 的sm_lid、sm_sl、lid、stateumad_get_port():libibumad/umad.c------ 获取本地 Port 信息,包括 SM LID/SLresolve_sm_portid():infiniband-diags/ibdiag_common.c------ 从umad_port_t.sm_lid构建 SM 目标地址- 实际的 Fabric Initialization 由 OpenSM(不在 rdma-core 中)完成,rdma-core 提供底层 MAD 传输和诊断工具
7. 内核-用户态 ABI 映射
rdma-core 通过两套 ABI 与内核 RDMA 子系统交互:
7.1 传统 Write ABI(Legacy)
- 文件 :
kernel-headers/rdma/ib_user_verbs.h - 机制 :用户态通过
write()将ib_uverbs_cmd_hdr+ payload 写入/dev/infiniband/uverbsX - 核心结构 :
ib_uverbs_create_qp/ib_uverbs_create_qp_respib_uverbs_create_cq/ib_uverbs_create_cq_respib_uverbs_reg_mr/ib_uverbs_reg_mr_resp(返回lkey、rkey)ib_uverbs_alloc_pd/ib_uverbs_dealloc_pdib_uverbs_create_ah/ib_uverbs_destroy_ah
7.2 现代 Ioctl ABI(Recommended)
- 文件 :
kernel-headers/rdma/ib_user_ioctl_cmds.h、ib_user_ioctl_verbs.h - 机制 :使用
ioctl(),基于 Object-Method-Attribute 模型 - 核心对象 :
UVERBS_OBJECT_DEVICE、UVERBS_OBJECT_PD、UVERBS_OBJECT_CQ、UVERBS_OBJECT_QP、UVERBS_OBJECT_MR、UVERBS_OBJECT_MW、UVERBS_OBJECT_AH、UVERBS_OBJECT_SRQ、UVERBS_OBJECT_XRCD - 示例 :QP 创建方法
UVERBS_METHOD_CREATE_QP,属性包括UVERBS_ATTR_CREATE_QP_PD_HANDLE、UVERBS_ATTR_CREATE_QP_SEND_CQ_HANDLE、UVERBS_ATTR_CREATE_QP_CAP、UVERBS_ATTR_CREATE_QP_TYPE等
7.3 ABI 与 IB 架构的直接对应
| IB 架构对象 | 内核 ABI 对象 | 用户态结构 | 关键命令/方法 |
|---|---|---|---|
| Queue Pair | UVERBS_OBJECT_QP |
struct ibv_qp |
CREATE_QP、DESTROY_QP、MODIFY_QP |
| Completion Queue | UVERBS_OBJECT_CQ |
struct ibv_cq |
CREATE_CQ、DESTROY_CQ、POLL_CQ |
| Protection Domain | UVERBS_OBJECT_PD |
struct ibv_pd |
ALLOC_PD、DEALLOC_PD |
| Memory Region | UVERBS_OBJECT_MR |
struct ibv_mr |
REG_MR、DEREG_MR |
| Memory Window | UVERBS_OBJECT_MW |
struct ibv_mw |
ALLOC_MW、DEALLOC_MW、BIND_MW |
| Address Handle | UVERBS_OBJECT_AH |
struct ibv_ah |
CREATE_AH、DESTROY_AH |
| Shared Receive Queue | UVERBS_OBJECT_SRQ |
struct ibv_srq |
CREATE_SRQ、DESTROY_SRQ |
| XRC Domain | UVERBS_OBJECT_XRCD |
struct ibv_xrcd |
OPEN_XRCD、CLOSE_XRCD |
| Work Queue(RSS) | UVERBS_OBJECT_WQ / UVERBS_OBJECT_RWQ_IND_TBL |
struct ibv_wq |
CREATE_WQ、CREATE_RWQ_IND_TBL |
8. 事务流总结(3.8)
Spec 3.8 描述的完整事务流在 rdma-core 中的体现:
- 消费者构造 WR (
struct ibv_send_wr/ibv_recv_wr)→ibv_post_send()/ibv_post_recv() - libibverbs 通过 cmd path 将 WR 传递给内核 (
ioctl或write到ib_uverbs) - 内核 RDMA 驱动将 WR 写入硬件 WQE 队列
- HCA 硬件 :
- 解析 WQE,进行虚拟地址→物理地址转换(使用 L_Key/R_Key)
- 构造报文:添加 Transport Header(BTH 等效:QPN、PSN、Opcode)、Network Header(GRH,如需要)、Link Header(LRH)
- 计算 ICRC/VCRC,通过物理端口发送
- Switch 基于 DLID 转发(或 Router 基于 GRH 跨子网路由)
- 对端 HCA 接收报文,校验 CRC、PSN、P_Key,根据 QP Context 执行操作(写接收缓冲区、RDMA 写远程内存、返回 Atomic 结果或 ACK)
- 完成时 ,硬件写 CQE 到 CQ → 用户态通过
ibv_poll_cq()获取完成状态
9. 总览映射表
| IB Spec Ch3 章节 | 体系结构概念 | rdma-core 主要实现目录 | 关键源文件 | 核心结构/函数 |
|---|---|---|---|---|
| 3.1 / 3.4 | 拓扑、HCA/TCA、Switch、Router、SM/SMA/GSA | libibverbs/、libibumad/、infiniband-diags/ |
verbs.h、device.c、umad.c、umad_sm.h、umad_sa.h、smpquery.c、saquery.c、ibroute.c |
ibv_device、ibv_context、umad_smp、umad_sa_packet、umad_port_t |
| 3.2 / 3.6 | QP、WQE、CQE、WR、Channel/Memory Semantics | libibverbs/ |
verbs.h、verbs.c、cmd_qp.c、cmd_cq.c |
ibv_qp、ibv_cq、ibv_send_wr、ibv_recv_wr、ibv_sge、ibv_post_send、ibv_poll_cq |
| 3.5.1 | Queue Pairs | libibverbs/ |
verbs.h、cmd_qp.c |
enum ibv_qp_type、enum ibv_qp_state、ibv_create_qp、ibv_modify_qp |
| 3.5.2 | Service Types(RC/UC/RD/UD/Raw) | libibverbs/ |
verbs.h |
IBV_QPT_RC、IBV_QPT_UC、IBV_QPT_UD、IBV_QPT_RAW_PACKET、IBV_QPT_XRC_SEND、IBV_QPT_XRC_RECV |
| 3.5.3 | Keys(M_Key、B_Key、P_Key、Q_Key、L_Key、R_Key) | libibverbs/、libibumad/ |
verbs.h、umad.h、cmd_mr.c |
ibv_mr.lkey/rkey、ibv_qp_attr.qkey、umad_port_t.pkeys、ibv_access_flags |
| 3.5.4 | Virtual Memory Addresses | libibverbs/ |
verbs.h、cmd_mr.c |
ibv_reg_mr()、ibv_mr.addr |
| 3.5.5 | Protection Domains | libibverbs/ |
verbs.h、verbs.c、cmd_pd.c |
struct ibv_pd、ibv_alloc_pd() |
| 3.5.6 | Partitions | libibverbs/、libibumad/ |
verbs.h、sysfs.c |
ibv_qp_attr.pkey_index、umad_port_t.pkeys |
| 3.5.7 | Virtual Lanes | 内核/驱动/SM | ib_user_verbs.h |
max_vl_num、ibv_ah_attr.sl(间接映射) |
| 3.5.8 | Quality of Service | 内核/驱动/SM | ib_user_verbs.h |
active_width、active_speed、ibv_ah_attr.sl |
| 3.5.10 | Addressing(LID/GID) | libibverbs/、libibumad/ |
verbs.h、umad.h |
ibv_ah_attr.dlid、ibv_global_route.dgid、union ibv_gid |
| 3.5.11 | Multicast | libibumad/、librdmacm/ |
umad_sa_mcm.h、saquery.c |
MCMemberRecord、rdma_join_multicast(librdmacm) |
| 3.5.12 | Verbs | libibverbs/ |
verbs.h、verbs.c、driver.h |
verbs_context_ops、ibv_create_qp、ibv_post_send、ibv_poll_cq |
| 3.7.1~3.7.4 | 分层架构(PHY/Link/Network/Transport) | kernel-headers/、libibverbs/ |
ib_user_verbs.h、verbs.h |
ib_uverbs_query_port_resp、ibv_ah_attr、ibv_send_wr.opcode |
| 3.7.5.1 | Subnet Management(SMP/QP0) | libibumad/、infiniband-diags/ |
umad.c、umad_sm.h、smpdump.c、sminfo.c |
umad_open_smi_port()、umad_smp、smp_query_via() |
| 3.7.5.2 | General Services(GSI/QP1/SA/CM) | libibumad/、infiniband-diags/ |
umad.c、umad_sa.h、saquery.c、srp_daemon.c |
umad_open_port()、umad_sa_packet、sa_query() |
| 3.9.4.2 | Directed Routing | libibumad/、infiniband-diags/ |
umad_sm.h、smpdump.c、ibdiag_common.c、ibtracert.c |
umad_smp.initial_path、drsmp_get_init()、str2drpath() |
| 3.10 | I/O Operation(TCA) | libibverbs/、srp_daemon/ |
verbs.h、srp_daemon.c |
HCA/TCA 统一由 ibv_device 表示;SRP 作为 TCA 上层应用 |
10. 结论
IB Specification Vol 1 Chapter 3 所描述的体系结构,在 rdma-core-2410mlnx54 中得到了完整且系统的实现:
-
libibverbs是 Verbs 语义 (3.5.12)的直接 API 化实现,将 Spec 中的 QP、CQ、PD、MR、MW、AH、WR、CQE 等概念映射为可编程的数据结构和函数调用,并通过 内核 ABI (UVERBS_OBJECT_*)下沉到内核驱动与硬件。 -
libibumad是 管理基础设施(3.9)的用户态底座,完整实现了 MAD 报文格式、QP0(SMI)和 QP1(GSI)的注册与收发、Directed Routing(DR)路径向量、以及 SM/SA 交互所需的底层原语。 -
kernel-headers/rdma/中的 ABI 定义(ib_user_verbs.h、ib_user_ioctl_verbs.h、rdma_netlink.h)构成了用户态与内核态之间的标准化契约,将 IB 架构对象(QP、CQ、PD、MR 等)翻译为内核对象和方法,保持了与 Spec 定义的高度同构性。 -
infiniband-diags/和srp_daemon/等工具则是架构管理面 的具体应用,它们基于libibumad和libibverbs构建,实现了拓扑发现、路径追踪、SA 查询、SMP 诊断、I/O 目标发现等高级功能,直接对应 Spec 中 SM、SMA、GSA、CM、DevMgt 等 Upper Layer Protocol 的角色。
综上,rdma-core-2410mlnx54 的代码结构严格遵循了 IB Spec Chapter 3 的体系划分:libibverbs 承载数据面(Transport + Verbs),libibumad 承载管理面(Subnet Management + General Services),内核 ABI 提供跨层标准化接口,三者协同实现了 InfiniBand 架构的完整软件栈。