[ofa-general] [PATCH 10/10] infiniband-diags: Convert perfquery, saquery, sminfo, smpquery, and vendstat to "new" ibmad interface

Ira Weiny weiny2 at llnl.gov
Thu Feb 19 19:06:08 PST 2009


>From e809dfacb08e6c2237ad2d0f197d1227654dde87 Mon Sep 17 00:00:00 2001
From: Ira Weiny <weiny2 at llnl.gov>
Date: Thu, 19 Feb 2009 18:53:10 -0800
Subject: [PATCH] infiniband-diags: Convert perfquery, saquery, sminfo, smpquery, and vendstat to "new" ibmad interface


Signed-off-by: Ira Weiny <weiny2 at llnl.gov>
---
 infiniband-diags/src/perfquery.c |   35 +++++++++++++++++--------
 infiniband-diags/src/saquery.c   |    9 ++++--
 infiniband-diags/src/sminfo.c    |   18 +++++++++---
 infiniband-diags/src/smpquery.c  |   53 +++++++++++++++++++++++--------------
 infiniband-diags/src/vendstat.c  |   19 ++++++++-----
 5 files changed, 88 insertions(+), 46 deletions(-)

diff --git a/infiniband-diags/src/perfquery.c b/infiniband-diags/src/perfquery.c
index 6292743..2f104b8 100644
--- a/infiniband-diags/src/perfquery.c
+++ b/infiniband-diags/src/perfquery.c
@@ -47,6 +47,8 @@
 
 #include "ibdiag_common.h"
 
