Skip to contentSkip to conversation

opensm: conversion to osm_get_port_by_lid()

PATCH New Sasha Khapyorsky 1 participant 1 message Apr 25, 2010 InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 opensm: conversion to osm_get_port_by_lid()

Simplify many obvious flows by using osm_get_port_by_lid*() helpers.

This also introduces osm_get_port_by_lid_ho() helper where lid parameter is used in host byte order - this is in order to prevent double byte order conversion in routing engines code.

---
 opensm/include/opensm/osm_subnet.h     |   33 +++++++++++++-
 opensm/opensm/osm_console.c            |    4 +-
 opensm/opensm/osm_dump.c               |    6 +-
 opensm/opensm/osm_inform.c             |    5 +-
 opensm/opensm/osm_link_mgr.c           |    9 +---
 opensm/opensm/osm_sa_informinfo.c      |    2 +-
 opensm/opensm/osm_sa_path_record.c     |   75 ++++++++++++--------------------
 opensm/opensm/osm_sa_portinfo_record.c |   37 +++-------------
 opensm/opensm/osm_subnet.c             |   23 ++--------
 opensm/opensm/osm_trap_rcv.c           |   51 ++++++---------------
 opensm/opensm/osm_ucast_ftree.c        |    4 +-
 opensm/opensm/osm_ucast_lash.c         |    2 +-
 opensm/opensm/osm_ucast_updn.c         |   18 +++----
 13 files changed, 106 insertions(+), 163 deletions(-)
opensm/include/opensm/osm_subnet.h +31 -2
index 8a7c0d9..d79ed8f 100644
@@ -958,6 +958,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_ho
+* NAME
+*	osm_get_port_by_lid_ho
+*
+* DESCRIPTION
+*	Returns a pointer of the port object for given lid value.
+*
+* SYNOPSIS
+*/
+struct osm_port *osm_get_port_by_lid_ho(const osm_subn_t * subn, uint16_t lid);
+/*
+* PARAMETERS
+*	subn
+*		[in] Pointer to the subnet data structure.
+*
+*	lid
+*		[in] LID requested in hot byte order.
+*
+* RETURN VALUES
+*	The port structure pointer if found. NULL otherwise.
+*
+* SEE ALSO
+*       Subnet object, osm_port_t
+*********/
+
 /****f* OpenSM: Port/osm_get_port_by_lid
 * NAME
 *	osm_get_port_by_lid
@@ -967,14 +992,18 @@ struct osm_port *osm_get_port_by_guid(IN osm_subn_t const *p_subn,
 *
 * SYNOPSIS
 */
