]> Pileus Git - ~andy/linux/blobdiff - drivers/infiniband/core/cache.c
Merge branch 'for-linus' of git://git.linaro.org/people/rmk/linux-arm
[~andy/linux] / drivers / infiniband / core / cache.c
index 9353992f9eeadbb336a8b634798079ce57f34ac9..80f6cf2449fb9b852533d254ab8e6cbabc706156 100644 (file)
@@ -167,6 +167,7 @@ int ib_find_cached_pkey(struct ib_device *device,
        unsigned long flags;
        int i;
        int ret = -ENOENT;
+       int partial_ix = -1;
 
        if (port_num < start_port(device) || port_num > end_port(device))
                return -EINVAL;
@@ -179,6 +180,46 @@ int ib_find_cached_pkey(struct ib_device *device,
 
        for (i = 0; i < cache->table_len; ++i)
                if ((cache->table[i] & 0x7fff) == (pkey & 0x7fff)) {
+                       if (cache->table[i] & 0x8000) {
+                               *index = i;
+                               ret = 0;
+                               break;
+                       } else
+                               partial_ix = i;
+               }
+
+       if (ret && partial_ix >= 0) {
+               *index = partial_ix;
+               ret = 0;
+       }
+
+       read_unlock_irqrestore(&device->cache.lock, flags);
+
+       return ret;
+}
+EXPORT_SYMBOL(ib_find_cached_pkey);
+
+int ib_find_exact_cached_pkey(struct ib_device *device,
+                             u8                port_num,
+                             u16               pkey,
+                             u16              *index)
+{
+       struct ib_pkey_cache *cache;
+       unsigned long flags;
+       int i;
+       int ret = -ENOENT;
+
+       if (port_num < start_port(device) || port_num > end_port(device))
+               return -EINVAL;
+
+       read_lock_irqsave(&device->cache.lock, flags);
+
+       cache = device->cache.pkey_cache[port_num - start_port(device)];
+
+       *index = -1;
+
+       for (i = 0; i < cache->table_len; ++i)
+               if (cache->table[i] == pkey) {
                        *index = i;
                        ret = 0;
                        break;
@@ -188,7 +229,7 @@ int ib_find_cached_pkey(struct ib_device *device,
 
        return ret;
 }
-EXPORT_SYMBOL(ib_find_cached_pkey);
+EXPORT_SYMBOL(ib_find_exact_cached_pkey);
 
 int ib_get_cached_lmc(struct ib_device *device,
                      u8                port_num,