+struct ibmad_port *srcport;
+
 struct perf_count {
 	uint32_t portselect;
 	uint32_t counterselect;
@@ -269,7 +271,7 @@ static void dump_perfcounters(int extended, int timeout, uint16_t cap_mask,
 	char buf[1024];
 
 	if (extended != 1) {
-		if (!port_performance_query(pc, portid, port, timeout))
+		if (!port_performance_query_via(pc, portid, port, timeout, srcport))
 			IBERROR("perfquery");
 		if (!(cap_mask & 0x1000)) {
 			/* if PortCounters:PortXmitWait not suppported clear this counter */
@@ -284,7 +286,7 @@ static void dump_perfcounters(int extended, int timeout, uint16_t cap_mask,
 		if (!(cap_mask & 0x200)) /* 1.2 errata: bit 9 is extended counter support */
 			IBWARN("PerfMgt ClassPortInfo 0x%x extended counters not indicated\n", cap_mask);
 
-		if (!port_performance_ext_query(pc, portid, port, timeout))
+		if (!port_performance_ext_query_via(pc, portid, port, timeout, srcport))
 			IBERROR("perfextquery");
 		if (aggregate)
 			aggregate_perfcounters_ext();
@@ -299,10 +301,12 @@ static void dump_perfcounters(int extended, int timeout, uint16_t cap_mask,
 static void reset_counters(int extended, int timeout, int mask, ib_portid_t *portid, int port)
 {
 	if (extended != 1) {
-		if (!port_performance_reset(pc, portid, port, mask, timeout))
+		if (!port_performance_reset_via(pc, portid, port, mask,
+				timeout, srcport))
 			IBERROR("perf reset");
 	} else {
-		if (!port_performance_ext_reset(pc, portid, port, mask, timeout))
+		if (!port_performance_ext_reset_via(pc, portid, port, mask,
+				timeout, srcport))
 			IBERROR("perf ext reset");
 	}
 }
@@ -382,18 +386,22 @@ int main(int argc, char **argv)
 	if (argc > 2)
 		mask = strtoul(argv[2], 0, 0);
 
-	madrpc_init(ibd_ca, ibd_ca_port, mgmt_classes, 4);
+	srcport = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 4);
+	if (!srcport)
+		IBERROR("Failed to open '%s' port '%d'", ibd_ca, ibd_ca_port);
 
 	if (argc) {
-		if (ib_resolve_portid_str(&portid, argv[0], ibd_dest_type, ibd_sm_id) < 0)
+		if (ib_resolve_portid_str_via(&portid, argv[0], ibd_dest_type,
+				ibd_sm_id, srcport) < 0)
 			IBERROR("can't resolve destination port %s", argv[0]);
 	} else {
-		if (ib_resolve_self(&portid, &port, 0) < 0)
+		if (ib_resolve_self_via(&portid, &port, 0, srcport) < 0)
 			IBERROR("can't resolve self port %s", argv[0]);
 	}
 
 	/* PerfMgt ClassPortInfo is a required attribute */
-	if (!perf_classportinfo_query(pc, &portid, port, ibd_timeout))
+	if (!perf_classportinfo_query_via(pc, &portid, port,
+			ibd_timeout, srcport))
 		IBERROR("classportinfo query");
 	/* ClassPortInfo should be supported as part of libibmad */
 	memcpy(&cap_mask, pc + 2, sizeof(cap_mask));	/* CapabilityMask */
@@ -406,7 +414,8 @@ int main(int argc, char **argv)
 	}
 
 	if (all_ports_loop || (loop_ports && (all_ports || port == ALL_PORTS))) {
-		if (smp_query(data, &portid, IB_ATTR_NODE_INFO, 0, 0) < 0)
+		if (smp_query_via(data, &portid, IB_ATTR_NODE_INFO, 0, 0,
+				srcport) < 0)
 			IBERROR("smp query nodeinfo failed");
 		node_type = mad_get_field(data, 0, IB_NODE_TYPE_F);
 		mad_decode_field(data, IB_NODE_NPORTS_F, &num_ports);
@@ -414,7 +423,8 @@ int main(int argc, char **argv)
 			IBERROR("smp query nodeinfo: num ports invalid");
 
 		if (node_type == IB_NODE_SWITCH) {
-			if (smp_query(data, &portid, IB_ATTR_SWITCH_INFO, 0, 0) < 0)
+			if (smp_query_via(data, &portid, IB_ATTR_SWITCH_INFO,
+					0, 0, srcport) < 0)
 				IBERROR("smp query nodeinfo failed");
 			enhancedport0 = mad_get_field(data, 0, IB_SW_ENHANCED_PORT0_F);
 			if (enhancedport0)
@@ -441,8 +451,10 @@ int main(int argc, char **argv)
 	else
 		dump_perfcounters(extended, ibd_timeout, cap_mask, &portid, port, 0);
 
-	if (!reset)
+	if (!reset) {
+		mad_rpc_close_port(srcport);
 		exit(0);
+	}
 
 do_reset:
 
@@ -456,5 +468,6 @@ do_reset:
 	else
 		reset_counters(extended, ibd_timeout, mask, &portid, port);
 
+	mad_rpc_close_port(srcport);
 	exit(0);
 }
diff --git a/infiniband-diags/src/saquery.c b/infiniband-diags/src/saquery.c
index 9726d22..e6cbe50 100644
--- a/infiniband-diags/src/saquery.c
+++ b/infiniband-diags/src/saquery.c
@@ -1316,12 +1316,15 @@ static int query_mft_records(const struct query_cmd *q, bind_handle_t h,
 
 static bind_handle_t get_bind_handle(void)
 {
+	static struct ibmad_port *srcport;
 	static struct bind_handle handle;
 	int mgmt_classes[2] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS };
 
-	madrpc_init(ibd_ca, ibd_ca_port, mgmt_classes, 2);
+	srcport = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 2);
+	if (!srcport)
+		IBERROR("Failed to open '%s' port '%d'", ibd_ca, ibd_ca_port);
 
-	ib_resolve_smlid(&handle.dport, ibd_timeout);
+	ib_resolve_smlid_via(&handle.dport, ibd_timeout, srcport);
 	if (!handle.dport.lid)
 		IBPANIC("No SM found.");
 
@@ -1329,7 +1332,7 @@ static bind_handle_t get_bind_handle(void)
 	if (!handle.dport.qkey)
 		handle.dport.qkey = IB_DEFAULT_QP1_QKEY;
 
-	handle.fd = madrpc_portid();
+	handle.fd = mad_rpc_portid(srcport);
 	handle.agent = umad_register(handle.fd, IB_SA_CLASS, 2, 1, NULL);
 
 	return &handle;
diff --git a/infiniband-diags/src/sminfo.c b/infiniband-diags/src/sminfo.c
index 549cb81..ebf6a47 100644
--- a/infiniband-diags/src/sminfo.c
+++ b/infiniband-diags/src/sminfo.c
@@ -48,6 +48,8 @@
 
 static uint8_t sminfo[1024];
 
+struct ibmad_port *srcport;
+
 int strdata, xdata=1, bindata;
 enum {
 	SMINFO_NOTACT,
@@ -113,13 +115,16 @@ int main(int argc, char **argv)
 	if (argc > 1)
 		mod = atoi(argv[1]);
 
-	madrpc_init(ibd_ca, ibd_ca_port, mgmt_classes, 3);
+	srcport = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 3);
+	if (!srcport)
+		IBERROR("Failed to open '%s' port '%d'", ibd_ca, ibd_ca_port);
 
 	if (argc) {
-		if (ib_resolve_portid_str(&portid, argv[0], ibd_dest_type, 0) < 0)
+		if (ib_resolve_portid_str_via(&portid, argv[0], ibd_dest_type,
+				0, srcport) < 0)
 			IBERROR("can't resolve destination port %s", argv[0]);
 	} else {
-		if (ib_resolve_smlid(&portid, ibd_timeout) < 0)
+		if (ib_resolve_smlid_via(&portid, ibd_timeout, srcport) < 0)
 			IBERROR("can't resolve sm port %s", argv[0]);
 	}
 
@@ -130,10 +135,12 @@ int main(int argc, char **argv)
 	mad_encode_field(sminfo, IB_SMINFO_STATE_F, &state);
 
 	if (mod) {
-		if (!(p = smp_set(sminfo, &portid, IB_ATTR_SMINFO, mod, ibd_timeout)))
+		if (!(p = smp_set_via(sminfo, &portid, IB_ATTR_SMINFO, mod,
+				ibd_timeout, srcport)))
 			IBERROR("query");
 	} else
-		if (!(p = smp_query(sminfo, &portid, IB_ATTR_SMINFO, 0, ibd_timeout)))
+		if (!(p = smp_query_via(sminfo, &portid, IB_ATTR_SMINFO, 0,
+				ibd_timeout, srcport)))
 			IBERROR("query");
 
 	mad_decode_field(sminfo, IB_SMINFO_GUID_F, &guid);
@@ -145,5 +152,6 @@ int main(int argc, char **argv)
 	printf("sminfo: sm lid %d sm guid 0x%" PRIx64 ", activity count %u priority %d state %d %s\n",
 		portid.lid, guid, act, prio, state, STATESTR(state));
 
+	mad_rpc_close_port(srcport);
 	exit(0);
 }
diff --git a/infiniband-diags/src/smpquery.c b/infiniband-diags/src/smpquery.c
index bf1626d..2ed1e65 100644
--- a/infiniband-diags/src/smpquery.c
+++ b/infiniband-diags/src/smpquery.c
@@ -51,6 +51,8 @@
 
 #include "ibdiag_common.h"
 
+struct ibmad_port *srcport;
+
 typedef char *(op_fn_t)(ib_portid_t *dest, char **argv, int argc);
 
 typedef struct match_rec {
@@ -88,13 +90,13 @@ node_desc(ib_portid_t *dest, char **argv, int argc)
 	char      dots[128];
 	char     *nodename = NULL;
 
-	if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
+	if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
 		return "node info query failed";
 
 	mad_decode_field(data, IB_NODE_TYPE_F, &node_type);
 	mad_decode_field(data, IB_NODE_GUID_F, &node_guid);
 
-	if (!smp_query(nd, dest, IB_ATTR_NODE_DESC, 0, 0))
+	if (!smp_query_via(nd, dest, IB_ATTR_NODE_DESC, 0, 0, srcport))
 		return "node desc query failed";
 
 	nodename = remap_node_name(node_name_map, node_guid, nd);
@@ -119,7 +121,7 @@ node_info(ib_portid_t *dest, char **argv, int argc)
 	char buf[2048];
 	char data[IB_SMP_DATA_SIZE];
 
-	if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
+	if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
 		return "node info query failed";
 
 	mad_dump_nodeinfo(buf, sizeof buf, data, sizeof data);
@@ -138,7 +140,7 @@ port_info(ib_portid_t *dest, char **argv, int argc)
 	if (argc > 0)
 		portnum = strtol(argv[0], 0, 0);
 
-	if (!smp_query(data, dest, IB_ATTR_PORT_INFO, portnum, 0))
+	if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, srcport))
 		return "port info query failed";
 
 	mad_dump_portinfo(buf, sizeof buf, data, sizeof data);
@@ -153,7 +155,7 @@ switch_info(ib_portid_t *dest, char **argv, int argc)
 	char buf[2048];
 	char data[IB_SMP_DATA_SIZE];
 
-	if (!smp_query(data, dest, IB_ATTR_SWITCH_INFO, 0, 0))
+	if (!smp_query_via(data, dest, IB_ATTR_SWITCH_INFO, 0, 0, srcport))
 		return "switch info query failed";
 
 	mad_dump_switchinfo(buf, sizeof buf, data, sizeof data);
@@ -176,7 +178,7 @@ pkey_table(ib_portid_t *dest, char **argv, int argc)
 		portnum = strtol(argv[0], 0, 0);
 
 	/* Get the partition capacity */
-	if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
+	if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
 		return "node info query failed";
 
 	mad_decode_field(data, IB_NODE_TYPE_F, &t);
@@ -185,7 +187,8 @@ pkey_table(ib_portid_t *dest, char **argv, int argc)
 		return "invalid port number";
 
 	if ((t == IB_NODE_SWITCH) && (portnum != 0)) {
-		if (!smp_query(data, dest, IB_ATTR_SWITCH_INFO, 0, 0))
+		if (!smp_query_via(data, dest, IB_ATTR_SWITCH_INFO, 0, 0,
+				srcport))
 			return "switch info failed";
 		mad_decode_field(data, IB_SW_PARTITION_ENFORCE_CAP_F, &n);
 	} else
@@ -193,7 +196,8 @@ pkey_table(ib_portid_t *dest, char **argv, int argc)
 
 	for (i = 0; i < (n + 31) / 32; i++) {
 		mod =  i | (portnum << 16);
-		if (!smp_query(data, dest, IB_ATTR_PKEY_TBL, mod, 0))
+		if (!smp_query_via(data, dest, IB_ATTR_PKEY_TBL, mod, 0,
+				srcport))
 			return "pkey table query failed";
 		if (i + 1 == (n + 31) / 32)
 			k = ((n + 7 - i * 32) / 8) * 8;
@@ -220,7 +224,7 @@ static char *sl2vl_dump_table_entry(ib_portid_t *dest, int in, int out)
 	char data[IB_SMP_DATA_SIZE];
 	int portnum = (in << 8) | out;
 
-	if (!smp_query(data, dest, IB_ATTR_SLVL_TABLE, portnum, 0))
+	if (!smp_query_via(data, dest, IB_ATTR_SLVL_TABLE, portnum, 0, srcport))
 		return "slvl query failed";
 
 	mad_dump_sltovl(buf, sizeof buf, data, sizeof data);
@@ -240,7 +244,7 @@ sl2vl_table(ib_portid_t *dest, char **argv, int argc)
 	if (argc > 0)
 		portnum = strtol(argv[0], 0, 0);
 
-	if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
+	if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0, srcport))
 		return "node info query failed";
 
 	mad_decode_field(data, IB_NODE_TYPE_F, &type);
@@ -270,8 +274,8 @@ static char *vlarb_dump_table_entry(ib_portid_t *dest, int portnum, int offset,
 	char buf[2048];
 	char data[IB_SMP_DATA_SIZE];
 
-	if (!smp_query(data, dest, IB_ATTR_VL_ARBITRATION,
-			(offset << 16) | portnum, 0))
+	if (!smp_query_via(data, dest, IB_ATTR_VL_ARBITRATION,
+			(offset << 16) | portnum, 0, srcport))
 		return "vl arb query failed";
 	mad_dump_vlarbitration(buf, sizeof(buf), data, cap * 2);
 	printf("%s", buf);
@@ -305,12 +309,14 @@ vlarb_table(ib_portid_t *dest, char **argv, int argc)
 
 	/* port number of 0 could mean SP0 or port MAD arrives on */
 	if (portnum == 0) {
-		if (!smp_query(data, dest, IB_ATTR_NODE_INFO, 0, 0))
+		if (!smp_query_via(data, dest, IB_ATTR_NODE_INFO, 0, 0,
+				srcport))
 			return "node info query failed";
 
 		mad_decode_field(data, IB_NODE_TYPE_F, &type);
 		if (type == IB_NODE_SWITCH) {
-			if (!smp_query(data, dest, IB_ATTR_SWITCH_INFO, 0, 0))
+			if (!smp_query_via(data, dest, IB_ATTR_SWITCH_INFO, 0,
+					0, srcport))
 				return "switch info query failed";
 			mad_decode_field(data, IB_SW_ENHANCED_PORT0_F, &enhsp0);
 			if (!enhsp0) {
@@ -321,7 +327,7 @@ vlarb_table(ib_portid_t *dest, char **argv, int argc)
 		}
 	}
 
-	if (!smp_query(data, dest, IB_ATTR_PORT_INFO, portnum, 0))
+	if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, portnum, 0, srcport))
 		return "port info query failed";
 
 	mad_decode_field(data, IB_PORT_VL_ARBITRATION_LOW_CAP_F, &lowcap);
@@ -349,13 +355,14 @@ guid_info(ib_portid_t *dest, char **argv, int argc)
 	int n;
 
 	/* Get the guid capacity */
-	if (!smp_query(data, dest, IB_ATTR_PORT_INFO, 0, 0))
+	if (!smp_query_via(data, dest, IB_ATTR_PORT_INFO, 0, 0, srcport))
 		return "port info failed";
 	mad_decode_field(data, IB_PORT_GUID_CAP_F, &n);
 
 	for (i = 0; i < (n + 7) / 8; i++) {
 		mod =  i;
-		if (!smp_query(data, dest, IB_ATTR_GUID_INFO, mod, 0))
+		if (!smp_query_via(data, dest, IB_ATTR_GUID_INFO, mod, 0,
+				srcport))
 			return "guid info query failed";
 		if (i + 1 == (n + 7) / 8)
 			k = ((n + 1 - i * 8) / 2) * 2;
@@ -445,11 +452,15 @@ int main(int argc, char **argv)
 	if (!(fn = match_op(argv[0])))
 		IBERROR("operation '%s' not supported", argv[0]);
 
-	madrpc_init(ibd_ca, ibd_ca_port, mgmt_classes, 3);
+	srcport = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 3);
+	if (!srcport)
+		IBERROR("Failed to open '%s' port '%d'", ibd_ca, ibd_ca_port);
+
 	node_name_map = open_node_name_map(node_name_map_file);
 
 	if (ibd_dest_type != IB_DEST_DRSLID) {
-		if (ib_resolve_portid_str(&portid, argv[1], ibd_dest_type, ibd_sm_id) < 0)
+		if (ib_resolve_portid_str_via(&portid, argv[1], ibd_dest_type,
+				ibd_sm_id, srcport) < 0)
 			IBERROR("can't resolve destination port %s", argv[1]);
 		if ((err = fn(&portid, argv+2, argc-2)))
 			IBERROR("operation %s: %s", argv[0], err);
@@ -458,11 +469,13 @@ int main(int argc, char **argv)
 
 		memset(concat, 0, 64);
 		snprintf(concat, sizeof(concat), "%s %s", argv[1], argv[2]);
-		if (ib_resolve_portid_str(&portid, concat, ibd_dest_type, ibd_sm_id) < 0)
+		if (ib_resolve_portid_str_via(&portid, concat, ibd_dest_type,
+				ibd_sm_id, srcport) < 0)
 			IBERROR("can't resolve destination port %s", concat);
 		if ((err = fn(&portid, argv+3, argc-3)))
 			IBERROR("operation %s: %s", argv[0], err);
 	}
 	close_node_name_map(node_name_map);
+	mad_rpc_close_port(srcport);
 	exit(0);
 }
diff --git a/infiniband-diags/src/vendstat.c b/infiniband-diags/src/vendstat.c
index db87e38..d001a01 100644
--- a/infiniband-diags/src/vendstat.c
+++ b/infiniband-diags/src/vendstat.c
@@ -55,6 +55,8 @@
 /* Config space addresses */
 #define IB_MLX_IS3_PORT_XMIT_WAIT	0x10013C
 
+struct ibmad_port *srcport;
+
 typedef struct {
 	uint16_t hw_revision;
 	uint16_t device_id;
@@ -152,13 +154,16 @@ int main(int argc, char **argv)
 	if (argc > 1)
 		port = strtoul(argv[1], 0, 0);
 
-	madrpc_init(ibd_ca, ibd_ca_port, mgmt_classes, 4);
+	srcport = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 4);
+	if (!srcport)
+		IBERROR("Failed to open '%s' port '%d'", ibd_ca, ibd_ca_port);
 
 	if (argc) {
-		if (ib_resolve_portid_str(&portid, argv[0], ibd_dest_type, ibd_sm_id) < 0)
+		if (ib_resolve_portid_str_via(&portid, argv[0], ibd_dest_type,
+				ibd_sm_id, srcport) < 0)
 			IBERROR("can't resolve destination port %s", argv[0]);
 	} else {
-		if (ib_resolve_self(&portid, &port, 0) < 0)
+		if (ib_resolve_self_via(&portid, &port, 0, srcport) < 0)
 			IBERROR("can't resolve self port %s", argv[0]);
 	}
 
@@ -180,12 +185,12 @@ int main(int argc, char **argv)
 	memset(&buf, 0, sizeof(buf));
 	/* vendor ClassPortInfo is required attribute if class supported */
 	call.attrid = CLASS_PORT_INFO;
-	if (!ib_vendor_call(&buf, &portid, &call))
+	if (!ib_vendor_call_via(&buf, &portid, &call, srcport))
 		IBERROR("classportinfo query");
 
 	memset(&buf, 0, sizeof(buf));
 	call.attrid = IB_MLX_IS3_GENERAL_INFO;
-	if (!ib_vendor_call(&buf, &portid, &call))
+	if (!ib_vendor_call_via(&buf, &portid, &call, srcport))
 		IBERROR("vendstat");
 	gi = (is3_general_info_t *)&buf;
 
@@ -217,7 +222,7 @@ int main(int argc, char **argv)
 		cs = (is3_config_space_t *)&buf;
 		for (i = 0; i < 16; i++)
 			cs->record[i].address = htonl(IB_MLX_IS3_PORT_XMIT_WAIT + ((i + 1) << 12));
-		if (!ib_vendor_call(&buf, &portid, &call))
+		if (!ib_vendor_call_via(&buf, &portid, &call, srcport))
 			IBERROR("vendstat");
 
 		for (i = 0; i < 16; i++)
@@ -232,7 +237,7 @@ int main(int argc, char **argv)
 		cs = (is3_config_space_t *)&buf;
 		for (i = 0; i < 8; i++)
 			cs->record[i].address = htonl(IB_MLX_IS3_PORT_XMIT_WAIT + ((i + 17) << 12));
-		if (!ib_vendor_call(&buf, &portid, &call))
+		if (!ib_vendor_call_via(&buf, &portid, &call, srcport))
 			IBERROR("vendstat");
 
 		for (i = 0; i < 8; i++)
-- 
1.5.4.5




More information about the general mailing list