---
name: "ibv_get_pkey_index"
section: "3"
platform: "linux"
package: "rdma-core"
version: "65.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/ibv_get_pkey_index"
---

# ibv\_get\_pkey\_index(3)

obtain the index in the P\_Key table of a P\_Key

## NAME

ibv\_get\_pkey\_index - obtain the index in the P\_Key table of a P\_Key

## SYNOPSIS

-

  ```
  #include <infiniband/verbs.h>
  int ibv_get_pkey_index(struct ibv_context *context,
                         uint8_t port_num,
                         __be16 pkey);
  ```

## DESCRIPTION

Every InfiniBand HCA maintains a P\_Key table for each of its ports that is indexed by an integer and with a P\_Key in each element. Certain InfiniBand data structures that work with P\_Keys expect a P\_Key index, e.g. **struct ibv\_qp\_attr** and **struct** **ib\_mad\_addr**. Hence the function **ibv\_get\_pkey\_index()** that accepts a P\_Key in network byte order and that returns an index in the P\_Key table as result.

## RETURN VALUE

**ibv\_get\_pkey\_index()** returns the P\_Key index on success, and -1 on error.

## SEE ALSO

[**ibv\_open\_device**(3)](/ibv_open_device/3.md), [**ibv\_query\_device**(3)](/ibv_query_device/3.md), [**ibv\_query\_gid**(3)](/ibv_query_gid/3.md), [**ibv\_query\_pkey**(3)](/ibv_query_pkey/3.md), [**ibv\_query\_port**(3)](/ibv_query_port/3.md)

## AUTHOR

Bart Van Assche ⟨bvanassche@acm.org⟩\\c
