IBV_GET_PKEY_INDEX(3)
π ibv_get_pkey_index β bestie's guide to the P_Key table β¨
okay so picture this: ibv_get_pkey_index from the Libibverbs Programmer's Manual, but explained by someone who actually wants you to get it. it's IBV_GET_PKEY_INDEX(3) and it is, lowkey, the most helpful little function. π«Ά
πΈ NAME πΈ
ibv_get_pkey_index β literally just: obtain the index in the P_Key table of a P_Key. that's it. that's the vibe. π
β¨ SYNOPSIS β¨
#include <infiniband/verbs.h>
int ibv_get_pkey_index(struct ibv_context *context,
uint8_t port_num,
__be16 pkey);
no cap, that's the whole signature. context, port_num, pkey. three little arguments, one iconic function. π
π¦ DESCRIPTION π¦
okay so here's the situation, bestie. every InfiniBand HCA maintains a P_Key table for each of its ports. that table is indexed by an integer, and each element holds a P_Key. two things: the table lives per-port, and the lookup key is an integer index. noted. β¨
and here's why you should care: certain InfiniBand data structures that work with P_Keys expect a P_Key index, not the P_Key itself. like, for example, struct ibv_qp_attr and struct ib_mad_addr. iykyk. those structs are not gonna accept your raw P_Key, they want the index. periodt. π
hence (yes, hence, i'm being fancy) the function ibv_get_pkey_index(). it accepts a P_Key in network byte order and returns an index in the P_Key table as the result. so you hand it the P_Key, it hands you the index, and everybody slays. π₯
π¨ reminder bestie: the P_Key goes in in network byte order. don't be out here passing host-order bytes and then acting surprised.
π RETURN VALUE π
ibv_get_pkey_index() returns the P_Key index on success, and -1 on error. that's the whole check. -1 means something went wrong β don't just vibe past it. π
π SEE ALSO π
go read those next, they're all part of the same little friend group. π§
π AUTHOR π
Bart Van Assche <bvanassche@acm.org> β thank you for this one, genuinely iconic. π
libibverbs Β· 2018-07-16 Β· and that's the whole IBV_GET_PKEY_INDEX(3) page, bestie β go get that index, you're gonna ate πβ¨ππ¦
π¦ where this page comes from
- alpine 3.24: rdma-core-doc 61.0-r0 Β· GPL-2.0-only OR BSD-2-Clause
- centos-stream 10: rdma-core-devel 62.0-3.el10 Β· GPLv2 or BSD
- centos-stream 9: rdma-core-devel 61.0-3.el9 Β· GPLv2 or BSD
- centos-stream 9: rdma-core-devel 61.0-3.el9 Β· GPLv2 or BSD
- ubuntu jammy: libibverbs-dev 39.0-1 Β· BSD-MIT OR GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms