public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] opensm/multicast: improve function prototypes
@ 2009-09-19 16:58 Sasha Khapyorsky
  2009-09-19 16:59 ` [PATCH] opensm/osm_sa_path_record.c: validate multicast membership Sasha Khapyorsky
  0 siblings, 1 reply; 4+ messages in thread
From: Sasha Khapyorsky @ 2009-09-19 16:58 UTC (permalink / raw)
  To: OpenIB, linux-rdma; +Cc: Eli Dorfman, Slava Strebkov


Improve some function prototypes:
- osm_mgrp_new() will get MCMember record now.
- osm_mgrp_is_port_present() is replaced by cleaner
  osm_mgrp_get_mcm_port() helper.

Signed-off-by: Sasha Khapyorsky <sashak-smomgflXvOZWk0Htik3J/w@public.gmane.org>
---
 opensm/include/opensm/osm_multicast.h  |   25 ++++++++++---------------
 opensm/opensm/osm_multicast.c          |   32 ++++++++++----------------------
 opensm/opensm/osm_sa_mcmember_record.c |   26 +++++++++++---------------
 3 files changed, 31 insertions(+), 52 deletions(-)

diff --git a/opensm/include/opensm/osm_multicast.h b/opensm/include/opensm/osm_multicast.h
index 32bcb78..15d7e78 100644
--- a/opensm/include/opensm/osm_multicast.h
+++ b/opensm/include/opensm/osm_multicast.h
@@ -142,12 +142,15 @@ typedef struct osm_mgrp {
 *
 * SYNOPSIS
 */
-osm_mgrp_t *osm_mgrp_new(IN const ib_net16_t mlid);
+osm_mgrp_t *osm_mgrp_new(IN const ib_net16_t mlid, IN ib_member_rec_t * mcmr);
 /*
 * PARAMETERS
 *	mlid
 *		[in] Multicast LID for this multicast group.
 *
+*	mcmr
+*		[in] MCMember Record for this multicast group.
+*
 * RETURN VALUES
 *	IB_SUCCESS if initialization was successful.
 *
@@ -309,20 +312,17 @@ osm_mcm_port_t *osm_mgrp_add_port(osm_subn_t *subn, osm_log_t *log,
 * SEE ALSO
 *********/
 
-/****f* OpenSM: Multicast Group/osm_mgrp_is_port_present
+/****f* OpenSM: Multicast Group/osm_mgrp_get_mcm_port
 * NAME
-*	osm_mgrp_is_port_present
+*	osm_mgrp_get_mcm_port
 *
 * DESCRIPTION
-*	checks a port from the multicast group.
+*	finds a port in the multicast group.
 *
 * SYNOPSIS
 */
-
-boolean_t
-osm_mgrp_is_port_present(IN const osm_mgrp_t * const p_mgrp,
-			 IN const ib_net64_t port_guid,
-			 OUT osm_mcm_port_t ** const pp_mcm_port);
+osm_mcm_port_t *osm_mgrp_get_mcm_port(IN const osm_mgrp_t * const p_mgrp,
+				      IN const ib_net64_t port_guid);
 /*
 * PARAMETERS
 *	p_mgrp
@@ -331,13 +331,8 @@ osm_mgrp_is_port_present(IN const osm_mgrp_t * const p_mgrp,
 *	port_guid
 *		[in] Port guid of the departing port.
 *
-*  pp_mcm_port
-*     [out] Pointer to a pointer to osm_mcm_port_t
-*           Updated to the member on success or NULLed
-*
 * RETURN VALUES
-*	TRUE if port present
-*	FALSE if port is not present.
+*	Pointer to the mcm port object when present or NULL otherwise.
 *
 * NOTES
 *
diff --git a/opensm/opensm/osm_multicast.c b/opensm/opensm/osm_multicast.c
index 5a10003..a674514 100644
--- a/opensm/opensm/osm_multicast.c
+++ b/opensm/opensm/osm_multicast.c
@@ -75,9 +75,7 @@ void osm_mgrp_delete(IN osm_mgrp_t * p_mgrp)
 	free(p_mgrp);
 }
 
-/**********************************************************************
- **********************************************************************/
-osm_mgrp_t *osm_mgrp_new(IN const ib_net16_t mlid)
+osm_mgrp_t *osm_mgrp_new(IN const ib_net16_t mlid, IN ib_member_rec_t * mcmr)
 {
 	osm_mgrp_t *p_mgrp;
 
@@ -88,10 +86,13 @@ osm_mgrp_t *osm_mgrp_new(IN const ib_net16_t mlid)
 	memset(p_mgrp, 0, sizeof(*p_mgrp));
 	cl_qmap_init(&p_mgrp->mcm_port_tbl);
 	p_mgrp->mlid = mlid;
+	p_mgrp->mcmember_rec = *mcmr;
 
 	return p_mgrp;
 }
 
+/**********************************************************************
+ **********************************************************************/
 void osm_mgrp_cleanup(osm_subn_t * subn, osm_mgrp_t * mgrp)
 {
 	osm_mcm_port_t *mcm_port;
@@ -207,8 +208,6 @@ osm_mcm_port_t *osm_mgrp_add_port(IN osm_subn_t * subn, osm_log_t * log,
 	return mcm_port;
 }
 
-/**********************************************************************
- **********************************************************************/
 void osm_mgrp_remove_port(osm_subn_t * subn, osm_log_t * log, osm_mgrp_t * mgrp,
 			  osm_mcm_port_t * mcm_port, ib_member_rec_t *mcmr)
 {
@@ -277,22 +276,11 @@ void osm_mgrp_delete_port(osm_subn_t * subn, osm_log_t * log, osm_mgrp_t * mgrp,
 
 /**********************************************************************
  **********************************************************************/
-boolean_t osm_mgrp_is_port_present(IN const osm_mgrp_t * p_mgrp,
-				   IN const ib_net64_t port_guid,
-				   OUT osm_mcm_port_t ** const pp_mcm_port)
+osm_mcm_port_t *osm_mgrp_get_mcm_port(IN const osm_mgrp_t * p_mgrp,
+				      IN const ib_net64_t port_guid)
 {
-	cl_map_item_t *p_map_item;
-
-	CL_ASSERT(p_mgrp);
-
-	p_map_item = cl_qmap_get(&p_mgrp->mcm_port_tbl, port_guid);
-
-	if (p_map_item != cl_qmap_end(&p_mgrp->mcm_port_tbl)) {
-		if (pp_mcm_port)
-			*pp_mcm_port = (osm_mcm_port_t *) p_map_item;
-		return TRUE;
-	}
-	if (pp_mcm_port)
-		*pp_mcm_port = NULL;
-	return FALSE;
+	cl_map_item_t *item = cl_qmap_get(&p_mgrp->mcm_port_tbl, port_guid);
+	if (item != cl_qmap_end(&p_mgrp->mcm_port_tbl))
+		return (osm_mcm_port_t *)item;
+	return NULL;
 }
diff --git a/opensm/opensm/osm_sa_mcmember_record.c b/opensm/opensm/osm_sa_mcmember_record.c
index 8f7816b..f581663 100644
--- a/opensm/opensm/osm_sa_mcmember_record.c
+++ b/opensm/opensm/osm_sa_mcmember_record.c
@@ -340,10 +340,10 @@ static boolean_t validate_modify(IN osm_sa_t * sa, IN osm_mgrp_t * p_mgrp,
 
 	portguid = p_recvd_mcmember_rec->port_gid.unicast.interface_id;
 
-	*pp_mcm_port = NULL;
+	*pp_mcm_port = osm_mgrp_get_mcm_port(p_mgrp, portguid);
 
 	/* o15-0.2.1: If this is a new port being added - nothing to check */
-	if (!osm_mgrp_is_port_present(p_mgrp, portguid, pp_mcm_port)) {
+	if (!*pp_mcm_port) {
 		OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
 			"This is a new port in the MC group\n");
 		return TRUE;
@@ -428,10 +428,10 @@ static boolean_t validate_delete(IN osm_sa_t * sa, IN osm_mgrp_t * p_mgrp,
 
 	portguid = p_recvd_mcmember_rec->port_gid.unicast.interface_id;
 
-	*pp_mcm_port = NULL;
+	*pp_mcm_port = osm_mgrp_get_mcm_port(p_mgrp, portguid);
 
 	/* 1 */
-	if (!osm_mgrp_is_port_present(p_mgrp, portguid, pp_mcm_port)) {
+	if (!*pp_mcm_port) {
 		OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
 			"Failed to find the port in the MC group\n");
 		return FALSE;
@@ -812,7 +812,8 @@ ib_api_status_t osm_mcmr_rcv_create_new_mgrp(IN osm_sa_t * sa,
 	}
 
 	/* create a new MC Group */
-	*pp_mgrp = osm_mgrp_new(mlid);
+	mcm_rec.mlid = mlid;
+	*pp_mgrp = osm_mgrp_new(mlid, &mcm_rec);
 	if (*pp_mgrp == NULL) {
 		OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1B08: "
 			"osm_mgrp_new failed\n");
@@ -821,10 +822,6 @@ ib_api_status_t osm_mcmr_rcv_create_new_mgrp(IN osm_sa_t * sa,
 		goto Exit;
 	}
 
-	/* Initialize the mgrp */
-	(*pp_mgrp)->mcmember_rec = mcm_rec;
-	(*pp_mgrp)->mcmember_rec.mlid = mlid;
-
 	/* the mcmember_record should have mtu_sel, rate_sel, and pkt_lifetime_sel = 2 */
 	(*pp_mgrp)->mcmember_rec.mtu &= 0x3f;
 	(*pp_mgrp)->mcmember_rec.mtu |= 2 << 6;	/* exactly */
@@ -1307,13 +1304,12 @@ static void mcmr_by_comp_mask(osm_sa_t * sa, const ib_member_rec_t * p_rcvd_rec,
 	/* so did we get the PortGUID mask */
 	if (IB_MCR_COMPMASK_PORT_GID & comp_mask) {
 		/* try to find this port */
-		if (osm_mgrp_is_port_present(p_mgrp, portguid, &p_mcm_port)) {
-			scope_state = p_mcm_port->scope_state;
-			memcpy(&port_gid, &(p_mcm_port->port_gid),
-			       sizeof(ib_gid_t));
-			proxy_join = p_mcm_port->proxy_join;
-		} else /* port not in group */
+		p_mcm_port = osm_mgrp_get_mcm_port(p_mgrp, portguid);
+		if (!p_mcm_port) /* port not in group */
 			goto Exit;
+		scope_state = p_mcm_port->scope_state;
+		memcpy(&port_gid, &(p_mcm_port->port_gid), sizeof(ib_gid_t));
+		proxy_join = p_mcm_port->proxy_join;
 	} else /* point to the group information */
 		scope_state = p_mgrp->mcmember_rec.scope_state;
 
-- 
1.6.5.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] opensm/osm_sa_path_record.c: validate multicast membership
  2009-09-19 16:58 [PATCH] opensm/multicast: improve function prototypes Sasha Khapyorsky
@ 2009-09-19 16:59 ` Sasha Khapyorsky
  2009-09-19 17:00   ` [PATCH] opensm: discard multicast SA PR with wildcard DGID Sasha Khapyorsky
  2009-09-19 17:00   ` [PATCH] opensm: osm_get_port_by_lid() helper Sasha Khapyorsky
  0 siblings, 2 replies; 4+ messages in thread
