Skip to content

Commit 73aaa74

Browse files
Jack Morgensteinrolandd
authored andcommitted
IB/core: Add ib_find_exact_cached_pkey()
When P_Key tables potentially contain both full and partial membership copies for the same P_Key, we need a function to find the index for an exact (16-bit) P_Key. This is necessary when the master forwards QP1 MADs sent by guests. If the guest has sent the MAD with a limited membership P_Key, we need to to forward the MAD using the same limited membership P_Key. Since the master may have both the limited and the full member P_Keys in its table, we must make sure to retrieve the limited membership P_Key in this case. Signed-off-by: Jack Morgenstein <jackm@dev.mellanox.co.il> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> Signed-off-by: Roland Dreier <roland@purestorage.com>
1 parent ff7166c commit 73aaa74

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

‎drivers/infiniband/core/cache.c‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,38 @@ int ib_find_cached_pkey(struct ib_device *device,
199199
}
200200
EXPORT_SYMBOL(ib_find_cached_pkey);
201201

202+
int ib_find_exact_cached_pkey(struct ib_device *device,
203+
u8 port_num,
204+
u16 pkey,
205+
u16 *index)
206+
{
207+
struct ib_pkey_cache *cache;
208+
unsigned long flags;
209+
int i;
210+
int ret = -ENOENT;
211+
212+
if (port_num < start_port(device) || port_num > end_port(device))
213+
return -EINVAL;
214+
215+
read_lock_irqsave(&device->cache.lock, flags);
216+
217+
cache = device->cache.pkey_cache[port_num - start_port(device)];
218+
219+
*index = -1;
220+
221+
for (i = 0; i < cache->table_len; ++i)
222+
if (cache->table[i] == pkey) {
223+
*index = i;
224+
ret = 0;
225+
break;
226+
}
227+
228+
read_unlock_irqrestore(&device->cache.lock, flags);
229+
230+
return ret;
231+
}
232+
EXPORT_SYMBOL(ib_find_exact_cached_pkey);
233+
202234
int ib_get_cached_lmc(struct ib_device *device,
203235
u8 port_num,
204236
u8 *lmc)

‎include/rdma/ib_cache.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,22 @@ int ib_find_cached_pkey(struct ib_device *device,
100100
u16 pkey,
101101
u16 *index);
102102

103+
/**
104+
* ib_find_exact_cached_pkey - Returns the PKey table index where a specified
105+
* PKey value occurs. Comparison uses the FULL 16 bits (incl membership bit)
106+
* @device: The device to query.
107+
* @port_num: The port number of the device to search for the PKey.
108+
* @pkey: The PKey value to search for.
109+
* @index: The index into the cached PKey table where the PKey was found.
110+
*
111+
* ib_find_exact_cached_pkey() searches the specified PKey table in
112+
* the local software cache.
113+
*/
114+
int ib_find_exact_cached_pkey(struct ib_device *device,
115+
u8 port_num,
116+
u16 pkey,
117+
u16 *index);
118+
103119
/**
104120
* ib_get_cached_lmc - Returns a cached lmc table entry
105121
* @device: The device to query.

0 commit comments

Comments
 (0)