From: Roland Dreier Date: Tue, 31 May 2005 15:56:49 +0000 (+0000) Subject: Add generic userspace part of query GID and query P_Key verbs X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=9dde5e8abb4620e90b6b65ccd19e3ed1d7ef27e2;p=~shefty%2Flibibverbs.git Add generic userspace part of query GID and query P_Key verbs Signed-off-by: Roland Dreier --- diff --git a/include/infiniband/driver.h b/include/infiniband/driver.h index 7d89af4..45279e3 100644 --- a/include/infiniband/driver.h +++ b/include/infiniband/driver.h @@ -68,6 +68,10 @@ extern int ibv_cmd_get_context(int num_comp, struct ibv_context *context, extern int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num, struct ibv_port_attr *port_attr, struct ibv_query_port *cmd, size_t cmd_size); +extern int ibv_cmd_query_gid(struct ibv_context *context, uint8_t port_num, + int index, union ibv_gid *gid); +extern int ibv_cmd_query_pkey(struct ibv_context *context, uint8_t port_num, + int index, uint16_t *pkey); extern int ibv_cmd_alloc_pd(struct ibv_context *context, struct ibv_pd *pd, struct ibv_alloc_pd *cmd, size_t cmd_size); extern int ibv_cmd_dealloc_pd(struct ibv_pd *pd); diff --git a/include/infiniband/kern-abi.h b/include/infiniband/kern-abi.h index 25137c2..8166c83 100644 --- a/include/infiniband/kern-abi.h +++ b/include/infiniband/kern-abi.h @@ -196,6 +196,7 @@ struct ibv_query_pkey { struct ibv_query_pkey_resp { __u16 pkey; + __u16 reserved; }; struct ibv_alloc_pd { diff --git a/include/infiniband/verbs.h b/include/infiniband/verbs.h index 57d4016..602d697 100644 --- a/include/infiniband/verbs.h +++ b/include/infiniband/verbs.h @@ -414,6 +414,10 @@ struct ibv_device { struct ibv_context_ops { int (*query_port)(struct ibv_context *context, uint8_t port_num, struct ibv_port_attr *port_attr); + int (*query_gid)(struct ibv_context *context, uint8_t port_num, + int index, union ibv_gid *gid); + int (*query_pkey)(struct ibv_context *context, uint8_t port_num, + int index, uint16_t *pkey); struct ibv_pd * (*alloc_pd)(struct ibv_context *context); int (*dealloc_pd)(struct ibv_pd *pd); struct ibv_mr * (*reg_mr)(struct ibv_pd *pd, void *addr, size_t length, @@ -486,6 +490,18 @@ extern int ibv_get_async_event(struct ibv_context *context, extern int ibv_query_port(struct ibv_context *context, uint8_t port_num, struct ibv_port_attr *port_attr); +/** + * ibv_query_gid - Get a GID table entry + */ +extern int ibv_query_gid(struct ibv_context *context, uint8_t port_num, + int index, union ibv_gid *gid); + +/** + * ibv_query_pkey - Get a P_Key table entry + */ +extern int ibv_query_pkey(struct ibv_context *context, uint8_t port_num, + int index, uint16_t *pkey); + /** * ibv_alloc_pd - Allocate a protection domain */ diff --git a/src/cmd.c b/src/cmd.c index 2a4ffef..4e74495 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -97,6 +97,42 @@ int ibv_cmd_query_port(struct ibv_context *context, uint8_t port_num, return 0; } +int ibv_cmd_query_gid(struct ibv_context *context, uint8_t port_num, + int index, union ibv_gid *gid) +{ + struct ibv_query_gid cmd; + struct ibv_query_gid_resp resp; + + IBV_INIT_CMD_RESP(&cmd, sizeof cmd, QUERY_GID, &resp); + cmd.port_num = port_num; + cmd.index = index; + + if (write(context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) + return errno; + + memcpy(gid->raw, resp.gid, 16); + + return 0; +} + +int ibv_cmd_query_pkey(struct ibv_context *context, uint8_t port_num, + int index, uint16_t *pkey) +{ + struct ibv_query_pkey cmd; + struct ibv_query_pkey_resp resp; + + IBV_INIT_CMD_RESP(&cmd, sizeof cmd, QUERY_PKEY, &resp); + cmd.port_num = port_num; + cmd.index = index; + + if (write(context->cmd_fd, &cmd, sizeof cmd) != sizeof cmd) + return errno; + + *pkey = resp.pkey; + + return 0; +} + int ibv_cmd_alloc_pd(struct ibv_context *context, struct ibv_pd *pd, struct ibv_alloc_pd *cmd, size_t cmd_size) { diff --git a/src/libibverbs.map b/src/libibverbs.map index 0a812dd..64a4f6a 100644 --- a/src/libibverbs.map +++ b/src/libibverbs.map @@ -7,6 +7,8 @@ IBVERBS_1.0 { ibv_close_device; ibv_get_async_event; ibv_query_port; + ibv_query_gid; + ibv_query_pkey; ibv_alloc_pd; ibv_dealloc_pd; ibv_reg_mr; @@ -23,6 +25,8 @@ IBVERBS_1.0 { ibv_detach_mcast; ibv_cmd_get_context; ibv_cmd_query_port; + ibv_cmd_query_gid; + ibv_cmd_query_pkey; ibv_cmd_alloc_pd; ibv_cmd_dealloc_pd; ibv_cmd_reg_mr; diff --git a/src/verbs.c b/src/verbs.c index c732d4b..94830b4 100644 --- a/src/verbs.c +++ b/src/verbs.c @@ -48,6 +48,18 @@ int ibv_query_port(struct ibv_context *context, uint8_t port_num, return context->ops.query_port(context, port_num, port_attr); } +int ibv_query_gid(struct ibv_context *context, uint8_t port_num, + int index, union ibv_gid *gid) +{ + return context->ops.query_gid(context, port_num, index, gid); +} + +int ibv_query_pkey(struct ibv_context *context, uint8_t port_num, + int index, uint16_t *pkey) +{ + return context->ops.query_pkey(context, port_num, index, pkey); +} + struct ibv_pd *ibv_alloc_pd(struct ibv_context *context) { struct ibv_pd *pd;