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; From patchwork Mon Jul 23 16:48:12 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: 10540595 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 E9A991823 for ; Mon, 23 Jul 2018 16:48:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D915F28C64 for ; Mon, 23 Jul 2018 16:48:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD95528CC0; Mon, 23 Jul 2018 16:48:19 +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 F03CC28CA9 for ; Mon, 23 Jul 2018 16:48:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388703AbeGWRuW (ORCPT ); Mon, 23 Jul 2018 13:50:22 -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 S2388283AbeGWRuV (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=xcaKTd/FtGEVtStYYzwJFM0Gcskw8mmel18YGkG8tPY=; b=Z3W+IN9owXMnbiGLSed80LwBmmpsiCoa+R8jAPrGL84/BvqXheCLw8Me 0LNi3anltX+BN43PYKOMPGD2JsrdfDFtPiNvLxMMllomaR6KIdvZMYNNW 4RjIlnsiLU+UgXjCS/b0Dpi7FJonlRrXd7A1Y0LoYyTPbxZ+rpw7Iuu/3 vnB5ETmB6aXe7OjXFZ4DutaPSyvfIqTzV4xWuJlQan2xx+imAiz+XakTs YSnVDbgyzfCaCDbBVtotN9qs1gOZo5HE2wWkQAq6Sb+VIuafrNxCRpTOF 4qoYSAu7Iq3l5Oq1ZxVrS10IgKN1221wTHgLkpdf++66HsUPMvltR59uB Q==; X-IronPort-AV: E=Sophos;i="5.51,393,1526313600"; d="scan'208";a="88094275" 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 2/5] srp_daemon: Move the pkey_index_to_pkey() definition Date: Mon, 23 Jul 2018 09:48:12 -0700 Message-Id: <20180723164815.26448-3-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 --- srp_daemon/srp_daemon.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/srp_daemon/srp_daemon.c b/srp_daemon/srp_daemon.c index 6356e1373f9a..08d1134dca7d 100644 --- a/srp_daemon/srp_daemon.c +++ b/srp_daemon/srp_daemon.c @@ -793,6 +793,24 @@ static int check_sm_cap(struct umad_resources *umad_res, int *mask_match) return 0; } +int pkey_index_to_pkey(struct umad_resources *umad_res, int pkey_index, + uint16_t *pkey) +{ + char pkey_file[18], pkey_str[16]; + + /* Read pkey */ + snprintf(pkey_file, sizeof(pkey_file), "pkeys/%d", pkey_index); + if (srpd_sys_read_string(umad_res->port_sysfs_path, pkey_file, + pkey_str, sizeof(pkey_str)) < 0) + return -1; + + *pkey = strtoul(pkey_str, NULL, 0); + if (*pkey) + pr_debug("discover Targets for P_key %04x (index %d)\n", + *pkey, pkey_index); + return 0; +} + static int set_class_port_info(struct umad_resources *umad_res, uint16_t dlid) { struct srp_ib_user_mad in_mad, out_mad; @@ -1071,24 +1089,6 @@ static int get_port_info(struct umad_resources *umad_res, uint16_t dlid, return 0; } -int pkey_index_to_pkey(struct umad_resources *umad_res, int pkey_index, - uint16_t *pkey) -{ - char pkey_file[18], pkey_str[16]; - - /* Read pkey */ - snprintf(pkey_file, sizeof(pkey_file), "pkeys/%d", pkey_index); - if (srpd_sys_read_string(umad_res->port_sysfs_path, pkey_file, - pkey_str, sizeof(pkey_str)) < 0) - return -1; - - *pkey = strtoul(pkey_str, NULL, 0); - if (*pkey) - pr_debug("discover Targets for P_key %04x (index %d)\n", - *pkey, pkey_index); - return 0; -} - static int get_shared_pkeys(struct resources *res, uint16_t dest_port_lid, uint16_t *pkeys) From patchwork Mon Jul 23 16:48:13 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: 10540603 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 A641BA636 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 96E3B28C9A for ; Mon, 23 Jul 2018 16:48:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B2A428C64; 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 3746E28CC0 for ; Mon, 23 Jul 2018 16:48:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388283AbeGWRuX (ORCPT ); Mon, 23 Jul 2018 13:50:23 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:54919 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388722AbeGWRuV (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=3eL6oXWpWaNsV23feK5rZK4A5ffGpe3ks77K71vDajI=; b=X4tt2o/v9OES63zwMPMpCiLVoRIIMxauGDTPvGVUw03X+obcwN89wu93 R8TTTgeu0IOe9a5QXIP6xy3Lh6QX+h/o6yUe9sq6m64bm/Tk7l/SrWgL3 CMwbDbxMlmH18Q/2UbQtr02LtRahDIJH61ij7gw+jK+VkznDOB3LZtBZn 9huwYabC93pVoStpoJ0UxFx6u6dUI8FnAOstqS+iXxtVGaIbMLZOF7rxS OphE5AHqWMf8JrxLyb8daUKe3/yfnyR1pdeqnRybnxPqhnahI7wk+lvjo Pxi6U5neVQ9tjFIpzlfLfFGWwGLneG+JHt3WyGbgNXMAPxk5CNcAfrFIW A==; X-IronPort-AV: E=Sophos;i="5.51,393,1526313600"; d="scan'208";a="88094276" 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 3/5] srp_daemon: Use ibv_query_pkey() Date: Mon, 23 Jul 2018 09:48:13 -0700 Message-Id: <20180723164815.26448-4-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 --- srp_daemon/srp_daemon.c | 11 +++-------- srp_daemon/srp_daemon.h | 1 + 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/srp_daemon/srp_daemon.c b/srp_daemon/srp_daemon.c index 08d1134dca7d..9be37f3ced1d 100644 --- a/srp_daemon/srp_daemon.c +++ b/srp_daemon/srp_daemon.c @@ -796,15 +796,9 @@ static int check_sm_cap(struct umad_resources *umad_res, int *mask_match) int pkey_index_to_pkey(struct umad_resources *umad_res, int pkey_index, uint16_t *pkey) { - char pkey_file[18], pkey_str[16]; - - /* Read pkey */ - snprintf(pkey_file, sizeof(pkey_file), "pkeys/%d", pkey_index); - if (srpd_sys_read_string(umad_res->port_sysfs_path, pkey_file, - pkey_str, sizeof(pkey_str)) < 0) + if (ibv_query_pkey(umad_res->ib_ctx, config->port_num, pkey_index, + pkey) < 0) return -1; - - *pkey = strtoul(pkey_str, NULL, 0); if (*pkey) pr_debug("discover Targets for P_key %04x (index %d)\n", *pkey, pkey_index); @@ -1934,6 +1928,7 @@ static struct resources *alloc_res(void) if (ret) goto err; res->res.ud_res = &res->ud_res; + res->umad_res.ib_ctx = res->ud_res.ib_ctx; ret = sync_resources_init(&res->sync_res); if (ret) diff --git a/srp_daemon/srp_daemon.h b/srp_daemon/srp_daemon.h index b29beb3f2d6a..dcc848aa6ed5 100644 --- a/srp_daemon/srp_daemon.h +++ b/srp_daemon/srp_daemon.h @@ -234,6 +234,7 @@ struct ud_resources { }; struct umad_resources { + struct ibv_context *ib_ctx; int portid; int agent; char *port_sysfs_path; From patchwork Mon Jul 23 16:48:14 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: 10540597 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 61182112B 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 4CADC28CAC for ; Mon, 23 Jul 2018 16:48:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F6EB28CC5; 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 6914C28CAC for ; Mon, 23 Jul 2018 16:48:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388748AbeGWRuW (ORCPT ); Mon, 23 Jul 2018 13:50:22 -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 S2388563AbeGWRuW (ORCPT ); Mon, 23 Jul 2018 13:50:22 -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=nsfWcEd1xT13ZovbaHFZqjlp8ZWRhhLk8+7CYiGK9BU=; b=GO5kkiXIL6Imcdyp63mnPja4oYjZYOWQRDOlNJ+z1rDth5ZJW58Xpjq7 LTYnsA2iBMJywJP249o35PbZ2I4u5HebLZtn59LiyYvVnFq9dbXbj2MYA edaEDPySIxm3jfXRmHSjxOoDeA229EmDTCa5bKdsBQoqi4YuhVwlfBRyN gXtEaNwMHXE4XzQbRd8qFQbmeKVtCoaLF0cxnS8UUq9T0PTudwZ4ofSei yIgcKUOpQt+vkw2Xd06ObkumWW3URYOCVsHYdIAi35PtuKzGRXIjrYvFE mHutb6d/lNYwvsmD6cgKWCgELtHPJMv7HwZ33qSnRRVXLsrj9U0CurVYa g==; X-IronPort-AV: E=Sophos;i="5.51,393,1526313600"; d="scan'208";a="88094277" 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:17 +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:18 -0700 From: Bart Van Assche To: Jason Gunthorpe Cc: Doug Ledford , linux-rdma@vger.kernel.org, Daniel Ahlin , Bart Van Assche Subject: [PATCH 4/5] srp_daemon: Fix pkey handling Date: Mon, 23 Jul 2018 09:48:14 -0700 Message-Id: <20180723164815.26448-5-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 From: Daniel Ahlin Make sure that the pkey index is set in outgoing device management MADs. Signed-off-by: Daniel Ahlin [ bvanassche: split this patch in three patches / left out the num_path check ] Signed-off-by: Bart Van Assche --- srp_daemon/srp_daemon.c | 51 ++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/srp_daemon/srp_daemon.c b/srp_daemon/srp_daemon.c index 9be37f3ced1d..a8ff1bb5eff8 100644 --- a/srp_daemon/srp_daemon.c +++ b/srp_daemon/srp_daemon.c @@ -805,7 +805,17 @@ int pkey_index_to_pkey(struct umad_resources *umad_res, int pkey_index, return 0; } -static int set_class_port_info(struct umad_resources *umad_res, uint16_t dlid) +static int pkey_to_pkey_index(struct umad_resources *umad_res, uint16_t h_pkey, + uint16_t *pkey_index) +{ + int res = ibv_get_pkey_index(umad_res->ib_ctx, config->port_num, + htobe16(h_pkey)); + if (res >= 0) + *pkey_index = res; + return res; +} + +static int set_class_port_info(struct umad_resources *umad_res, uint16_t dlid, uint16_t h_pkey) { struct srp_ib_user_mad in_mad, out_mad; struct umad_dm_packet *out_dm_mad, *in_dm_mad; @@ -815,6 +825,12 @@ static int set_class_port_info(struct umad_resources *umad_res, uint16_t dlid) init_srp_dm_mad(&out_mad, umad_res->agent, dlid, UMAD_ATTR_CLASS_PORT_INFO, 0); + if (pkey_to_pkey_index(umad_res, h_pkey, &out_mad.hdr.addr.pkey_index) + < 0) { + pr_err("set_class_port_info: Unable to find pkey_index for pkey %#x\n", h_pkey); + return -1; + } + out_dm_mad = get_data_ptr(out_mad); out_dm_mad->mad_hdr.method = UMAD_METHOD_SET; @@ -849,12 +865,17 @@ static int set_class_port_info(struct umad_resources *umad_res, uint16_t dlid) } static int get_iou_info(struct umad_resources *umad_res, uint16_t dlid, - struct srp_dm_iou_info *iou_info) + uint16_t h_pkey, struct srp_dm_iou_info *iou_info) { struct srp_ib_user_mad in_mad, out_mad; struct umad_dm_packet *in_dm_mad; init_srp_dm_mad(&out_mad, umad_res->agent, dlid, SRP_DM_ATTR_IO_UNIT_INFO, 0); + if (pkey_to_pkey_index(umad_res, h_pkey, &out_mad.hdr.addr.pkey_index) + < 0) { + pr_err("get_iou_info: Unable to find pkey_index for pkey %#x\n", h_pkey); + return -1; + } if (send_and_get(umad_res->portid, umad_res->agent, &out_mad, &in_mad, 0) < 0) return -1; @@ -873,7 +894,7 @@ static int get_iou_info(struct umad_resources *umad_res, uint16_t dlid, return 0; } -static int get_ioc_prof(struct umad_resources *umad_res, uint16_t h_dlid, int ioc, +static int get_ioc_prof(struct umad_resources *umad_res, uint16_t h_dlid, uint16_t h_pkey, int ioc, struct srp_dm_ioc_prof *ioc_prof) { struct srp_ib_user_mad in_mad, out_mad; @@ -881,6 +902,13 @@ static int get_ioc_prof(struct umad_resources *umad_res, uint16_t h_dlid, int io init_srp_dm_mad(&out_mad, umad_res->agent, h_dlid, SRP_DM_ATTR_IO_CONTROLLER_PROFILE, ioc); + if (pkey_to_pkey_index(umad_res, h_pkey, &out_mad.hdr.addr.pkey_index) + < 0) { + pr_err("get_ioc_prof: Unable to find pkey_index for pkey %#x\n", + h_pkey); + return -1; + } + if (send_and_get(umad_res->portid, umad_res->agent, &out_mad, &in_mad, 0) < 0) return -1; @@ -896,7 +924,7 @@ static int get_ioc_prof(struct umad_resources *umad_res, uint16_t h_dlid, int io return 0; } -static int get_svc_entries(struct umad_resources *umad_res, uint16_t dlid, int ioc, +static int get_svc_entries(struct umad_resources *umad_res, uint16_t dlid, uint16_t h_pkey, int ioc, int start, int end, struct srp_dm_svc_entries *svc_entries) { struct srp_ib_user_mad in_mad, out_mad; @@ -905,6 +933,13 @@ static int get_svc_entries(struct umad_resources *umad_res, uint16_t dlid, int i init_srp_dm_mad(&out_mad, umad_res->agent, dlid, SRP_DM_ATTR_SERVICE_ENTRIES, (ioc << 16) | (end << 8) | start); + if (pkey_to_pkey_index(umad_res, h_pkey, &out_mad.hdr.addr.pkey_index) + < 0) { + pr_err("get_svc_entries: Unable to find pkey_index for pkey %#x\n", + h_pkey); + return -1; + } + if (send_and_get(umad_res->portid, umad_res->agent, &out_mad, &in_mad, 0) < 0) return -1; @@ -940,10 +975,10 @@ static int do_port(struct resources *res, uint16_t pkey, uint16_t dlid, pr_debug("enter do_port\n"); if ((target->h_guid & oui_mask) == topspin_oui && - set_class_port_info(umad_res, dlid)) + set_class_port_info(umad_res, dlid, pkey)) pr_err("Warning: set of ClassPortInfo failed\n"); - ret = get_iou_info(umad_res, dlid, &iou_info); + ret = get_iou_info(umad_res, dlid, pkey, &iou_info); if (ret < 0) { pr_err("failed to get iou info for dlid %#x\n", dlid); goto out; @@ -974,7 +1009,7 @@ static int do_port(struct resources *res, uint16_t pkey, uint16_t dlid, SRP_DM_IOC_PRESENT) { pr_human("\n"); - if (get_ioc_prof(umad_res, dlid, i + 1, &target->ioc_prof)) + if (get_ioc_prof(umad_res, dlid, pkey, i + 1, &target->ioc_prof)) continue; pr_human(" controller[%3d]\n", i + 1); @@ -994,7 +1029,7 @@ static int do_port(struct resources *res, uint16_t pkey, uint16_t dlid, if (n >= target->ioc_prof.service_entries) n = target->ioc_prof.service_entries - 1; - if (get_svc_entries(umad_res, dlid, i + 1, + if (get_svc_entries(umad_res, dlid, pkey, i + 1, j, n, &svc_entries)) continue; From patchwork Mon Jul 23 16:48:15 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: 10540599 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 696B214BC 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 59B0228C64 for ; Mon, 23 Jul 2018 16:48:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D42128CCA; 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 E8F9528CA9 for ; Mon, 23 Jul 2018 16:48:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388563AbeGWRuW (ORCPT ); Mon, 23 Jul 2018 13:50:22 -0400 Received: from esa3.hgst.iphmx.com ([216.71.153.141]:54919 "EHLO esa3.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388283AbeGWRuW (ORCPT ); Mon, 23 Jul 2018 13:50:22 -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=1532364498; x=1563900498; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=SVJ4dat4LJtFCQJsWTN983UOO6ZJ3m1jRO5fXLA0f20=; b=QcNOsRydZqG+uXx1pMdPny2aBrbG72eKuqTKoDbDc7U2r6PEHIr5y1z7 Bv1Iow2qnGNAqmj38hhhRRrSxd6ZuRdv8rbKxwGwOqGRpGlB9v1DEj9+q 01JuP6I7fMMs5szV4CKJR/90I2Athb4Xgzu/Qo/MZ/YzfLjVUSmnxp8Qy aIxVF0krEchyFk/uTz1FCw8l6mMwpQzmiaFQ9sIWnuXhiyG9RVEBBibEv wF5zNffBD0AKJPCUtM76J5YhwSBOUZj0QwKFDSvi2wphDequhjz6EupKZ +TpXZyGchjGeNpZOeNwwriXIzu7+nAVpcOFkNCi5lQYgPw2KIcEjW62mx Q==; X-IronPort-AV: E=Sophos;i="5.51,393,1526313600"; d="scan'208";a="88094278" 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:17 +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:27 -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:18 -0700 From: Bart Van Assche To: Jason Gunthorpe Cc: Doug Ledford , linux-rdma@vger.kernel.org, Daniel Ahlin , Bart Van Assche Subject: [PATCH 5/5] srp_daemon: Rename ib_path_rec.num_path Date: Mon, 23 Jul 2018 09:48:15 -0700 Message-Id: <20180723164815.26448-6-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 Make it clear what the meaning is of the highest bit of num_path. Signed-off-by: Bart Van Assche --- srp_daemon/srp_daemon.c | 2 +- srp_daemon/srp_ib_types.h | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/srp_daemon/srp_daemon.c b/srp_daemon/srp_daemon.c index a8ff1bb5eff8..94d7c45bcd3e 100644 --- a/srp_daemon/srp_daemon.c +++ b/srp_daemon/srp_daemon.c @@ -2411,7 +2411,7 @@ static int get_lid(struct umad_resources *umad_res, union umad_gid *gid, path_rec->sgid = *gid; path_rec->dgid = *gid; - path_rec->num_path = 1; + path_rec->reversible_numpath = 1; path_rec->hop_flow_raw = htobe32(1 << 31); /* rawtraffic=1 hoplimit = 0 */ if (send_and_get(umad_res->portid, umad_res->agent, &out_mad, &in_mad, 0) < 0) diff --git a/srp_daemon/srp_ib_types.h b/srp_daemon/srp_ib_types.h index 0aacdd3efdc8..a5bd9dcabe6f 100644 --- a/srp_daemon/srp_ib_types.h +++ b/srp_daemon/srp_ib_types.h @@ -91,9 +91,12 @@ enum { * route between two end-points on a subnet. * * SYNOPSIS +* +* NOTES +* The role of this data structure is identical to the role of struct +* ibv_path_record in libibverbs/sa.h. */ -struct ib_path_rec -{ +struct ib_path_rec { uint8_t resv0[8]; union umad_gid dgid; union umad_gid sgid; @@ -101,7 +104,7 @@ struct ib_path_rec __be16 slid; __be32 hop_flow_raw; uint8_t tclass; - uint8_t num_path; + uint8_t reversible_numpath; /* reversible-7:7 num path-6:0 */ __be16 pkey; __be16 sl; uint8_t mtu; @@ -109,8 +112,7 @@ struct ib_path_rec uint8_t pkt_life; uint8_t preference; uint8_t resv2[6]; - -} PACK_SUFFIX4; +}; /****f* IBA Base: Types/umad_init_new