@@ -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)) {