Skip to content


5.00 avg. rating (97% score) - 1 vote
int ibv_query_gid(struct ibv_context *context, uint8_t port_num,
                  int index, union ibv_gid *gid)


ibv_query_gid() returns the value of an index in The GID table of an RDMA device port's.

The content of the GID table is valid only when the port_attr.state is either IBV_PORT_ARMED or IBV_PORT_ACTIVE. For other states of the port, the value of the GID table is indeterminate.

GID[0] contains the port GID, which is a constant value, provided by the vendor of the RDMA device manufacture.

The entity that configures this table (except for entry 0) is the SM.


Name Direction Description
context in RDMA device context that was returned from ibv_open_device()
port_num in Port number to query, values can be [1..dev_cap.phys_port_cnt]
index in Requested GID index, values can be [0..port_attr.gid_tbl_len-1]
gid out GID table entry value

Return Values

Value Description
0 On success
-1 On failure, errno indicates the failure reason:

EMFILE Too many files are opened by this process


Query port 1 for the GID table entry value in index 2:

union ibv_gid gid;
rc = ibv_query_gid(ctx, 1, 2, &gid);
if (rc) {
	fprintf(stderr, "Error, failed to query GID index %d of port %d in device '%s'\n",
		2, 1, ibv_get_device_name(ctx->device));
	return -1;


Why is GID good for anyway?

GID is the global address when sending packets between different subnets.

Every GID has 128 bits and its value is combined from two parts:

  • Higher 64 bits: subnet prefix. Value that identifies a set of endports which are managed by a common SM
  • Lower 64 bits: GID prefix. EUI-64 value that is configured by the SM

I'm using iWARP/IBoE, will I use this verb?

This verb is relevant for InfiniBand and IBoE.

Calling every time to ibv_query_gid() when I need a GID index value takes time, can I cache this value?

Actually, yes. The GID table is configured by the SM and it can change it after the initial configuration, but most of the time it won't. If you cache the value of the GID table, in case of the event IBV_EVENT_GID_CHANGE you should flush those values.

Share Our Posts

Share this post through social bookmarks.

  • Delicious
  • Digg
  • Newsvine
  • RSS
  • StumbleUpon
  • Technorati


Tell us what do you think.

  1. James says: September 24, 2013

    I am using Mellanox VPI and need to query, print and store the gid value. I do not use IPV6 addresses, but according to Mellanox VPI documentation for ibv_query_gid() a GID is: a valid IPv6 address composed of the globally unique identifier (GUID) and a prefix assigned by the SM. Is there a way to still use ibv_query_gid without ipv6 addresses, if so how do you recommend doing so(storing and or printing the GUID and prefix provided by the SM). I am programming in Microsoft Visual Studio 2010 with C++. Thanks for your help

    • Dotan Barak says: September 24, 2013

      Hi James.

      A GID is an address which is complaint to an IPv6 address.
      A GID in InfiniBand is composed from subnet prefix and GUID (as you mentioned),
      but what is the reason that you need them?

      ibv_query_gid return the GIDs from the GID table but anyway you don't have to use them
      (unless for example, you send messages that cross subnets).

      If you need to use a GID, you can use GID[0] which is constant.

      Did I answer your question?


      • James says: September 24, 2013

        I am interested in using the gid as an identifier for that specific port in an unrelated program. Is this possible while not using ipv6

      • Dotan Barak says: September 25, 2013


        You can safely ignore the fact that this address may be treated as an IPv6 HW address,
        and only use it as a port unique identifier for InfiniBand.


Add a Comment

Fill in the form and submit.

Time limit is exhausted. Please reload CAPTCHA.