From patchwork Wed Jul 20 23:16:54 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 993362 X-Patchwork-Delegate: ira.weiny@intel.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p6KNGtjn024149 for ; Wed, 20 Jul 2011 23:16:56 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752101Ab1GTXQz (ORCPT ); Wed, 20 Jul 2011 19:16:55 -0400 Received: from nspiron-2.llnl.gov ([128.115.41.82]:51195 "EHLO nspiron-2.llnl.gov" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751934Ab1GTXQy (ORCPT ); Wed, 20 Jul 2011 19:16:54 -0400 X-Attachments: None Received: from eris.llnl.gov (HELO trebuchet) ([134.9.2.84]) by nspiron-2.llnl.gov with SMTP; 20 Jul 2011 16:16:54 -0700 Date: Wed, 20 Jul 2011 16:16:54 -0700 From: Ira Weiny To: "linux-rdma@vger.kernel.org" Cc: Jason Gunthorpe , Hal Rosenstock Subject: [PATCH 1/3] infiniband-diags: libibnetdisc add port interface Message-Id: <20110720161654.406e442b.weiny2@llnl.gov> X-Mailer: Sylpheed 3.1.1 (GTK+ 2.18.9; x86_64-unknown-linux-gnu) Mime-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 20 Jul 2011 23:17:18 +0000 (UTC) Add ability to find port's based on PortGUID and DRPath Signed-off-by: Ira Weiny --- libibnetdisc/include/infiniband/ibnetdisc.h | 11 +++ libibnetdisc/libibnetdisc.ver | 2 +- libibnetdisc/src/ibnetdisc.c | 112 ++++++++++++++++++++------- libibnetdisc/src/libibnetdisc.map | 3 + 4 files changed, 98 insertions(+), 30 deletions(-) diff --git a/libibnetdisc/include/infiniband/ibnetdisc.h b/libibnetdisc/include/infiniband/ibnetdisc.h index 7b42026..300094e 100644 --- a/libibnetdisc/include/infiniband/ibnetdisc.h +++ b/libibnetdisc/include/infiniband/ibnetdisc.h @@ -213,6 +213,17 @@ IBND_EXPORT void ibnd_iter_nodes_type(ibnd_fabric_t * fabric, int node_type, void *user_data); /** ========================================================================= + * Port operations + */ +IBND_EXPORT ibnd_port_t *ibnd_find_port_guid(ibnd_fabric_t * fabric, + uint64_t guid); +IBND_EXPORT ibnd_port_t *ibnd_find_port_dr(ibnd_fabric_t * fabric, + char *dr_str); +typedef void (*ibnd_iter_port_func_t) (ibnd_port_t * port, void *user_data); +IBND_EXPORT void ibnd_iter_ports(ibnd_fabric_t * fabric, + ibnd_iter_port_func_t func, void *user_data); + +/** ========================================================================= * Chassis queries */ IBND_EXPORT uint64_t ibnd_get_chassis_guid(ibnd_fabric_t * fabric, diff --git a/libibnetdisc/libibnetdisc.ver b/libibnetdisc/libibnetdisc.ver index 27f922f..8ff2d35 100644 --- a/libibnetdisc/libibnetdisc.ver +++ b/libibnetdisc/libibnetdisc.ver @@ -6,4 +6,4 @@ # API_REV - advance on any added API # RUNNING_REV - advance any change to the vendor files # AGE - number of backward versions the API still supports -LIBVERSION=5:1:0 +LIBVERSION=6:0:1 diff --git a/libibnetdisc/src/ibnetdisc.c b/libibnetdisc/src/ibnetdisc.c index 4a4f33b..b7fa75a 100644 --- a/libibnetdisc/src/ibnetdisc.c +++ b/libibnetdisc/src/ibnetdisc.c @@ -387,37 +387,13 @@ ibnd_node_t *ibnd_find_node_guid(ibnd_fabric_t * fabric, uint64_t guid) return NULL; } +/* forward declare */ +ibnd_port_t *ibnd_find_port_dr(ibnd_fabric_t * fabric, char *dr_str); + ibnd_node_t *ibnd_find_node_dr(ibnd_fabric_t * fabric, char *dr_str) { - int i = 0; - ibnd_node_t *rc; - ib_dr_path_t path; - - if (!fabric) { - IBND_DEBUG("fabric parameter NULL\n"); - return NULL; - } - - rc = fabric->from_node; - - if (str2drpath(&path, dr_str, 0, 0) == -1) - return NULL; - - for (i = 0; i <= path.cnt; i++) { - ibnd_port_t *remote_port = NULL; - if (path.p[i] == 0) - continue; - if (!rc->ports) - return NULL; - - remote_port = rc->ports[path.p[i]]->remoteport; - if (!remote_port) - return NULL; - - rc = remote_port->node; - } - - return rc; + ibnd_port_t *rc = ibnd_find_port_dr(fabric, dr_str); + return rc->node; } void add_to_nodeguid_hash(ibnd_node_t * node, ibnd_node_t * hash[]) @@ -632,3 +608,81 @@ void ibnd_iter_nodes_type(ibnd_fabric_t * fabric, ibnd_iter_node_func_t func, for (cur = list; cur; cur = cur->type_next) func(cur, user_data); } + +ibnd_port_t *ibnd_find_port_guid(ibnd_fabric_t * fabric, uint64_t guid) +{ + int hash = HASHGUID(guid) % HTSZ; + ibnd_port_t *port; + + if (!fabric) { + IBND_DEBUG("fabric parameter NULL\n"); + return NULL; + } + + for (port = fabric->portstbl[hash]; port; port = port->htnext) + if (port->guid == guid) + return port; + + return NULL; +} + +ibnd_port_t *ibnd_find_port_dr(ibnd_fabric_t * fabric, char *dr_str) +{ + int i = 0; + ibnd_node_t *cur_node; + ibnd_port_t *rc; + ib_dr_path_t path; + + if (!fabric) { + IBND_DEBUG("fabric parameter NULL\n"); + return NULL; + } + + if (!dr_str) { + IBND_DEBUG("dr_str parameter NULL\n"); + return NULL; + } + + cur_node = fabric->from_node; + + if (str2drpath(&path, dr_str, 0, 0) == -1) + return NULL; + + for (i = 0; i <= path.cnt; i++) { + ibnd_port_t *remote_port = NULL; + if (path.p[i] == 0) + continue; + if (!cur_node->ports) + return NULL; + + remote_port = cur_node->ports[path.p[i]]->remoteport; + if (!remote_port) + return NULL; + + rc = remote_port; + cur_node = remote_port->node; + } + + return rc; +} + +void ibnd_iter_ports(ibnd_fabric_t * fabric, ibnd_iter_port_func_t func, + void *user_data) +{ + int i = 0; + ibnd_port_t *cur = NULL; + + if (!fabric) { + IBND_DEBUG("fabric parameter NULL\n"); + return; + } + + if (!func) { + IBND_DEBUG("func parameter NULL\n"); + return; + } + + for (i = 0; iportstbl[i]; cur; cur = cur->htnext) + func(cur, user_data); +} diff --git a/libibnetdisc/src/libibnetdisc.map b/libibnetdisc/src/libibnetdisc.map index 8a56fbb..1c42e7b 100644 --- a/libibnetdisc/src/libibnetdisc.map +++ b/libibnetdisc/src/libibnetdisc.map @@ -14,5 +14,8 @@ IBNETDISC_1.0 { ibnd_get_chassis_slot_str; ibnd_iter_nodes; ibnd_iter_nodes_type; + ibnd_find_port_guid; + ibnd_find_port_dr; + ibnd_iter_ports; local: *; };