-struct osm_port *osm_get_port_by_lid(const osm_subn_t * subn, ib_net16_t lid);
+static inline struct osm_port *osm_get_port_by_lid(IN osm_subn_t const * subn,
+						   IN ib_net16_t lid)
+{
+	return osm_get_port_by_lid_ho(subn, cl_ntoh16(lid));
+}
 /*
 * PARAMETERS
 *	subn
 *		[in] Pointer to the subnet data structure.
 *
 *	lid
-*		[in] LID requested.
+*		[in] LID requested in network byte order.
 *
 * RETURN VALUES
 *	The port structure pointer if found. NULL otherwise.
opensm/opensm/osm_console.c +1 -3
index a27bee3..968486e 100644
@@ -515,9 +515,7 @@ static void querylid_parse(char **p_last, osm_opensm_t * p_osm, FILE * out)
 
 	lid = (uint16_t) strtoul(p_cmd, NULL, 0);
 	cl_plock_acquire(&p_osm->lock);
-	if (lid > cl_ptr_vector_get_capacity(&(p_osm->subn.port_lid_tbl)))
-		goto invalid_lid;
-	p_port = cl_ptr_vector_get(&(p_osm->subn.port_lid_tbl), lid);
+	p_port = osm_get_port_by_lid_ho(&p_osm->subn, lid);
 	if (!p_port)
 		goto invalid_lid;
 
opensm/opensm/osm_dump.c +3 -3
index 86e9c00..fe2c3bc 100644
@@ -140,7 +140,7 @@ static void dump_ucast_routes(cl_map_item_t * item, FILE * file, void *cxt)
 	for (lid_ho = 1; lid_ho <= max_lid_ho; lid_ho++) {
 		fprintf(file, "0x%04X : ", lid_ho);
 
-		p_port = cl_ptr_vector_get(&p_osm->subn.port_lid_tbl, lid_ho);
+		p_port = osm_get_port_by_lid_ho(&p_osm->subn, lid_ho);
 		if (!p_port) {
 			fprintf(file, "UNREACHABLE\n");
 			continue;
@@ -313,7 +313,7 @@ static void dump_lid_matrix(cl_map_item_t * item, FILE * file, void *cxt)
 		for (port = 0; port < max_port; port++)
 			fprintf(file, " %02x",
 				osm_switch_get_hop_count(p_sw, lid, port));
-		p_port = cl_ptr_vector_get(&p_osm->subn.port_lid_tbl, lid);
+		p_port = osm_get_port_by_lid_ho(&p_osm->subn, lid);
 		if (p_port)
 			fprintf(file, " # portguid 0x016%" PRIx64,
 				cl_ntoh64(osm_port_get_guid(p_port)));
@@ -344,7 +344,7 @@ static void dump_ucast_lfts(cl_map_item_t * item, FILE * file, void *cxt)
 
 		fprintf(file, "0x%04x %03u # ", lid, port);
 
-		p_port = cl_ptr_vector_get(&p_osm->subn.port_lid_tbl, lid);
+		p_port = osm_get_port_by_lid_ho(&p_osm->subn, lid);
 		if (p_port) {
 			p_node = p_port->p_node;
 			fprintf(file, "%s portguid 0x%016" PRIx64 ": \'%s\'",
opensm/opensm/osm_inform.c +2 -3
index 8108213..46aa835 100644
@@ -485,9 +485,8 @@ static void match_notice_to_inf_rec(IN cl_list_item_t * p_list_item,
 		goto Exit;
 	}
 
-	p_dest_port =
-	    cl_ptr_vector_get(&p_subn->port_lid_tbl,
-			      cl_ntoh16(p_infr_rec->report_addr.dest_lid));
+	p_dest_port = osm_get_port_by_lid(p_subn,
+					  p_infr_rec->report_addr.dest_lid);
 	if (!p_dest_port) {
 		OSM_LOG(p_log, OSM_LOG_INFO,
 			"Cannot find destination port with LID:%u\n",
opensm/opensm/osm_link_mgr.c +3 -6
index 03a585b..e6c9b3b 100644
@@ -59,7 +59,7 @@ static uint8_t link_mgr_get_smsl(IN osm_sm_t * sm, IN osm_physp_t * p_physp)
 {
 	osm_opensm_t *p_osm = sm->p_subn->p_osm;
 	const osm_port_t *p_sm_port, *p_src_port;
-	ib_net16_t slid, smlid;
+	ib_net16_t slid;
 	uint8_t sl;
 
 	OSM_LOG_ENTER(sm->p_log);
@@ -72,13 +72,10 @@ static uint8_t link_mgr_get_smsl(IN osm_sm_t * sm, IN osm_physp_t * p_physp)
 	}
 
 	/* Find osm_port of the SM itself = dest_port */
-	smlid = sm->p_subn->sm_base_lid;
-	p_sm_port =
-	    cl_ptr_vector_get(&sm->p_subn->port_lid_tbl, cl_ntoh16(smlid));
+	p_sm_port = osm_get_port_by_lid(sm->p_subn, sm->p_subn->sm_base_lid);
 
 	/* Find osm_port of the source = p_physp */
-	p_src_port =
-	    cl_ptr_vector_get(&sm->p_subn->port_lid_tbl, cl_ntoh16(slid));
+	p_src_port = osm_get_port_by_lid(sm->p_subn, slid);
 
 	/* Call lash to find proper SL */
 	sl = osm_get_lash_sl(p_osm, p_src_port, p_sm_port);
