[ofa-general] [PATCH 3/10] infiniband-diags: convert ibping to "new" ibmad interface
Ira Weiny
weiny2 at llnl.gov
Thu Feb 19 19:05:32 PST 2009
>From 039b42d9df09598d146d47d5d2adc1a13d952999 Mon Sep 17 00:00:00 2001
From: Ira Weiny <weiny2 at llnl.gov>
Date: Thu, 19 Feb 2009 16:57:55 -0800
Subject: [PATCH] infiniband-diags: convert ibping to "new" ibmad interface
To do this I needed the following additional functions
mad_register_client_via
mad_register_server_via
mad_send_via
mad_receive_via
mad_respond_via
ib_vendor_call_via
And I marked their counterparts as deprecated and clean up interface a bit
more.
Note I moved some of the "new" interface declarations higher in mad.h
Signed-off-by: Ira Weiny <weiny2 at llnl.gov>
---
infiniband-diags/src/ibping.c | 21 ++++++++----
libibmad/include/infiniband/mad.h | 66 +++++++++++++++++++++++++------------
libibmad/src/libibmad.map | 5 +++
libibmad/src/mad_internal.h | 44 ++++++++++++++++++++++++
libibmad/src/register.c | 58 ++++++++++++++++++++++++++------
libibmad/src/rpc.c | 8 +---
libibmad/src/serv.c | 39 ++++++++++++++++++++--
libibmad/src/vendor.c | 15 +++++++-
8 files changed, 206 insertions(+), 50 deletions(-)
create mode 100644 libibmad/src/mad_internal.h
diff --git a/infiniband-diags/src/ibping.c b/infiniband-diags/src/ibping.c
index 1994eba..901079f 100644
--- a/infiniband-diags/src/ibping.c
+++ b/infiniband-diags/src/ibping.c
@@ -48,6 +48,8 @@
#include "ibdiag_common.h"
+struct ibmad_port *srcport;
+
static char host_and_domain[IB_VENDOR_RANGE2_DATA_SIZE];
static char last_host[IB_VENDOR_RANGE2_DATA_SIZE];
@@ -82,7 +84,7 @@ ibping_serv(void)
DEBUG("starting to serve...");
- while ((umad = mad_receive(0, -1))) {
+ while ((umad = mad_receive_via(0, -1, srcport))) {
mad = umad_get_mad(umad);
data = (char *)mad + IB_VENDOR_RANGE2_DATA_OFFS;
@@ -91,7 +93,7 @@ ibping_serv(void)
DEBUG("Pong: %s", data);
- if (mad_respond(umad, 0, 0) < 0)
+ if (mad_respond_via(umad, 0, 0, srcport) < 0)
DEBUG("respond failed");
mad_free(umad);
@@ -120,7 +122,7 @@ ibping(ib_portid_t *portid, int quiet)
call.timeout = 0;
memset(&call.rmpp, 0, sizeof call.rmpp);
- if (!ib_vendor_call(data, portid, &call))
+ if (!ib_vendor_call_via(data, portid, &call, srcport))
return ~0ull;
rtt = cl_get_time_stamp() - start;
@@ -208,10 +210,12 @@ int main(int argc, char **argv)
if (!argc && !server)
ibdiag_show_usage();
- 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 (server) {
- if (mad_register_server(ping_class, 0, 0, oui) < 0)
+ if (mad_register_server_via(ping_class, 0, 0, oui, srcport) < 0)
IBERROR("can't serve class %d on this port", ping_class);
get_host_and_domain(host_and_domain, sizeof host_and_domain);
@@ -221,10 +225,11 @@ int main(int argc, char **argv)
exit(0);
}
- if (mad_register_client(ping_class, 0) < 0)
+ if (mad_register_client_via(ping_class, 0, srcport) < 0)
IBERROR("can't register ping class %d on this port", ping_class);
- 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]);
signal(SIGINT, report);
@@ -252,5 +257,7 @@ int main(int argc, char **argv)
report(0);
+ mad_rpc_close_port(srcport);
+
exit(-1);
}
diff --git a/libibmad/include/infiniband/mad.h b/libibmad/include/infiniband/mad.h
index 80e38be..5cf135e 100644
--- a/libibmad/include/infiniband/mad.h
+++ b/libibmad/include/infiniband/mad.h
@@ -691,27 +691,64 @@ MAD_EXPORT uint64_t mad_trid(void);
MAD_EXPORT int mad_build_pkt(void *umad, ib_rpc_t * rpc, ib_portid_t * dport,
ib_rmpp_hdr_t * rmpp, void *data);
+/* New interface */
+MAD_EXPORT void madrpc_show_errors(int set);
+MAD_EXPORT int madrpc_set_retries(int retries);
+MAD_EXPORT int madrpc_set_timeout(int timeout);
+MAD_EXPORT struct ibmad_port *mad_rpc_open_port(char *dev_name, int dev_port, int *mgmt_classes,
+ int num_classes);
+MAD_EXPORT void mad_rpc_close_port(struct ibmad_port *srcport);
+MAD_EXPORT void *mad_rpc(const struct ibmad_port *srcport, ib_rpc_t * rpc, ib_portid_t * dport,
+ void *payload, void *rcvdata);
+MAD_EXPORT void *mad_rpc_rmpp(const struct ibmad_port *srcport, ib_rpc_t * rpc, ib_portid_t * dport,
+ ib_rmpp_hdr_t * rmpp, void *data);
+MAD_EXPORT int mad_rpc_portid(struct ibmad_port *srcport);
+
/* register.c */
MAD_EXPORT int mad_register_port_client(int port_id, int mgmt,
- uint8_t rmpp_version);
-MAD_EXPORT int mad_register_client(int mgmt, uint8_t rmpp_version);
+ uint8_t rmpp_version) __attribute__ ((deprecated));
+MAD_EXPORT int mad_register_client(int mgmt, uint8_t rmpp_version)
+ __attribute__ ((deprecated));
MAD_EXPORT int mad_register_server(int mgmt, uint8_t rmpp_version,
- long method_mask[16 / sizeof(long)],
- uint32_t class_oui);
+ long method_mask[16 / sizeof(long)],
+ uint32_t class_oui) __attribute__ ((deprecated));
+/* register.c new interface */
+MAD_EXPORT int mad_register_client_via(int mgmt, uint8_t rmpp_version,
+ struct ibmad_port *srcport);
+MAD_EXPORT int mad_register_server_via(int mgmt, uint8_t rmpp_version,
+ long method_mask[16 / sizeof(long)],
+ uint32_t class_oui,
+ struct ibmad_port *srcport);
MAD_EXPORT int mad_class_agent(int mgmt);
MAD_EXPORT int mad_agent_class(int agent);
/* serv.c */
MAD_EXPORT int mad_send(ib_rpc_t * rpc, ib_portid_t * dport,
- ib_rmpp_hdr_t * rmpp, void *data);
-MAD_EXPORT void *mad_receive(void *umad, int timeout);
-MAD_EXPORT int mad_respond(void *umad, ib_portid_t * portid, uint32_t rstatus);
+ ib_rmpp_hdr_t * rmpp, void *data) __attribute__ ((deprecated));
+MAD_EXPORT void *mad_receive(void *umad, int timeout)
+ __attribute__ ((deprecated));
+MAD_EXPORT int mad_respond(void *umad, ib_portid_t * portid, uint32_t rstatus)
+ __attribute__ ((deprecated));
+
+/* serv.c new interface */
+MAD_EXPORT int mad_send_via(ib_rpc_t * rpc, ib_portid_t * dport,
+ ib_rmpp_hdr_t * rmpp, void *data,
+ struct ibmad_port *srcport);
+MAD_EXPORT void *mad_receive_via(void *umad, int timeout,
+ struct ibmad_port *srcport);
+MAD_EXPORT int mad_respond_via(void *umad, ib_portid_t * portid, uint32_t rstatus,
+ struct ibmad_port *srcport);
MAD_EXPORT void *mad_alloc(void);
MAD_EXPORT void mad_free(void *umad);
/* vendor.c */
MAD_EXPORT uint8_t *ib_vendor_call(void *data, ib_portid_t * portid,
- ib_vendor_call_t * call);
+ ib_vendor_call_t * call) __attribute__ ((deprecated));
+
+/* vendor.c new interface */
+MAD_EXPORT uint8_t *ib_vendor_call_via(void *data, ib_portid_t * portid,
+ ib_vendor_call_t * call,
+ struct ibmad_port *srcport);
static inline int mad_is_vendor_range1(int mgmt)
{
@@ -733,19 +770,6 @@ MAD_EXPORT void madrpc_init(char *dev_name, int dev_port, int *mgmt_classes,
int num_classes) __attribute__ ((deprecated));
void madrpc_save_mad(void *madbuf, int len) __attribute__ ((deprecated));
-/* New interface */
-MAD_EXPORT void madrpc_show_errors(int set);
-MAD_EXPORT int madrpc_set_retries(int retries);
-MAD_EXPORT int madrpc_set_timeout(int timeout);
-MAD_EXPORT struct ibmad_port *mad_rpc_open_port(char *dev_name, int dev_port, int *mgmt_classes,
- int num_classes);
-MAD_EXPORT void mad_rpc_close_port(struct ibmad_port *srcport);
-MAD_EXPORT void *mad_rpc(const struct ibmad_port *srcport, ib_rpc_t * rpc, ib_portid_t * dport,
- void *payload, void *rcvdata);
-MAD_EXPORT void *mad_rpc_rmpp(const struct ibmad_port *srcport, ib_rpc_t * rpc, ib_portid_t * dport,
- ib_rmpp_hdr_t * rmpp, void *data);
-MAD_EXPORT int mad_rpc_portid(struct ibmad_port *srcport);
-
/* smp.c */
MAD_EXPORT uint8_t *smp_query(void *buf, ib_portid_t * id, unsigned attrid,
unsigned mod, unsigned timeout) __attribute__ ((deprecated));
diff --git a/libibmad/src/libibmad.map b/libibmad/src/libibmad.map
index 94d7762..bac74a9 100644
--- a/libibmad/src/libibmad.map
+++ b/libibmad/src/libibmad.map
@@ -60,6 +60,8 @@ IBMAD_1.3 {
mad_class_agent;
mad_register_client;
mad_register_server;
+ mad_register_client_via;
+ mad_register_server_via;
ib_resolve_guid;
ib_resolve_portid_str;
ib_resolve_self;
@@ -86,10 +88,13 @@ IBMAD_1.3 {
mad_free;
mad_receive;
mad_respond;
+ mad_receive_via;
+ mad_respond_via;
mad_send;
smp_query;
smp_set;
ib_vendor_call;
+ ib_vendor_call_via;
smp_query_via;
smp_set_via;
ib_path_query_via;
diff --git a/libibmad/src/mad_internal.h b/libibmad/src/mad_internal.h
new file mode 100644
index 0000000..9afe7a9
--- /dev/null
+++ b/libibmad/src/mad_internal.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2004-2006 Voltaire Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses. You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ */
+
+#ifndef _MAD_INTERNAL_H_
+#define _MAD_INTERNAL_H_
+
+#define MAX_CLASS 256
+
+struct ibmad_port {
+ int port_id; /* file descriptor returned by umad_open() */
+ int class_agents[MAX_CLASS]; /* class2agent mapper */
+};
+
+#endif /* _MAD_INTERNAL_H_ */
diff --git a/libibmad/src/register.c b/libibmad/src/register.c
index 4d91ff8..4aabd7c 100644
--- a/libibmad/src/register.c
+++ b/libibmad/src/register.c
@@ -43,10 +43,11 @@
#include <infiniband/umad.h>
#include <infiniband/mad.h>
+#include "mad_internal.h"
+
#undef DEBUG
#define DEBUG if (ibdebug) IBWARN
-#define MAX_CLASS 256
#define MAX_AGENTS 256
static int class_agent[MAX_CLASS];
@@ -136,22 +137,57 @@ int mad_register_port_client(int port_id, int mgmt, uint8_t rmpp_version)
int mad_register_client(int mgmt, uint8_t rmpp_version)
{
+ int rc = 0;
+ struct ibmad_port port;
+
+ port.port_id = madrpc_portid();
+ rc = mad_register_client_via(mgmt, rmpp_version, &port);
+ if (rc < 0)
+ return rc;
+ return register_agent(port.class_agents[mgmt], mgmt);
+}
+
+int mad_register_client_via(int mgmt, uint8_t rmpp_version,
+ struct ibmad_port *srcport)
+{
int agent;
- agent = mad_register_port_client(madrpc_portid(), mgmt, rmpp_version);
+ if (!srcport)
+ return -1;
+
+ agent = mad_register_port_client(mad_rpc_portid(srcport), mgmt, rmpp_version);
if (agent < 0)
return agent;
- return register_agent(agent, mgmt);
+ srcport->class_agents[mgmt] = agent;
+ return 0;
}
int
mad_register_server(int mgmt, uint8_t rmpp_version,
long method_mask[], uint32_t class_oui)
{
+ int rc = 0;
+ struct ibmad_port port;
+
+ port.port_id = madrpc_portid();
+ port.class_agents[mgmt] = class_agent[mgmt];
+ rc = mad_register_server_via(mgmt, rmpp_version,
+ method_mask, class_oui,
+ &port);
+ if (rc < 0)
+ return rc;
+ return register_agent(port.class_agents[mgmt], mgmt);
+}
+
+int
+mad_register_server_via(int mgmt, uint8_t rmpp_version,
+ long method_mask[], uint32_t class_oui,
+ struct ibmad_port *srcport)
+{
long class_method_mask[16 / sizeof(long)];
uint8_t oui[3];
- int agent, vers, mad_portid;
+ int agent, vers;
if (method_mask)
memcpy(class_method_mask, method_mask,
@@ -159,11 +195,12 @@ mad_register_server(int mgmt, uint8_t rmpp_version,
else
memset(class_method_mask, 0xff, sizeof(class_method_mask));
- if ((mad_portid = madrpc_portid()) < 0)
+ if (!srcport)
return -1;
- if (class_agent[mgmt] >= 0) {
- DEBUG("Class 0x%x already registered", mgmt);
+ if (srcport->class_agents[mgmt] >= 0) {
+ DEBUG("Class 0x%x already registered %d",
+ mgmt, srcport->class_agents[mgmt]);
return -1;
}
if ((vers = mgmt_class_vers(mgmt)) <= 0) {
@@ -175,19 +212,18 @@ mad_register_server(int mgmt, uint8_t rmpp_version,
oui[0] = (class_oui >> 16) & 0xff;
oui[1] = (class_oui >> 8) & 0xff;
oui[2] = class_oui & 0xff;
- if ((agent = umad_register_oui(mad_portid, mgmt, rmpp_version,
+ if ((agent = umad_register_oui(srcport->port_id, mgmt, rmpp_version,
oui, class_method_mask)) < 0) {
DEBUG("Can't register agent for class %d", mgmt);
return -1;
}
- } else if ((agent = umad_register(mad_portid, mgmt, vers, rmpp_version,
+ } else if ((agent = umad_register(srcport->port_id, mgmt, vers, rmpp_version,
class_method_mask)) < 0) {
DEBUG("Can't register agent for class %d", mgmt);
return -1;
}
- if (register_agent(agent, mgmt) < 0)
- return -1;
+ srcport->class_agents[mgmt] = agent;
return agent;
}
diff --git a/libibmad/src/rpc.c b/libibmad/src/rpc.c
index d47873b..210f0c2 100644
--- a/libibmad/src/rpc.c
+++ b/libibmad/src/rpc.c
@@ -43,12 +43,7 @@
#include <infiniband/umad.h>
#include <infiniband/mad.h>
-#define MAX_CLASS 256
-
-struct ibmad_port {
- int port_id; /* file descriptor returned by umad_open() */
- int class_agents[MAX_CLASS]; /* class2agent mapper */
-};
+#include "mad_internal.h"
int ibdebug;
@@ -339,6 +334,7 @@ struct ibmad_port *mad_rpc_open_port(char *dev_name, int dev_port,
return NULL;
}
+ memset(p->class_agents, 0xff, sizeof p->class_agents);
while (num_classes--) {
uint8_t rmpp_version = 0;
int mgmt = *mgmt_classes++;
diff --git a/libibmad/src/serv.c b/libibmad/src/serv.c
index c7631bb..0ce1660 100644
--- a/libibmad/src/serv.c
+++ b/libibmad/src/serv.c
@@ -42,12 +42,25 @@
#include <infiniband/umad.h>
#include <infiniband/mad.h>
+#include "mad_internal.h"
+
#undef DEBUG
#define DEBUG if (ibdebug) IBWARN
int
mad_send(ib_rpc_t * rpc, ib_portid_t * dport, ib_rmpp_hdr_t * rmpp, void *data)
{
+ struct ibmad_port port;
+
+ port.port_id = madrpc_portid();
+ port.class_agents[rpc->mgtclass] = mad_class_agent(rpc->mgtclass);
+ return mad_send_via(rpc, dport, rmpp, data, &port);
+}
+
+int
+mad_send_via(ib_rpc_t * rpc, ib_portid_t * dport, ib_rmpp_hdr_t * rmpp, void *data,
+ struct ibmad_port *srcport)
+{
uint8_t pktbuf[1024];
void *umad = pktbuf;
@@ -64,7 +77,7 @@ mad_send(ib_rpc_t * rpc, ib_portid_t * dport, ib_rmpp_hdr_t * rmpp, void *data)
(char *)umad_get_mad(umad) + rpc->dataoffs, rpc->datasz);
}
- if (umad_send(madrpc_portid(), mad_class_agent(rpc->mgtclass),
+ if (umad_send(srcport->port_id, srcport->class_agents[rpc->mgtclass],
umad, IB_MAD_SIZE, rpc->timeout, 0) < 0) {
IBWARN("send failed; %m");
return -1;
@@ -75,6 +88,18 @@ mad_send(ib_rpc_t * rpc, ib_portid_t * dport, ib_rmpp_hdr_t * rmpp, void *data)
int mad_respond(void *umad, ib_portid_t * portid, uint32_t rstatus)
{
+ int i = 0;
+ struct ibmad_port port;
+
+ port.port_id = madrpc_portid();
+ for (i = 1; i < MAX_CLASS; i++)
+ port.class_agents[i] = mad_class_agent(i);
+ return mad_respond_via(umad, portid, rstatus, &port);
+}
+
+int mad_respond_via(void *umad, ib_portid_t * portid, uint32_t rstatus,
+ struct ibmad_port *srcport)
+{
uint8_t *mad = umad_get_mad(umad);
ib_mad_addr_t *mad_addr;
ib_rpc_t rpc = { 0 };
@@ -138,7 +163,7 @@ int mad_respond(void *umad, ib_portid_t * portid, uint32_t rstatus)
if (ibdebug > 1)
xdump(stderr, "mad respond pkt\n", mad, IB_MAD_SIZE);
- if (umad_send(madrpc_portid(), mad_class_agent(rpc.mgtclass), umad,
+ if (umad_send(srcport->port_id, srcport->class_agents[rpc.mgtclass], umad,
IB_MAD_SIZE, rpc.timeout, 0) < 0) {
DEBUG("send failed; %m");
return -1;
@@ -149,11 +174,19 @@ int mad_respond(void *umad, ib_portid_t * portid, uint32_t rstatus)
void *mad_receive(void *umad, int timeout)
{
+ struct ibmad_port port;
+
+ port.port_id = madrpc_portid();
+ return mad_receive_via(umad, timeout, &port);
+}
+
+void *mad_receive_via(void *umad, int timeout, struct ibmad_port *srcport)
+{
void *mad = umad ? umad : umad_alloc(1, umad_size() + IB_MAD_SIZE);
int agent;
int length = IB_MAD_SIZE;
- if ((agent = umad_recv(madrpc_portid(), mad, &length, timeout)) < 0) {
+ if ((agent = umad_recv(srcport->port_id, mad, &length, timeout)) < 0) {
if (!umad)
umad_free(mad);
DEBUG("recv failed: %m");
diff --git a/libibmad/src/vendor.c b/libibmad/src/vendor.c
index 50a878e..1a129e5 100644
--- a/libibmad/src/vendor.c
+++ b/libibmad/src/vendor.c
@@ -40,6 +40,7 @@
#include <string.h>
#include <infiniband/mad.h>
+#include "mad_internal.h"
#undef DEBUG
#define DEBUG if (ibdebug) IBWARN
@@ -53,6 +54,16 @@ static inline int response_expected(int method)
uint8_t *ib_vendor_call(void *data, ib_portid_t * portid,
ib_vendor_call_t * call)
{
+ struct ibmad_port port;
+
+ port.port_id = madrpc_portid();
+ return ib_vendor_call_via(data, portid, call, &port);
+}
+
+uint8_t *ib_vendor_call_via(void *data, ib_portid_t * portid,
+ ib_vendor_call_t * call,
+ struct ibmad_port *srcport)
+{
ib_rpc_t rpc = { 0 };
int range1 = 0, resp_expected;
@@ -90,7 +101,7 @@ uint8_t *ib_vendor_call(void *data, ib_portid_t * portid,
portid->qkey = IB_DEFAULT_QP1_QKEY;
if (resp_expected)
- return madrpc_rmpp(&rpc, portid, 0, data); /* FIXME: no RMPP for now */
+ return mad_rpc_rmpp(srcport, &rpc, portid, 0, data); /* FIXME: no RMPP for now */
- return mad_send(&rpc, portid, 0, data) < 0 ? 0 : data; /* FIXME: no RMPP for now */
+ return mad_send_via(&rpc, portid, 0, data, srcport) < 0 ? 0 : data; /* FIXME: no RMPP for now */
}
--
1.5.4.5
More information about the general
mailing list