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