]> git.openfabrics.org - ~shefty/ibacm.git/commitdiff
ibacm: Use pkey 0xffff or 0x7fff for SA query
authorKaike Wan <kaike.wan@intel.com>
Wed, 25 Mar 2015 22:40:46 +0000 (15:40 -0700)
committerSean Hefty <sean.hefty@intel.com>
Wed, 25 Mar 2015 22:40:46 +0000 (15:40 -0700)
Currently, ibacm uses the first pkey on the local port to query SA. More
appropriately, it should use either 0xffff or 0x7fff for SA query.
However, if the local port is not configured with either pkey, ibacm will
continue to use the first pkey.

Signed-off-by: Kaike Wan <kaike.wan@intel.com>
Signed-off-by: Sean Hefty <sean.hefty@intel.com>
src/acm.c

index 815a916b0e9ec20b79bcd7ecff6c71fbc2429ba6..76497252c7c806174278c57d47247f78e802f60a 100644 (file)
--- a/src/acm.c
+++ b/src/acm.c
@@ -106,6 +106,7 @@ struct acmc_port {
        union ibv_gid       *gid_tbl;
        uint16_t            lid;
        uint16_t            lid_mask;
+       int                 default_pkey_index;
 };
 
 struct acmc_device {
@@ -1844,6 +1845,7 @@ static void acm_port_up(struct acmc_port *port)
        uint16_t pkey;
        int i, ret;
        struct acmc_prov_context *dev_ctx;
+       int index = -1;
 
        acm_log(1, "%s %d\n", port->dev->device.verbs->device->name, 
                port->port.port_num);
@@ -1889,6 +1891,25 @@ static void acm_port_up(struct acmc_port *port)
                goto err1;
        }
 
+       /* Determine the default pkey first.
+          Order of preference: 0xffff, 0x7fff, first pkey
+       */
+       for (i = 0; i < attr.pkey_tbl_len; i++) {
+               ret = ibv_query_pkey(port->dev->device.verbs, 
+                                    port->port.port_num, i, &pkey);
+               if (ret)
+                       continue;
+               pkey = ntohs(pkey);
+               if (pkey == 0xffff) {
+                       index = i;
+                       break;
+               }
+               else if (pkey == 0x7fff) {
+                       index = i;
+               }
+       }
+       port->default_pkey_index = index < 0 ? 0: index;
+
        for (i = 0; i < attr.pkey_tbl_len; i++) {
                ret = ibv_query_pkey(port->dev->device.verbs, 
                                     port->port.port_num, i, &pkey);
@@ -2397,7 +2418,7 @@ int acm_send_sa_mad(struct acm_sa_mad *mad)
        mad->umad.addr.qkey = port->sa_addr.qkey;
        mad->umad.addr.lid = htons(port->sa_addr.lid);
        mad->umad.addr.sl = port->sa_addr.sl;
-       // TODO: mad->umad.addr.pkey_index = req->ep->?;
+       mad->umad.addr.pkey_index = req->ep->port->default_pkey_index;
 
        lock_acquire(&port->lock);
        if (port->sa_credits && DListEmpty(&port->sa_wait)) {