opensm/opensm/osm_sa_informinfo.c +1 -1
index 9fb3608..be7aba7 100644
@@ -158,7 +158,7 @@ static boolean_t validate_ports_access_rights(IN osm_sa_t * sa,
 		/* go over all defined lids within the range and make sure that the
 		   requester port can access them according to current partitioning. */
 		for (lid = lid_range_begin; lid <= lid_range_end; lid++) {
-			p_port = osm_get_port_by_lid(sa->p_subn, cl_hton16(lid));
+			p_port = osm_get_port_by_lid_ho(sa->p_subn, lid);
 			if (p_port == NULL)
 				continue;
 
opensm/opensm/osm_sa_path_record.c +28 -47

113 lines not on this page · raw message

opensm/opensm/osm_sa_portinfo_record.c +7 -30
index 72b976c..c5b88b8 100644
@@ -442,12 +442,10 @@ void osm_pir_rcv_process(IN void *ctx, IN void *data)
 	osm_madw_t *p_madw = data;
 	const ib_sa_mad_t *p_rcvd_mad;
 	const ib_portinfo_record_t *p_rcvd_rec;
-	const cl_ptr_vector_t *p_tbl;
 	const osm_port_t *p_port = NULL;
 	const ib_port_info_t *p_pi;
 	cl_qlist_t rec_list;
 	osm_pir_search_ctxt_t context;
-	ib_api_status_t status = IB_SUCCESS;
 	ib_net64_t comp_mask;
 	osm_physp_t *p_req_physp;
 
@@ -487,7 +485,6 @@ void osm_pir_rcv_process(IN void *ctx, IN void *data)
 	if (osm_log_is_active(sa->p_log, OSM_LOG_DEBUG))
 		osm_dump_portinfo_record(sa->p_log, p_rcvd_rec, OSM_LOG_DEBUG);
 
-	p_tbl = &sa->p_subn->port_lid_tbl;
 	p_pi = &p_rcvd_rec->port_info;
 
 	cl_qlist_init(&rec_list);
@@ -502,41 +499,21 @@ void osm_pir_rcv_process(IN void *ctx, IN void *data)
 
 	cl_plock_acquire(sa->p_lock);
 
-	CL_ASSERT(cl_ptr_vector_get_size(p_tbl) < 0x10000);
-
 	/*
 	   If the user specified a LID, it obviously narrows our
 	   work load, since we don't have to search every port
 	 */
-	if (comp_mask & IB_PIR_COMPMASK_LID) {
+	if (comp_mask & (IB_PIR_COMPMASK_LID | IB_PIR_COMPMASK_BASELID)) {
 		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",
-				cl_ntoh16(p_rcvd_rec->lid));
-		}
-	} else if (comp_mask & IB_PIR_COMPMASK_BASELID) {
-		if ((uint16_t) cl_ptr_vector_get_size(p_tbl) >
-		    cl_ntoh16(p_pi->base_lid))
-			p_port = cl_ptr_vector_get(p_tbl,
-						   cl_ntoh16(p_pi->base_lid));
-		else {
-			status = IB_NOT_FOUND;
-			OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2103: "
-				"Given LID (%u) is out of range:%u\n",
-				cl_ntoh16(p_pi->base_lid),
-				cl_ptr_vector_get_size(p_tbl));
-		}
-	}
-
-	if (status == IB_SUCCESS) {
 		if (p_port)
 			sa_pir_by_comp_mask(sa, p_port->p_node, &context);
 		else
-			cl_qmap_apply_func(&sa->p_subn->node_guid_tbl,
-					   sa_pir_by_comp_mask_cb, &context);
-	}
+			OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 2109: "
+				"No port found with LID %u\n",
+				cl_ntoh16(p_rcvd_rec->lid));
+	} else
+		cl_qmap_apply_func(&sa->p_subn->node_guid_tbl,
+				   sa_pir_by_comp_mask_cb, &context);
 
 	cl_plock_release(sa->p_lock);
 
opensm/opensm/osm_subnet.c +4 -19
index 6acf4bc..ac8cb37 100644
@@ -539,27 +539,13 @@ osm_port_t *osm_get_port_by_mad_addr(IN osm_log_t * p_log,
 				     IN const osm_subn_t * p_subn,
 				     IN osm_mad_addr_t * p_mad_addr)
 {
-	const cl_ptr_vector_t *p_port_lid_tbl;
-	osm_port_t *p_port = NULL;
-
-	/* Find the port gid of the request in the subnet */
-	p_port_lid_tbl = &p_subn->port_lid_tbl;
-
-	CL_ASSERT(cl_ptr_vector_get_size(p_port_lid_tbl) < 0x10000);
-
-	if ((uint16_t) cl_ptr_vector_get_size(p_port_lid_tbl) >
-	    cl_ntoh16(p_mad_addr->dest_lid)) {
-		p_port =
-		    cl_ptr_vector_get(p_port_lid_tbl,
-				      cl_ntoh16(p_mad_addr->dest_lid));
-	} else {
-		/* The dest_lid is not in the subnet table - this is an error */
+	osm_port_t *port = osm_get_port_by_lid(p_subn, p_mad_addr->dest_lid);
+	if (!port)
 		OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 7504: "
 			"Lid is out of range: %u\n",
 			cl_ntoh16(p_mad_addr->dest_lid));
-	}
 
