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;