/* ib_find_pkey - Returns the PKey table index where a specified PKey value occurs. @device: The device to query. @port_num: The port number of the device to search for the PKey. @pkey: The PKey value to search for. @index: The index into the PKey table where the PKey was found.  */
int ib_find_pkey(struct ib_device *device, u8 port_num, u16 pkey, u16 *index)
/* ib_find_pkey - Returns the PKey table index where a specified PKey value occurs. @device: The device to query. @port_num: The port number of the device to search for the PKey. @pkey: The PKey value to search for. @index: The index into the PKey table where the PKey was found.  */
int ib_find_pkey(struct ib_device *device, u8 port_num, u16 pkey, u16 *index)
{
	int ret, i;
	u16 tmp_pkey;
	for (i = 0; i < device->pkey_tbl_len[port_num - start_port(device)]; ++i) {
		ret = ib_query_pkey(device, port_num, i, &tmp_pkey);
		if (ret)
			return ret;
		if ((pkey & 0x7fff) == (tmp_pkey & 0x7fff)) {
			*index = i;
			return 0;
		}
	}
	return -ENOENT;
}