From patchwork Mon Jul 23 16:48:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 10540601 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 878B290E3 for ; Mon, 23 Jul 2018 16:48:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7763428C64 for ; Mon, 23 Jul 2018 16:48:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B5EF28C9A; Mon, 23 Jul 2018 16:48:20 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 77DFF28C9A for ; Mon, 23 Jul 2018 16:48:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388716AbeGWRuV (ORCPT ); Mon, 23 Jul 2018 13:50:21 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:26625 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388563AbeGWRuV (ORCPT ); Mon, 23 Jul 2018 13:50:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1532364497; x=1563900497; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=6ZFJupiEMvnBNsvFUJpPAiYU1VqSDvSbfLvLFvsSuKU=; b=fZjlobUB/FS1dFUyRdlzbwJIPiBxFvz7aE7B2MAAJpnqVT9nyu7DZwAx ky+PpZ8YpMOsguDMnF9JETXh43qtgH7czoszJRFUg6yPn2Z6MAwYIzaTr v35EygyI7JBq5GBZO2nLmr7PrU6qvFyAKC8nLOtu5FMszvTiO/bNzU2gu 3JhA7rzt0QR28tsk0+QTBf/wcSg7uNdnYGZj4DgHmfA8LtMy3kGfj0DON gDDlZsbj4TY1GkWs4YIQ1pBMMF9BgYgXPglVqb1cpAea4EYDx7WSa2nN+ BAaNHiWn+tThv2seuSIpZmAy1J8XUjjRxCxxlfor9aij80w3bJ4uchj7x w==; X-IronPort-AV: E=Sophos;i="5.51,393,1526313600"; d="scan'208";a="88094274" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 24 Jul 2018 00:48:16 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP; 23 Jul 2018 09:36:26 -0700 Received: from thinkpad-bart.sdcorp.global.sandisk.com ([10.111.67.248]) by uls-op-cesaip01.wdc.com with ESMTP; 23 Jul 2018 09:48:17 -0700 From: Bart Van Assche To: Jason Gunthorpe Cc: Doug Ledford , linux-rdma@vger.kernel.org, Daniel Ahlin , Bart Van Assche Subject: [PATCH 1/5] verbs, ibacm, librdmacm: Introduce ibv_get_pkey_index() Date: Mon, 23 Jul 2018 09:48:11 -0700 Message-Id: <20180723164815.26448-2-bart.vanassche@wdc.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180723164815.26448-1-bart.vanassche@wdc.com> References: <20180723164815.26448-1-bart.vanassche@wdc.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch does not change any functionality. Signed-off-by: Bart Van Assche --- ibacm/prov/acmp/src/acmp.c | 16 ++++----- libibverbs/man/CMakeLists.txt | 1 + libibverbs/man/ibv_get_pkey_index.3.md | 48 ++++++++++++++++++++++++++ libibverbs/verbs.c | 16 +++++++++ libibverbs/verbs.h | 6 ++++ librdmacm/cma.c | 36 ++++++------------- 6 files changed, 87 insertions(+), 36 deletions(-) create mode 100644 libibverbs/man/ibv_get_pkey_index.3.md diff --git a/ibacm/prov/acmp/src/acmp.c b/ibacm/prov/acmp/src/acmp.c index 884fc484c223..0324ae2f40b3 100644 --- a/ibacm/prov/acmp/src/acmp.c +++ b/ibacm/prov/acmp/src/acmp.c @@ -2453,20 +2453,16 @@ acmp_get_ep(struct acmp_port *port, struct acm_endpoint *endpoint) static uint16_t acmp_get_pkey_index(struct acm_endpoint *endpoint) { struct acmp_port *port; - int ret; - __be16 pkey; - uint16_t i; + int i; port = acmp_get_port(endpoint); if (!port) return 0; - - for (i = 0, ret = 0; !ret; i++) { - ret = ibv_query_pkey(port->dev->verbs, port->port_num, i, &pkey); - if (!ret && endpoint->pkey == be16toh(pkey)) - return i; - } - return 0; + i = ibv_get_pkey_index(port->dev->verbs, port->port_num, + htobe16(endpoint->pkey)); + if (i < 0) + return 0; + return i; } static void acmp_close_endpoint(void *ep_context) diff --git a/libibverbs/man/CMakeLists.txt b/libibverbs/man/CMakeLists.txt index 99c57d737e73..234b34e86d4e 100644 --- a/libibverbs/man/CMakeLists.txt +++ b/libibverbs/man/CMakeLists.txt @@ -33,6 +33,7 @@ rdma_man_pages( ibv_get_device_guid.3.md ibv_get_device_list.3 ibv_get_device_name.3.md + ibv_get_pkey_index.3.md ibv_get_srq_num.3.md ibv_inc_rkey.3.md ibv_modify_qp.3 diff --git a/libibverbs/man/ibv_get_pkey_index.3.md b/libibverbs/man/ibv_get_pkey_index.3.md new file mode 100644 index 000000000000..729f18217ee9 --- /dev/null +++ b/libibverbs/man/ibv_get_pkey_index.3.md @@ -0,0 +1,48 @@ +--- +date: 2018-07-16 +footer: libibverbs +header: "Libibverbs Programmer's Manual" +layout: page +license: 'Licensed under the OpenIB.org BSD license (FreeBSD Variant) - See COPYING.md' +section: 3 +title: IBV_GET_PKEY_INDEX +--- + +# NAME + +ibv_get_pkey_index - obtain the index in the P_Key table of a P_Key + +# SYNOPSIS + +```c +#include + +int ibv_get_pkey_index(struct ibv_context *context, + uint8_t port_num, + __be16 pkey); +``` + +# DESCRIPTION + +Every InfiniBand HCA maintains a P_Key table for each of its ports that is +indexed by an integer and with a P_Key in each element. Certain InfiniBand +data structures that work with P_Keys expect a P_Key index, e.g. **struct +ibv_qp_attr** and **struct ib_mad_addr**. Hence the function +**ibv_get_pkey_index()** that accepts a P_Key in network byte order and that +returns an index in the P_Key table as result. + +# RETURN VALUE + +**ibv_get_pkey_index()** returns the P_Key index on success, and -1 on error. + +# SEE ALSO + +**ibv_open_device**(3), +**ibv_query_device**(3), +**ibv_query_gid**(3), +**ibv_query_pkey**(3), +**ibv_query_port**(3) + +# AUTHOR + +Bart Van Assche diff --git a/libibverbs/verbs.c b/libibverbs/verbs.c index a0aac3681f08..fde550309d36 100644 --- a/libibverbs/verbs.c +++ b/libibverbs/verbs.c @@ -200,6 +200,22 @@ LATEST_SYMVER_FUNC(ibv_query_pkey, 1_1, "IBVERBS_1.1", return 0; } +LATEST_SYMVER_FUNC(ibv_get_pkey_index, 1_1, "IBVERBS_1.1", + int, + struct ibv_context *context, uint8_t port_num, __be16 pkey) +{ + __be16 pkey_i; + int i, ret; + + for (i = 0; ; i++) { + ret = ibv_query_pkey(context, port_num, i, &pkey_i); + if (ret < 0) + return ret; + if (pkey == pkey_i) + return i; + } +} + LATEST_SYMVER_FUNC(ibv_alloc_pd, 1_1, "IBVERBS_1.1", struct ibv_pd *, struct ibv_context *context) diff --git a/libibverbs/verbs.h b/libibverbs/verbs.h index 086f7862f62c..ad44c7d8990e 100644 --- a/libibverbs/verbs.h +++ b/libibverbs/verbs.h @@ -1969,6 +1969,12 @@ int ibv_query_gid(struct ibv_context *context, uint8_t port_num, int ibv_query_pkey(struct ibv_context *context, uint8_t port_num, int index, __be16 *pkey); +/** + * ibv_get_pkey_index - Translate a P_Key into a P_Key index + */ +int ibv_get_pkey_index(struct ibv_context *context, uint8_t port_num, + __be16 pkey); + /** * ibv_alloc_pd - Allocate a protection domain */ diff --git a/librdmacm/cma.c b/librdmacm/cma.c index 5251c7ea34fc..5e738e3b0feb 100644 --- a/librdmacm/cma.c +++ b/librdmacm/cma.c @@ -1092,33 +1092,17 @@ static int ucma_modify_qp_err(struct rdma_cm_id *id) return rdma_seterrno(ibv_modify_qp(id->qp, &qp_attr, IBV_QP_STATE)); } -static int ucma_find_pkey(struct cma_device *cma_dev, uint8_t port_num, - __be16 pkey, uint16_t *pkey_index) -{ - int ret, i; - __be16 chk_pkey; - - for (i = 0, ret = 0; !ret; i++) { - ret = ibv_query_pkey(cma_dev->verbs, port_num, i, &chk_pkey); - if (!ret && pkey == chk_pkey) { - *pkey_index = (uint16_t) i; - return 0; - } - } - return ERR(EINVAL); -} - static int ucma_init_conn_qp3(struct cma_id_private *id_priv, struct ibv_qp *qp) { struct ibv_qp_attr qp_attr; int ret; - ret = ucma_find_pkey(id_priv->cma_dev, id_priv->id.port_num, - id_priv->id.route.addr.addr.ibaddr.pkey, - &qp_attr.pkey_index); - if (ret) - return ret; + ret = ibv_get_pkey_index(id_priv->cma_dev->verbs, id_priv->id.port_num, + id_priv->id.route.addr.addr.ibaddr.pkey); + if (ret < 0) + return ERR(EINVAL); + qp_attr.pkey_index = ret; qp_attr.port_num = id_priv->id.port_num; qp_attr.qp_state = IBV_QPS_INIT; qp_attr.qp_access_flags = 0; @@ -1149,12 +1133,12 @@ static int ucma_init_ud_qp3(struct cma_id_private *id_priv, struct ibv_qp *qp) struct ibv_qp_attr qp_attr; int ret; - ret = ucma_find_pkey(id_priv->cma_dev, id_priv->id.port_num, - id_priv->id.route.addr.addr.ibaddr.pkey, - &qp_attr.pkey_index); - if (ret) - return ret; + ret = ibv_get_pkey_index(id_priv->cma_dev->verbs, id_priv->id.port_num, + id_priv->id.route.addr.addr.ibaddr.pkey); + if (ret < 0) + return ERR(EINVAL); + qp_attr.pkey_index = ret; qp_attr.port_num = id_priv->id.port_num; qp_attr.qp_state = IBV_QPS_INIT; qp_attr.qkey = RDMA_UDP_QKEY;