From: Sasha Khapyorsky @ 2009-09-19 16:59 UTC (permalink / raw)
  To: OpenIB, linux-rdma; +Cc: Eli Dorfman, Slava Strebkov, Hal Rosenstock


When PathRecord query has multicast destination and SLID and/or SGID is
specified we need to ensure that this path source port is member of the
destination multicast group.

Signed-off-by: Sasha Khapyorsky <sashak-smomgflXvOZWk0Htik3J/w@public.gmane.org>
---
 opensm/opensm/osm_sa_path_record.c |   14 ++++++++++++++
 1 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/opensm/opensm/osm_sa_path_record.c b/opensm/opensm/osm_sa_path_record.c
index 75d9516..f68be20 100644
--- a/opensm/opensm/osm_sa_path_record.c
+++ b/opensm/opensm/osm_sa_path_record.c
@@ -1488,6 +1488,7 @@ static ib_api_status_t pr_match_mgrp_attributes(IN osm_sa_t * sa,
 	const ib_path_rec_t *p_pr;
 	const ib_sa_mad_t *p_sa_mad;
 	ib_net64_t comp_mask;
+	const osm_port_t *port;
 	ib_api_status_t status = IB_ERROR;
 	uint32_t flow_label;
 	uint8_t sl;
@@ -1501,6 +1502,19 @@ static ib_api_status_t pr_match_mgrp_attributes(IN osm_sa_t * sa,
 	comp_mask = p_sa_mad->comp_mask;
 
 	/* If SGID and/or SLID specified, should validate as member of MC group */
+	if (comp_mask & IB_PR_COMPMASK_SGID) {
+		port = osm_get_port_by_guid(sa->p_subn,
+					    p_pr->sgid.unicast.interface_id);
+		if (!port || !osm_mgrp_get_mcm_port(p_mgrp, port->guid))
+			goto Exit;
+	}
+
+	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))
+			goto Exit;
+	}
+
 	/* Also, MTU, rate, packet lifetime, and raw traffic requested are not currently checked */
 	if (comp_mask & IB_PR_COMPMASK_PKEY) {
 		if (p_pr->pkey != p_mgrp->mcmember_rec.pkey)
-- 
1.6.5.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] opensm: discard multicast SA PR with wildcard DGID
  2009-09-19 16:59 ` [PATCH] opensm/osm_sa_path_record.c: validate multicast membership Sasha Khapyorsky
@ 2009-09-19 17:00   ` Sasha Khapyorsky
  2009-09-19 17:00   ` [PATCH] opensm: osm_get_port_by_lid() helper Sasha Khapyorsky
  1 sibling, 0 replies; 4+ messages in thread
From: Sasha Khapyorsky @ 2009-09-19 17:00 UTC (permalink / raw)
  To: OpenIB, linux-rdma; +Cc: Eli Dorfman, Slava Strebkov, Hal Rosenstock


IBA 1.2.1 states (Vol.1, 15.2.5.16, p.918) that DGID shell be explicitly
specified when path destination of SA PathRecord query is multicast
group.

Signed-off-by: Sasha Khapyorsky <sashak-smomgflXvOZWk0Htik3J/w@public.gmane.org>
---
 opensm/opensm/osm_sa_path_record.c |   45 ++++++++++++------------------------
 1 files changed, 15 insertions(+), 30 deletions(-)

diff --git a/opensm/opensm/osm_sa_path_record.c b/opensm/opensm/osm_sa_path_record.c
index f68be20..37f32ac 100644
--- a/opensm/opensm/osm_sa_path_record.c
+++ b/opensm/opensm/osm_sa_path_record.c
@@ -1437,45 +1437,27 @@ static osm_mgrp_t *pr_get_mgrp(IN osm_sa_t * sa, IN const osm_madw_t * p_madw)
 {
 	ib_path_rec_t *p_pr;
 	const ib_sa_mad_t *p_sa_mad;
-	ib_net64_t comp_mask;
-	osm_mgrp_t *mgrp = NULL;
+	osm_mgrp_t *mgrp;
 
 	p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
-	p_pr = (ib_path_rec_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
+	p_pr = ib_sa_mad_get_payload_ptr(p_sa_mad);
 
-	comp_mask = p_sa_mad->comp_mask;
+	if (!(p_sa_mad->comp_mask & IB_PR_COMPMASK_DGID)) {
+		OSM_LOG(sa->p_log, OSM_LOG_VERBOSE,
+			"discard multicast target SA PR with wildcarded MGID");
+		return NULL;
+	}
 
-	if ((comp_mask & IB_PR_COMPMASK_DGID) &&
-	    !(mgrp = osm_get_mgrp_by_mgid(sa, &p_pr->dgid))) {
+	mgrp = osm_get_mgrp_by_mgid(sa, &p_pr->dgid);
+	if (!mgrp) {
 		char gid_str[INET6_ADDRSTRLEN];
 		OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1F09: "
 			"No MC group found for PathRecord destination GID %s\n",
 			inet_ntop(AF_INET6, p_pr->dgid.raw, gid_str,
 				  sizeof gid_str));
-		goto Exit;
-	}
-
-	if (comp_mask & IB_PR_COMPMASK_DLID) {
-		if (mgrp) {
-			/* check that the MLID in the MC group is */
-			/* the same as the DLID in the PathRecord */
-			if (mgrp->mlid != p_pr->dlid) {
-				/* Note: perhaps this might be better indicated as an invalid request */
-				OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1F10: "
-					"MC group MLID 0x%x does not match "
-					"PathRecord destination LID 0x%x\n",
-					mgrp->mlid, p_pr->dlid);
-				mgrp = NULL;
-				goto Exit;
-			}
-		} else
-		    if (!(mgrp = osm_get_mgrp_by_mlid(sa->p_subn, p_pr->dlid)))
-			OSM_LOG(sa->p_log, OSM_LOG_ERROR,
-				"ERR 1F11: " "No MC group found for PathRecord "
-				"destination LID 0x%x\n", p_pr->dlid);
+		return NULL;
 	}
 
-Exit:
 	return mgrp;
 }
 
@@ -1497,10 +1479,14 @@ static ib_api_status_t pr_match_mgrp_attributes(IN osm_sa_t * sa,
 	OSM_LOG_ENTER(sa->p_log);
 
 	p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
-	p_pr = (ib_path_rec_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
+	p_pr = ib_sa_mad_get_payload_ptr(p_sa_mad);
 
 	comp_mask = p_sa_mad->comp_mask;
 
+	/* check that MLID of the MC group matchs the PathRecord DLID */
+	if ((comp_mask & IB_PR_COMPMASK_DLID) && p_mgrp->mlid != p_pr->dlid)
+		goto Exit;
+
 	/* If SGID and/or SLID specified, should validate as member of MC group */
 	if (comp_mask & IB_PR_COMPMASK_SGID) {
 		port = osm_get_port_by_guid(sa->p_subn,
@@ -1713,7 +1699,6 @@ McastDest:
 
 		/* First, get the MC info */
 		p_mgrp = pr_get_mgrp(sa, p_madw);
-
 		if (!p_mgrp)
 			goto Unlock;
 
-- 
1.6.5.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] opensm: osm_get_port_by_lid() helper
  2009-09-19 16:59 ` [PATCH] opensm/osm_sa_path_record.c: validate multicast membership Sasha Khapyorsky
  2009-09-19 17:00   ` [PATCH] opensm: discard multicast SA PR with wildcard DGID Sasha Khapyorsky
@ 2009-09-19 17:00   ` Sasha Khapyorsky
  1 sibling, 0 replies; 4+ messages in thread
From: Sasha Khapyorsky @ 2009-09-19 17:00 UTC (permalink / raw)
  To: OpenIB, linux-rdma; +Cc: Eli Dorfman, Slava Strebkov, Hal Rosenstock


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 <sashak-smomgflXvOZWk0Htik3J/w@public.gmane.org>
---
 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;
-- 
1.6.5.rc1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-09-19 17:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-19 16:58 [PATCH] opensm/multicast: improve function prototypes Sasha Khapyorsky
2009-09-19 16:59 ` [PATCH] opensm/osm_sa_path_record.c: validate multicast membership Sasha Khapyorsky
2009-09-19 17:00   ` [PATCH] opensm: discard multicast SA PR with wildcard DGID Sasha Khapyorsky
2009-09-19 17:00   ` [PATCH] opensm: osm_get_port_by_lid() helper Sasha Khapyorsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox