IB/core: Handle table with full and partial membership for the same P_Key
[pandora-kernel.git] / drivers / infiniband / core / device.c
index e711de4..18c1ece 100644 (file)
@@ -707,18 +707,28 @@ int ib_find_pkey(struct ib_device *device,
 {
        int ret, i;
        u16 tmp_pkey;
+       int partial_ix = -1;
 
        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;
+                       /* if there is full-member pkey take it.*/
+                       if (tmp_pkey & 0x8000) {
+                               *index = i;
+                               return 0;
+                       }
+                       if (partial_ix < 0)
+                               partial_ix = i;
                }
        }
 
+       /*no full-member, if exists take the limited*/
+       if (partial_ix >= 0) {
+               *index = partial_ix;
+               return 0;
+       }
        return -ENOENT;
 }
 EXPORT_SYMBOL(ib_find_pkey);