-	return p_port;
+	return port;
 }
 
 ib_api_status_t osm_get_gid_by_mad_addr(IN osm_log_t * p_log,
@@ -629,9 +615,8 @@ osm_port_t *osm_get_port_by_guid(IN osm_subn_t const *p_subn, IN ib_net64_t guid
 	return p_port;
 }
 
-osm_port_t *osm_get_port_by_lid(IN osm_subn_t const * subn, IN ib_net16_t lid)
+osm_port_t *osm_get_port_by_lid_ho(IN osm_subn_t const * subn, IN uint16_t lid)
 {
-	lid = cl_ntoh16(lid);
 	if (lid < cl_ptr_vector_get_size(&subn->port_lid_tbl))
 		return cl_ptr_vector_get(&subn->port_lid_tbl, lid);
 	return NULL;
opensm/opensm/osm_trap_rcv.c +15 -36

123 lines not on this page · raw message

opensm/opensm/osm_ucast_ftree.c +2 -2
index 39268eb..88ea344 100644
@@ -2994,8 +2994,8 @@ static void fabric_route_roots(IN ftree_fabric_t * p_ftree)
 			    p_leaf_sw->hops[lid] == OSM_NO_PATH)
 				continue;
 
-			p_port = cl_ptr_vector_get(
-				&p_ftree->p_osm->subn.port_lid_tbl, lid);
+			p_port = osm_get_port_by_lid_ho(&p_ftree->p_osm->subn,
+							lid);
 
 			/* we're interested only in switches */
 			if (!p_port || !p_port->p_node->sw)
opensm/opensm/osm_ucast_lash.c +1 -1
index 3054a56..4669946 100644
@@ -1008,7 +1008,7 @@ static void populate_fwd_tbls(lash_t * p_lash)
 		memset(p_sw->new_lft, OSM_NO_PATH, p_sw->lft_size);
 
 		for (lid = 1; lid <= max_lid_ho; lid++) {
-			port = cl_ptr_vector_get(&p_subn->port_lid_tbl, lid);
+			port = osm_get_port_by_lid_ho(p_subn, lid);
 			if (!port)
 				continue;
 
opensm/opensm/osm_ucast_updn.c +8 -10
index 01e40eb..164c6f4 100644
@@ -280,20 +280,18 @@ static int updn_subn_rank(IN updn_t * p_updn)
 }
 
 /* hack: preserve min hops entries to any other root switches */
-static void updn_clear_non_root_hops(updn_t * p_updn, osm_switch_t * p_sw)
+static void updn_clear_non_root_hops(updn_t * updn, osm_switch_t * sw)
 {
-	osm_port_t *p_port;
+	osm_port_t *port;
 	unsigned i;
 
-	for (i = 0; i < p_sw->num_hops; i++)
-		if (p_sw->hops[i]) {
-			p_port =
-			    cl_ptr_vector_get(&p_updn->p_osm->subn.port_lid_tbl,
-					      i);
-			if (!p_port || !p_port->p_node->sw
-			    || ((struct updn_node *)p_port->p_node->sw->priv)->
+	for (i = 0; i < sw->num_hops; i++)
+		if (sw->hops[i]) {
+			port = osm_get_port_by_lid_ho(&updn->p_osm->subn, i);
+			if (!port || !port->p_node->sw
+			    || ((struct updn_node *)port->p_node->sw->priv)->
 			    rank != 0)
-				memset(p_sw->hops[i], 0xff, p_sw->num_ports);
+				memset(sw->hops[i], 0xff, sw->num_ports);
 		}
 }
 
Signature · 6 lines
1.7.0.4

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html