From patchwork Sat Sep 19 17:00:47 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sasha Khapyorsky X-Patchwork-Id: 48774 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n8JGwQS5027316 for ; Sat, 19 Sep 2009 16:59:14 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750984AbZISQ7J (ORCPT ); Sat, 19 Sep 2009 12:59:09 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751020AbZISQ7J (ORCPT ); Sat, 19 Sep 2009 12:59:09 -0400 Received: from mail-ew0-f206.google.com ([209.85.219.206]:57187 "EHLO mail-ew0-f206.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750984AbZISQ7I (ORCPT ); Sat, 19 Sep 2009 12:59:08 -0400 Received: by ewy2 with SMTP id 2so2094099ewy.17 for ; Sat, 19 Sep 2009 09:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:sender:received:date:from:to :cc:subject:message-id:references:mime-version:content-type :content-disposition:in-reply-to:user-agent; bh=JFPQIMlQ7byqbRNKiEKm33+MqbHDxd50pEPVH6BBS+w=; b=o30djj1JDfHxhLYBno0sBvXZWKECbrHiAci3aUYVMstKW9wXcOmP5NzyTBGisfR6hU 3xDmifNFgZtPm9r3zmUDKj9qKagYzAyqdhYx/xEDZEiVEHUxmQjXwNA483dPhMvUTJOa cw7J2F+ZAJZIYTo78842y7tPn4kJCPIU/C/Qg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=hCGKsURkf14ijTxdPfQSEkLwR3EETEZ5nta4NeNpPvPPpTCL2yhA9XXbmoutBQLDDO tEncgiCUV1N9dDiwrypi0mJRx4tBrd9vJfsTdv5og9AIuo8rChvAnLwUobCfSesQj+Fz Nn7eSGjkhYb/CXC8XLKJ73dFaIRsYdp9tPKuE= Received: by 10.211.141.15 with SMTP id t15mr3550931ebn.59.1253379550182; Sat, 19 Sep 2009 09:59:10 -0700 (PDT) Received: from me.localdomain (85.64.35.106.dynamic.barak-online.net [85.64.35.106]) by mx.google.com with ESMTPS id 28sm968406eyg.33.2009.09.19.09.59.09 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 19 Sep 2009 09:59:09 -0700 (PDT) Received: by me.localdomain (Postfix, from userid 1000) id 4D38E417DC; Sat, 19 Sep 2009 20:00:47 +0300 (IDT) Date: Sat, 19 Sep 2009 20:00:47 +0300 From: Sasha Khapyorsky To: OpenIB , linux-rdma Cc: Eli Dorfman , Slava Strebkov , Hal Rosenstock Subject: [PATCH] opensm: osm_get_port_by_lid() helper Message-ID: <20090919170047.GF13667@me> References: <20090919165817.GC13667@me> <20090919165924.GD13667@me> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20090919165924.GD13667@me> User-Agent: Mutt/1.5.20 (2009-06-14) Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org This new helper is similar to osm_get_port_by_base_lid(), but with improved interface (returns port's pointer) and moved to osm_subnet.[ch] (where others osm_get_*_by_*() helpers are located). Signed-off-by: Sasha Khapyorsky --- opensm/include/opensm/osm_port.h | 35 ------------------------------- opensm/include/opensm/osm_subnet.h | 25 ++++++++++++++++++++++ opensm/opensm/osm_port.c | 36 -------------------------------- opensm/opensm/osm_sa_link_record.c | 13 +++-------- opensm/opensm/osm_sa_path_record.c | 4 +- opensm/opensm/osm_sa_pkey_record.c | 5 +-- opensm/opensm/osm_sa_portinfo_record.c | 6 +--- opensm/opensm/osm_sa_slvl_record.c | 6 +--- opensm/opensm/osm_sa_sminfo_record.c | 6 +--- opensm/opensm/osm_sa_vlarb_record.c | 6 +--- opensm/opensm/osm_subnet.c | 27 ++++++++++++++++++++++++ 11 files changed, 68 insertions(+), 101 deletions(-) diff --git a/opensm/include/opensm/osm_port.h b/opensm/include/opensm/osm_port.h index 000e2fe..eb77ed9 100644 --- a/opensm/include/opensm/osm_port.h +++ b/opensm/include/opensm/osm_port.h @@ -1376,41 +1376,6 @@ osm_port_get_lid_range_ho(IN const osm_port_t * const p_port, * Port *********/ -/****f* OpenSM: Port/osm_get_port_by_base_lid -* NAME -* osm_get_port_by_base_lid -* -* DESCRIPTION -* Returns a status on whether a Port was able to be -* determined based on the LID supplied and if so, return the Port. -* -* SYNOPSIS -*/ -ib_api_status_t -osm_get_port_by_base_lid(IN const osm_subn_t * const p_subn, - IN const ib_net16_t lid, - IN OUT const osm_port_t ** const pp_port); -/* -* PARAMETERS -* p_subn -* [in] Pointer to the subnet data structure. -* -* lid -* [in] LID requested. -* -* pp_port -* [in][out] Pointer to pointer to Port object. -* -* RETURN VALUES -* IB_SUCCESS -* IB_NOT_FOUND -* -* NOTES -* -* SEE ALSO -* Port -*********/ - /****f* OpenSM: Physical Port/osm_physp_calc_link_mtu * NAME * osm_physp_calc_link_mtu diff --git a/opensm/include/opensm/osm_subnet.h b/opensm/include/opensm/osm_subnet.h index 6c20de8..a8c6b62 100644 --- a/opensm/include/opensm/osm_subnet.h +++ b/opensm/include/opensm/osm_subnet.h @@ -935,6 +935,31 @@ struct osm_port *osm_get_port_by_guid(IN osm_subn_t const *p_subn, * osm_port_t *********/ +/****f* OpenSM: Port/osm_get_port_by_lid +* NAME +* osm_get_port_by_lid +* +* DESCRIPTION +* Returns a pointer of the port object for given lid value. +* +* SYNOPSIS +*/ +struct osm_port *osm_get_port_by_lid(const osm_subn_t * subn, ib_net16_t lid); +/* +* PARAMETERS +* subn +* [in] Pointer to the subnet data structure. +* +* lid +* [in] LID requested. +* +* RETURN VALUES +* The port structure pointer if found. NULL otherwise. +* +* SEE ALSO +* Subnet object, osm_port_t +*********/ + /****f* OpenSM: Subnet/osm_get_mgrp_by_mlid * NAME * osm_get_mgrp_by_mlid diff --git a/opensm/opensm/osm_port.c b/opensm/opensm/osm_port.c index dc8a768..79a8913 100644 --- a/opensm/opensm/osm_port.c +++ b/opensm/opensm/osm_port.c @@ -184,42 +184,6 @@ void osm_port_get_lid_range_ho(IN const osm_port_t * p_port, /********************************************************************** **********************************************************************/ -ib_api_status_t osm_get_port_by_base_lid(IN const osm_subn_t * p_subn, - IN ib_net16_t lid, - IN OUT const osm_port_t ** pp_port) -{ - ib_api_status_t status; - uint16_t base_lid; - uint8_t lmc; - - *pp_port = NULL; - - /* Loop on lmc from 0 up through max LMC possible */ - for (lmc = 0; lmc <= IB_PORT_LMC_MAX; lmc++) { - /* Calculate a base LID assuming this is the real LMC */ - base_lid = cl_ntoh16(lid) & ~((1 << lmc) - 1); - - /* Look for a match */ - status = cl_ptr_vector_at(&p_subn->port_lid_tbl, - base_lid, (void **)pp_port); - if ((status == CL_SUCCESS) && (*pp_port != NULL)) { - /* Determine if base LID "tested" is the real base LID */ - /* This is true if the LMC "tested" is the port's actual LMC */ - if (lmc == osm_port_get_lmc(*pp_port)) { - status = IB_SUCCESS; - goto Found; - } - } - } - *pp_port = NULL; - status = IB_NOT_FOUND; - -Found: - return status; -} - -/********************************************************************** - **********************************************************************/ uint8_t osm_physp_calc_link_mtu(IN osm_log_t * p_log, IN const osm_physp_t * p_physp) { diff --git a/opensm/opensm/osm_sa_link_record.c b/opensm/opensm/osm_sa_link_record.c index bf0b5ee..9e55e71 100644 --- a/opensm/opensm/osm_sa_link_record.c +++ b/opensm/opensm/osm_sa_link_record.c @@ -363,7 +363,6 @@ static ib_net16_t lr_rcv_get_end_points(IN osm_sa_t * sa, const ib_link_record_t *p_lr; const ib_sa_mad_t *p_sa_mad; ib_net64_t comp_mask; - ib_api_status_t status; ib_net16_t sa_status = IB_SA_MAD_STATUS_SUCCESS; OSM_LOG_ENTER(sa->p_log); @@ -380,10 +379,8 @@ static ib_net16_t lr_rcv_get_end_points(IN osm_sa_t * sa, *pp_dest_port = NULL; if (p_sa_mad->comp_mask & IB_LR_COMPMASK_FROM_LID) { - status = osm_get_port_by_base_lid(sa->p_subn, p_lr->from_lid, - pp_src_port); - - if (status != IB_SUCCESS || *pp_src_port == NULL) { + *pp_src_port = osm_get_port_by_lid(sa->p_subn, p_lr->from_lid); + if (!*pp_src_port) { /* This 'error' is the client's fault (bad lid) so don't enter it as an error in our own log. @@ -399,10 +396,8 @@ static ib_net16_t lr_rcv_get_end_points(IN osm_sa_t * sa, } if (p_sa_mad->comp_mask & IB_LR_COMPMASK_TO_LID) { - status = osm_get_port_by_base_lid(sa->p_subn, p_lr->to_lid, - pp_dest_port); - - if (status != IB_SUCCESS || *pp_dest_port == NULL) { + *pp_dest_port = osm_get_port_by_lid(sa->p_subn, p_lr->to_lid); + if (!*pp_dest_port) { /* This 'error' is the client's fault (bad lid) so don't enter it as an error in our own log. diff --git a/opensm/opensm/osm_sa_path_record.c b/opensm/opensm/osm_sa_path_record.c index 37f32ac..2247ebe 100644 --- a/opensm/opensm/osm_sa_path_record.c +++ b/opensm/opensm/osm_sa_path_record.c @@ -1496,8 +1496,8 @@ static ib_api_status_t pr_match_mgrp_attributes(IN osm_sa_t * sa, } if (comp_mask & IB_PR_COMPMASK_SLID) { - if (osm_get_port_by_base_lid(sa->p_subn, p_pr->slid, &port) || - !port || !osm_mgrp_get_mcm_port(p_mgrp, port->guid)) + port = osm_get_port_by_lid(sa->p_subn, p_pr->slid); + if (!port || !osm_mgrp_get_mcm_port(p_mgrp, port->guid)) goto Exit; } diff --git a/opensm/opensm/osm_sa_pkey_record.c b/opensm/opensm/osm_sa_pkey_record.c index 8e47745..a5a3e28 100644 --- a/opensm/opensm/osm_sa_pkey_record.c +++ b/opensm/opensm/osm_sa_pkey_record.c @@ -300,9 +300,8 @@ void osm_pkey_rec_rcv_process(IN void *ctx, IN void *data) work load, since we don't have to search every port */ if (comp_mask & IB_PKEY_COMPMASK_LID) { - status = osm_get_port_by_base_lid(sa->p_subn, p_rcvd_rec->lid, - &p_port); - if (status != IB_SUCCESS || p_port == NULL) { + p_port = osm_get_port_by_lid(sa->p_subn, p_rcvd_rec->lid); + if (!p_port) { status = IB_NOT_FOUND; OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 460B: " "No port found with LID %u\n", diff --git a/opensm/opensm/osm_sa_portinfo_record.c b/opensm/opensm/osm_sa_portinfo_record.c index b5ef101..448981c 100644 --- a/opensm/opensm/osm_sa_portinfo_record.c +++ b/opensm/opensm/osm_sa_portinfo_record.c @@ -521,10 +521,8 @@ void osm_pir_rcv_process(IN void *ctx, IN void *data) work load, since we don't have to search every port */ if (comp_mask & IB_PIR_COMPMASK_LID) { - status = - osm_get_port_by_base_lid(sa->p_subn, p_rcvd_rec->lid, - &p_port); - if ((status != IB_SUCCESS) || (p_port == NULL)) { + p_port = osm_get_port_by_lid(sa->p_subn, p_rcvd_rec->lid); + if (!p_port) { status = IB_NOT_FOUND; OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2109: " "No port found with LID %u\n", diff --git a/opensm/opensm/osm_sa_slvl_record.c b/opensm/opensm/osm_sa_slvl_record.c index 061d970..d310df0 100644 --- a/opensm/opensm/osm_sa_slvl_record.c +++ b/opensm/opensm/osm_sa_slvl_record.c @@ -274,10 +274,8 @@ void osm_slvl_rec_rcv_process(IN void *ctx, IN void *data) work load, since we don't have to search every port */ if (comp_mask & IB_SLVL_COMPMASK_LID) { - status = - osm_get_port_by_base_lid(sa->p_subn, p_rcvd_rec->lid, - &p_port); - if ((status != IB_SUCCESS) || (p_port == NULL)) { + p_port = osm_get_port_by_lid(sa->p_subn, p_rcvd_rec->lid); + if (!p_port) { status = IB_NOT_FOUND; OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2608: " "No port found with LID %u\n", diff --git a/opensm/opensm/osm_sa_sminfo_record.c b/opensm/opensm/osm_sa_sminfo_record.c index 4d454af..dcc8615 100644 --- a/opensm/opensm/osm_sa_sminfo_record.c +++ b/opensm/opensm/osm_sa_sminfo_record.c @@ -236,10 +236,8 @@ void osm_smir_rcv_process(IN void *ctx, IN void *data) work load, since we don't have to search every port */ if (comp_mask & IB_SMIR_COMPMASK_LID) { - status = - osm_get_port_by_base_lid(sa->p_subn, p_rcvd_rec->lid, - &p_port); - if ((status != IB_SUCCESS) || (p_port == NULL)) { + p_port = osm_get_port_by_lid(sa->p_subn, p_rcvd_rec->lid); + if (!p_port) { status = IB_NOT_FOUND; OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2806: " "No port found with LID %u\n", diff --git a/opensm/opensm/osm_sa_vlarb_record.c b/opensm/opensm/osm_sa_vlarb_record.c index f9f11b7..5c66049 100644 --- a/opensm/opensm/osm_sa_vlarb_record.c +++ b/opensm/opensm/osm_sa_vlarb_record.c @@ -288,10 +288,8 @@ void osm_vlarb_rec_rcv_process(IN void *ctx, IN void *data) work load, since we don't have to search every port */ if (comp_mask & IB_VLA_COMPMASK_LID) { - status = - osm_get_port_by_base_lid(sa->p_subn, p_rcvd_rec->lid, - &p_port); - if ((status != IB_SUCCESS) || (p_port == NULL)) { + p_port = osm_get_port_by_lid(sa->p_subn, p_rcvd_rec->lid); + if (!p_port) { status = IB_NOT_FOUND; OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2A09: " "No port found with LID %u\n", diff --git a/opensm/opensm/osm_subnet.c b/opensm/opensm/osm_subnet.c index 8d63a75..b475031 100644 --- a/opensm/opensm/osm_subnet.c +++ b/opensm/opensm/osm_subnet.c @@ -643,6 +643,33 @@ osm_port_t *osm_get_port_by_guid(IN osm_subn_t const *p_subn, IN ib_net64_t guid /********************************************************************** **********************************************************************/ +osm_port_t *osm_get_port_by_lid(IN osm_subn_t const * subn, IN ib_net16_t lid) +{ + osm_port_t *port = NULL; + ib_api_status_t stat; + uint16_t base_lid; + uint8_t lmc; + + lid = cl_ntoh16(lid); + + /* Loop on lmc from 0 up through max LMC possible */ + for (lmc = 0; lmc <= IB_PORT_LMC_MAX; lmc++) { + /* Calculate a base LID assuming this is the real LMC */ + base_lid = lid & ~((1 << lmc) - 1); + + stat = cl_ptr_vector_at(&subn->port_lid_tbl, base_lid, + (void *)&port); + /* Determine if base LID "tested" is the real base LID */ + /* This is true if the LMC "tested" is the port's actual LMC */ + if (stat == CL_SUCCESS && port && lmc == osm_port_get_lmc(port)) + return port; + } + + return NULL; +} + +/********************************************************************** + **********************************************************************/ static void subn_set_default_qos_options(IN osm_qos_options_t * opt) { opt->max_vls = OSM_DEFAULT_QOS_MAX_VLS;