From patchwork Tue Apr 7 12:30:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Wang X-Patchwork-Id: 6169551 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 900E2BF4A6 for ; Tue, 7 Apr 2015 12:30:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 88DC720353 for ; Tue, 7 Apr 2015 12:30:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4E15C20295 for ; Tue, 7 Apr 2015 12:30:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753288AbbDGMa3 (ORCPT ); Tue, 7 Apr 2015 08:30:29 -0400 Received: from mail-wg0-f49.google.com ([74.125.82.49]:33493 "EHLO mail-wg0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752914AbbDGMa1 (ORCPT ); Tue, 7 Apr 2015 08:30:27 -0400 Received: by wgin8 with SMTP id n8so54328826wgi.0 for ; Tue, 07 Apr 2015 05:30:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=tl2D8HE2aeZNHi/7LOf9jP42nSozI1WDYWRpUW1vAFk=; b=NXaYNC8nKcHQDXuvv3YvcBcdI7cWDeqqWI4x2goCR8TkjtsgT/ofLFijgBNnJTT/K2 V9H6m8x9pv8WNFFtkW75SsAFh3/ildIrFbo3UTyrS4h3elDHruAr5mJ5BXMhBc1gjLks GTt8wkQo1XGRz2RA4mHy3zSOIBb+QCKGqlg8TiW3aaxo4b3lkDo0h2bOMHogzSy6e2wz K9LwiMOStKIA5aIFH9WXx66NKtUNqSOzabxqw1RoTX2/GTDhyjyXexgMz4XaLo9U3t6I UxTo7t5mASw3Rl/ohQABcnpY7L75ecGmb2/N6ov0SVScgZzwrigELCU64zUJkMx5DpG4 Q//Q== X-Gm-Message-State: ALoCoQl7VVM+1K80k6FOqBvs2Qhe22H9e2L7Mw4TmA/K3yudJkxVNtQJeJmWnWvEoQ4+Rgxey28h X-Received: by 10.180.10.234 with SMTP id l10mr4263874wib.27.1428409825715; Tue, 07 Apr 2015 05:30:25 -0700 (PDT) Received: from [192.168.71.52] ([62.217.45.26]) by mx.google.com with ESMTPSA id go4sm4579469wib.1.2015.04.07.05.30.23 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Apr 2015 05:30:24 -0700 (PDT) Message-ID: <5523CDDE.4050209@profitbricks.com> Date: Tue, 07 Apr 2015 14:30:22 +0200 From: Michael Wang User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Roland Dreier , Sean Hefty , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, netdev@vger.kernel.org CC: Hal Rosenstock , Tom Tucker , Steve Wise , Hoang-Nam Nguyen , Christoph Raisch , Mike Marciniszyn , Eli Cohen , Faisal Latif , Upinder Malhi , Trond Myklebust , "J. Bruce Fields" , "David S. Miller" , Ira Weiny , PJ Waskiewicz , Tatyana Nikolova , Or Gerlitz , Jack Morgenstein , Haggai Eran , Ilya Nelkenbaum , Yann Droneaud , Bart Van Assche , Shachar Raindel , Sagi Grimberg , Devesh Sharma , Matan Barak , Moni Shoua , Jiri Kosina , Selvin Xavier , Mitesh Ahuja , Li RongQing , Rasmus Villemoes , Alex Estrin , Doug Ledford , Eric Dumazet , Erez Shitrit , Tom Gundersen , Chuck Lever , Michael Wang Subject: [PATCH v2 03/17] IB/Verbs: Use management helper cap_ib_mad() for mad-check References: <5523CCD5.6030401@profitbricks.com> In-Reply-To: <5523CCD5.6030401@profitbricks.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce helper cap_ib_mad() to help us check if the port of an IB device support Infiniband Management Datagrams. Reform ib_umad_add_one() to fit per-port-check method better. Cc: Jason Gunthorpe Cc: Doug Ledford Cc: Ira Weiny Cc: Sean Hefty Signed-off-by: Michael Wang --- drivers/infiniband/core/mad.c | 18 +++++++++--------- drivers/infiniband/core/user_mad.c | 26 ++++++++++++++++++++------ include/rdma/ib_verbs.h | 15 +++++++++++++++ 3 files changed, 44 insertions(+), 15 deletions(-) diff --git a/drivers/infiniband/core/mad.c b/drivers/infiniband/core/mad.c index 74c30f4..ef0c0c5 100644 --- a/drivers/infiniband/core/mad.c +++ b/drivers/infiniband/core/mad.c @@ -3057,9 +3057,6 @@ static void ib_mad_init_device(struct ib_device *device) { int start, end, i; - if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB) - return; - if (device->node_type == RDMA_NODE_IB_SWITCH) { start = 0; end = 0; @@ -3069,6 +3066,9 @@ static void ib_mad_init_device(struct ib_device *device) } for (i = start; i <= end; i++) { + if (!cap_ib_mad(device, i)) + continue; + if (ib_mad_port_open(device, i)) { dev_err(&device->dev, "Couldn't open port %d\n", i); goto error; @@ -3086,15 +3086,15 @@ error_agent: dev_err(&device->dev, "Couldn't close port %d\n", i); error: - i--; + while (--i >= start) { + if (!cap_ib_mad(device, i)) + continue; - while (i >= start) { if (ib_agent_port_close(device, i)) dev_err(&device->dev, "Couldn't close port %d for agents\n", i); if (ib_mad_port_close(device, i)) dev_err(&device->dev, "Couldn't close port %d\n", i); - i--; } } @@ -3102,9 +3102,6 @@ static void ib_mad_remove_device(struct ib_device *device) { int i, num_ports, cur_port; - if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB) - return; - if (device->node_type == RDMA_NODE_IB_SWITCH) { num_ports = 1; cur_port = 0; @@ -3113,6 +3110,9 @@ static void ib_mad_remove_device(struct ib_device *device) cur_port = 1; } for (i = 0; i < num_ports; i++, cur_port++) { + if (!cap_ib_mad(device, i)) + continue; + if (ib_agent_port_close(device, cur_port)) dev_err(&device->dev, "Couldn't close port %d for agents\n", diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c index 928cdd2..b52884b 100644 --- a/drivers/infiniband/core/user_mad.c +++ b/drivers/infiniband/core/user_mad.c @@ -1273,9 +1273,7 @@ static void ib_umad_add_one(struct ib_device *device) { struct ib_umad_device *umad_dev; int s, e, i; - - if (rdma_node_get_transport(device->node_type) != RDMA_TRANSPORT_IB) - return; + int count = 0; if (device->node_type == RDMA_NODE_IB_SWITCH) s = e = 0; @@ -1296,11 +1294,21 @@ static void ib_umad_add_one(struct ib_device *device) umad_dev->end_port = e; for (i = s; i <= e; ++i) { + if (!cap_ib_mad(device, i)) + continue; + umad_dev->port[i - s].umad_dev = umad_dev; if (ib_umad_init_port(device, i, umad_dev, &umad_dev->port[i - s])) goto err; + + count++; + } + + if (!count) { + kobject_put(&umad_dev->kobj); + return; } ib_set_client_data(device, &umad_client, umad_dev); @@ -1308,8 +1316,12 @@ static void ib_umad_add_one(struct ib_device *device) return; err: - while (--i >= s) + while (--i >= s) { + if (!cap_ib_mad(device, i)) + continue; + ib_umad_kill_port(&umad_dev->port[i - s]); + } kobject_put(&umad_dev->kobj); } @@ -1322,8 +1334,10 @@ static void ib_umad_remove_one(struct ib_device *device) if (!umad_dev) return; - for (i = 0; i <= umad_dev->end_port - umad_dev->start_port; ++i) - ib_umad_kill_port(&umad_dev->port[i]); + for (i = 0; i <= umad_dev->end_port - umad_dev->start_port; ++i) { + if (cap_ib_mad(device, i)) + ib_umad_kill_port(&umad_dev->port[i]); + } kobject_put(&umad_dev->kobj); } diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h index 780b3b7..4013933 100644 --- a/include/rdma/ib_verbs.h +++ b/include/rdma/ib_verbs.h @@ -1773,6 +1773,21 @@ static inline int rdma_ib_mgmt(struct ib_device *device, u8 port_num) return (tp == RDMA_TRANSPORT_IB || tp == RDMA_TRANSPORT_IBOE); } +/** + * cap_ib_mad - Check if the port of device has the capability Infiniband + * Management Datagrams. + * + * @device: Device to be checked + * @port_num: Port number of the device + * + * Return 0 when port of the device don't support Infiniband + * Management Datagrams. + */ +static inline int cap_ib_mad(struct ib_device *device, u8 port_num) +{ + return rdma_ib_mgmt(device, port_num); +} + int ib_query_gid(struct ib_device *device, u8 port_num, int index, union ib_gid *gid);