ib-mgmt: update to 518083dc46963eb5fb48855acbe2b351ce7361f8
authorshefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 27 May 2009 18:16:16 +0000 (18:16 +0000)
committershefty <shefty@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Wed, 27 May 2009 18:16:16 +0000 (18:16 +0000)
commit 518083dc46963eb5fb48855acbe2b351ce7361f8
Author: Doron Shoham <dorons@voltaire.com>
Date:   Sun May 10 11:17:11 2009 +0300

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@2211 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

12 files changed:
tools/infiniband-diags/src/iblinkinfo.c
tools/infiniband-diags/src/ibnetdiscover.c
tools/infiniband-diags/src/ibping.c
tools/infiniband-diags/src/ibqueryerrors.c
tools/infiniband-diags/src/ibsendtrap.c
tools/infiniband-diags/src/ibstat.c
tools/infiniband-diags/src/ibstat/SOURCES
tools/infiniband-diags/src/saquery.c
ulp/libibmad/include/infiniband/mad.h
ulp/libibmad/src/Sources
ulp/libibmad/src/bm.c [new file with mode: 0644]
ulp/libibnetdisc/src/ibnetdisc.c

index a8a93de..cf38ecb 100644 (file)
@@ -205,13 +205,8 @@ void
 print_switch(ibnd_node_t *node, void *user_data)
 {
        int i = 0;
-
-       if (!line_mode) {
-               char *remap = remap_node_name(node_name_map, node->guid,
-                                       node->nodedesc);
-               printf("Switch 0x%016"PRIx64" %s:\n", node->guid, remap);
-               free(remap);
-       }
+       int head_print = 0;
+       char *remap = remap_node_name(node_name_map, node->guid, node->nodedesc);
 
        for (i = 1; i <= node->numports; i++) {
                ibnd_port_t *port = node->ports[i];
@@ -219,9 +214,14 @@ print_switch(ibnd_node_t *node, void *user_data)
                        continue;
                if (!down_links_only ||
                                mad_get_field(port->info, 0, IB_PORT_STATE_F) == IB_LINK_DOWN) {
+                       if (!head_print && !line_mode) {
+                               printf("Switch 0x%016"PRIx64" %s:\n", node->guid, remap);
+                               head_print = 1;
+                       }
                        print_port(node, port);
                }
        }
+       free(remap);
 }
 
 void
@@ -262,13 +262,14 @@ main(int argc, char **argv)
        int ca_port = 0;
        ibnd_fabric_t *fabric = NULL;
        uint64_t guid = 0;
+       char *guid_str = NULL;
        char *dr_path = NULL;
        char *from = NULL;
        int hops = 0;
-       ib_portid_t port_id;
+       ib_portid_t port_id = {0};
 
        struct ibmad_port *ibmad_port;
-       int mgmt_classes[2] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS};
+       int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS};
 
        static char const str_opts[] = "S:D:n:C:P:t:sldgphuf:R";
        static const struct option long_opts[] = {
@@ -339,7 +340,8 @@ main(int argc, char **argv)
                        print_port_guids = 1;
                        break;
                case 'S':
-                       guid = (uint64_t)strtoull(optarg, 0, 0);
+                       guid_str = optarg;
+                       guid = (uint64_t)strtoull(guid_str, 0, 0);
                        break;
                case 'p':
                        add_sw_settings = 1;
@@ -358,7 +360,7 @@ main(int argc, char **argv)
        if (argc && !(f = fopen(argv[0], "w")))
                fprintf(stderr, "can't open file %s for writing", argv[0]);
 
-       ibmad_port = mad_rpc_open_port(ca, ca_port, mgmt_classes, 2);
+       ibmad_port = mad_rpc_open_port(ca, ca_port, mgmt_classes, 3);
        if (!ibmad_port) {
                fprintf(stderr, "Failed to open %s port %d", ca, ca_port);
                exit(1);
@@ -375,13 +377,23 @@ main(int argc, char **argv)
                        goto close_port;
                }
                guid = 0;
-       } else {
+       } else if (guid_str) {
+               if (ib_resolve_portid_str_via(&port_id, guid_str, IB_DEST_GUID,
+                               NULL, ibmad_port) >= 0) {
+                       if ((fabric = ibnd_discover_fabric(ibmad_port,
+                                       timeout_ms, &port_id, 1)) == NULL)
+                               IBWARN("Single node discover failed; attempting full scan\n");
+               } else
+                       IBWARN("Failed to resolve %s; attempting full scan\n",
+                               guid_str);
+       }
+
+       if (!fabric) /* do a full scan */
                if ((fabric = ibnd_discover_fabric(ibmad_port, timeout_ms, NULL, -1)) == NULL) {
                        fprintf(stderr, "discover failed\n");
                        rc = 1;
                        goto close_port;
                }
-       }
 
        if (guid) {
                ibnd_node_t *sw = ibnd_find_node_guid(fabric, guid);
index 810b8db..1799618 100644 (file)
@@ -144,7 +144,7 @@ list_node(ibnd_node_t *node, void *user_data)
 {
        char *node_type;
        char *nodename = remap_node_name(node_name_map, node->guid,
-                                             node->nodedesc);
+                                        node->nodedesc);
 
        switch(node->type) {
        case IB_NODE_SWITCH:
@@ -161,8 +161,7 @@ list_node(ibnd_node_t *node, void *user_data)
                break;
        }
        fprintf(f, "%s\t : 0x%016" PRIx64 " ports %d devid 0x%x vendid 0x%x \"%s\"\n",
-               node_type,
-               node->guid, node->numports,
+               node_type, node->guid, node->numports,
                mad_get_field(node->info, 0, IB_NODE_DEVID_F),
                mad_get_field(node->info, 0, IB_NODE_VENDORID_F),
                nodename);
@@ -173,15 +172,12 @@ list_node(ibnd_node_t *node, void *user_data)
 void
 list_nodes(ibnd_fabric_t *fabric, int list)
 {
-       if (list & LIST_CA_NODE) {
+       if (list & LIST_CA_NODE)
                ibnd_iter_nodes_type(fabric, list_node, IB_NODE_CA, NULL);
-       }
-       if (list & LIST_SWITCH_NODE) {
+       if (list & LIST_SWITCH_NODE)
                ibnd_iter_nodes_type(fabric, list_node, IB_NODE_SWITCH, NULL);
-       }
-       if (list & LIST_ROUTER_NODE) {
+       if (list & LIST_ROUTER_NODE)
                ibnd_iter_nodes_type(fabric, list_node, IB_NODE_ROUTER, NULL);
-       }
 }
 
 void
@@ -194,14 +190,12 @@ out_ids(ibnd_node_t *node, int group, char *chname)
                mad_get_field(node->info, 0, IB_NODE_DEVID_F));
        if (sysimgguid)
                fprintf(f, "sysimgguid=0x%" PRIx64, sysimgguid);
-       if (group
-           && node->chassis && node->chassis->chassisnum) {
+       if (group && node->chassis && node->chassis->chassisnum) {
                fprintf(f, "\t\t# Chassis %d", node->chassis->chassisnum);
                if (chname)
                        fprintf(f, " (%s)", clean_nodedesc(chname));
-               if (ibnd_is_xsigo_tca(node->guid)
-                               && node->ports[1]
-                               && node->ports[1]->remoteport)
+               if (ibnd_is_xsigo_tca(node->guid) && node->ports[1] &&
+                   node->ports[1]->remoteport)
                        fprintf(f, " slot %d", node->ports[1]->remoteport->portnum);
        }
        fprintf(f, "\n");
@@ -242,8 +236,7 @@ out_switch(ibnd_node_t *node, int group, char *chname)
        nodename = remap_node_name(node_name_map, node->guid, node->nodedesc);
 
        fprintf(f, "\nSwitch\t%d %s\t\t# \"%s\" %s port 0 lid %d lmc %d\n",
-               node->numports, node_name(node),
-               nodename,
+               node->numports, node_name(node), nodename,
                node->smaenhsp0 ? "enhanced" : "base",
                node->smalid, node->smalmc);
 
@@ -314,13 +307,12 @@ out_switch_port(ibnd_port_t *port, int group)
                fprintf(f, "%s", ext_port_str);
 
        rem_nodename = remap_node_name(node_name_map,
-                               port->remoteport->node->guid,
-                               port->remoteport->node->nodedesc);
+                                      port->remoteport->node->guid,
+                                      port->remoteport->node->nodedesc);
 
        ext_port_str = out_ext_port(port->remoteport, group);
        fprintf(f, "\t%s[%d]%s",
-               node_name(port->remoteport->node),
-               port->remoteport->portnum,
+               node_name(port->remoteport->node), port->remoteport->portnum,
                ext_port_str ? ext_port_str : "");
        if (port->remoteport->node->type != IB_NODE_SWITCH)
                fprintf(f, "(%" PRIx64 ") ", port->remoteport->guid);
@@ -355,8 +347,7 @@ out_ca_port(ibnd_port_t *port, int group)
        if (port->node->type != IB_NODE_SWITCH)
                fprintf(f, "(%" PRIx64 ") ", port->guid);
        fprintf(f, "\t%s[%d]",
-               node_name(port->remoteport->node),
-               port->remoteport->portnum);
+               node_name(port->remoteport->node), port->remoteport->portnum);
        str = out_ext_port(port->remoteport, group);
        if (str)
                fprintf(f, "%s", str);
@@ -364,8 +355,8 @@ out_ca_port(ibnd_port_t *port, int group)
                fprintf(f, " (%" PRIx64 ") ", port->remoteport->guid);
 
        rem_nodename = remap_node_name(node_name_map,
-                               port->remoteport->node->guid,
-                               port->remoteport->node->nodedesc);
+                                      port->remoteport->node->guid,
+                                      port->remoteport->node->nodedesc);
 
        fprintf(f, "\t\t# lid %d lmc %d \"%s\" lid %d %s%s\n",
                port->base_lid, port->lmc, rem_nodename,
@@ -513,7 +504,7 @@ dump_topology(int group, ibnd_fabric_t *fabric)
 
                        fprintf(f, "\n# Chassis Switches");
                        for (node = ch->nodes; node;
-                                       node = node->next_chassis_node) {
+                            node = node->next_chassis_node) {
                                if (node->type == IB_NODE_SWITCH) {
                                        out_switch(node, group, chname);
                                        for (p = 1; p <= node->numports; p++) {
@@ -527,7 +518,7 @@ dump_topology(int group, ibnd_fabric_t *fabric)
 
                        fprintf(f, "\n# Chassis CAs");
                        for (node = ch->nodes; node;
-                                       node = node->next_chassis_node) {
+                            node = node->next_chassis_node) {
                                if (node->type == IB_NODE_CA) {
                                        out_ca(node, group, chname);
                                        for (p = 1; p <= node->numports; p++) {
@@ -545,7 +536,7 @@ dump_topology(int group, ibnd_fabric_t *fabric)
                iter_user_data.group = group;
                iter_user_data.skip_chassis_nodes = 0;
                ibnd_iter_nodes_type(fabric, switch_iter_func,
-                               IB_NODE_SWITCH, &iter_user_data);
+                                    IB_NODE_SWITCH, &iter_user_data);
        }
 
        chname = NULL;
@@ -556,18 +547,17 @@ dump_topology(int group, ibnd_fabric_t *fabric)
                fprintf(f, "\nNon-Chassis Nodes\n");
 
                ibnd_iter_nodes_type(fabric, switch_iter_func,
-                               IB_NODE_SWITCH, &iter_user_data);
+                                    IB_NODE_SWITCH, &iter_user_data);
        }
 
        iter_user_data.group = group;
        iter_user_data.skip_chassis_nodes = 0;
        /* Make pass on CAs */
-       ibnd_iter_nodes_type(fabric, ca_iter_func, IB_NODE_CA,
-                       &iter_user_data);
+       ibnd_iter_nodes_type(fabric, ca_iter_func, IB_NODE_CA, &iter_user_data);
 
-       /* make pass on routers */
+       /* Make pass on routers */
        ibnd_iter_nodes_type(fabric, router_iter_func, IB_NODE_ROUTER,
-                       &iter_user_data);
+                            &iter_user_data);
 
        return i;
 }
@@ -578,8 +568,7 @@ void dump_ports_report (ibnd_node_t *node, void *user_data)
        ibnd_port_t *port = NULL;
 
        /* for each port */
-       for (p = node->numports, port = node->ports[p];
-            p > 0;
+       for (p = node->numports, port = node->ports[p]; p > 0;
             port = node->ports[--p]) {
                uint32_t iwidth, ispeed;
                if (port == NULL)
@@ -591,8 +580,7 @@ void dump_ports_report (ibnd_node_t *node, void *user_data)
                        ports_nt_str_compat(node),
                        node->type == IB_NODE_SWITCH ?
                                node->smalid : port->base_lid,
-                       port->portnum,
-                       port->guid,
+                       port->portnum, port->guid,
                        dump_linkwidth_compat(iwidth),
                        dump_linkspeed_compat(ispeed));
                if (port->remoteport)
@@ -604,12 +592,10 @@ void dump_ports_report (ibnd_node_t *node, void *user_data)
                                        port->remoteport->node->smalid :
                                        port->remoteport->base_lid,
                                port->remoteport->portnum,
-                               port->remoteport->guid,
-                               port->node->nodedesc,
+                               port->remoteport->guid, port->node->nodedesc,
                                port->remoteport->node->nodedesc);
                else
-                       fprintf(stdout, "%36s'%s'\n", "",
-                               port->node->nodedesc);
+                       fprintf(stdout, "%36s'%s'\n", "", port->node->nodedesc);
        }
 }
 
index 7da48e2..901079f 100644 (file)
@@ -141,7 +141,7 @@ static uint64_t minrtt = ~0ull, maxrtt, total_rtt;
 static uint64_t start, total_time, replied, lost, ntrans;
 static ib_portid_t portid = {0};
 
-void __cdecl report(int sig)
+void report(int sig)
 {
        total_time = cl_get_time_stamp() - start;
 
index 09861be..525af70 100644 (file)
@@ -123,7 +123,6 @@ print_port_config(ibnd_node_t *node, int portnum)
        char speed_msg[256];
        char ext_port_str[256];
        int iwidth, ispeed, istate, iphystate;
-       int n = 0;
 
        ibnd_port_t *port = node->ports[portnum];
 
@@ -140,7 +139,7 @@ print_port_config(ibnd_node_t *node, int portnum)
        width_msg[0] = '\0';
        speed_msg[0] = '\0';
 
-       n = snprintf(link_str, 256, "(%3s %s %6s/%8s)",
+       snprintf(link_str, 256, "(%3s %s %6s/%8s)",
                mad_dump_val(IB_PORT_LINK_WIDTH_ACTIVE_F, width, 64, &iwidth),
                mad_dump_val(IB_PORT_LINK_SPEED_ACTIVE_F, speed, 64, &ispeed),
                mad_dump_val(IB_PORT_STATE_F, state, 64, &istate),
@@ -177,9 +176,9 @@ print_port_config(ibnd_node_t *node, int portnum)
                ext_port_str[0] = '\0';
 
        if (node->type == IB_NODE_SWITCH)
-               printf("       %6d", node->smalid);
+               printf("       Link info: %6d", node->smalid);
        else
-               printf("       %6d", port->base_lid);
+               printf("       Link info: %6d", port->base_lid);
 
        printf("%4d[%2s] ==%s==>  %s",
                port->portnum, ext_port_str, link_str, remote_str);
@@ -211,7 +210,7 @@ report_suppressed(void)
 }
 
 static void
-print_results(ibnd_node_t *node, uint8_t *pc, int portnum)
+print_results(ibnd_node_t *node, uint8_t *pc, int portnum, int *header_printed)
 {
        char buf[1024];
        char *str = buf;
@@ -237,7 +236,6 @@ print_results(ibnd_node_t *node, uint8_t *pc, int portnum)
 
        /* if we found errors. */
        if (n != 0) {
-               char *nodename = remap_node_name(node_name_map, node->guid, node->nodedesc);
                if (data_counters)
                        for (i = IB_PC_XMT_BYTES_F; i <= IB_PC_RCV_PKTS_F; i++) {
                                uint64_t val64 = 0;
@@ -247,17 +245,21 @@ print_results(ibnd_node_t *node, uint8_t *pc, int portnum)
                                                mad_field_name(i), val64);
                        }
 
-               printf("Errors for 0x%" PRIx64 " \"%s\"\n", node->guid, nodename);
-               printf("   GUID 0x%" PRIx64 " port %d:%s\n",
-                       node->guid, portnum, str);
+               if (!*header_printed) {
+                       char *nodename = remap_node_name(node_name_map, node->guid, node->nodedesc);
+                       printf("Errors for 0x%" PRIx64 " \"%s\"\n", node->guid, nodename);
+                       *header_printed = 1;
+                       free(nodename);
+               }
+
+               printf("   GUID 0x%" PRIx64 " port %d:%s\n", node->guid, portnum, str);
                if (port_config)
                        print_port_config(node, portnum);
-               free(nodename);
        }
 }
 
 static void
-print_port(ibnd_node_t *node, int portnum)
+print_port(ibnd_node_t *node, int portnum, int *header_printed)
 {
        uint8_t pc[1024];
        uint16_t cap_mask;
@@ -291,7 +293,7 @@ print_port(ibnd_node_t *node, int portnum)
                uint32_t foo = 0;
                mad_encode_field(pc, IB_PC_XMT_WAIT_F, &foo);
        }
-       print_results(node, pc, portnum);
+       print_results(node, pc, portnum, header_printed);
 
 cleanup:
        free(nodename);
@@ -300,6 +302,7 @@ cleanup:
 void
 print_node(ibnd_node_t *node, void *user_data)
 {
+       int header_printed = 0;
        int p = 0;
        int startport = 1;
 
@@ -311,7 +314,7 @@ print_node(ibnd_node_t *node, void *user_data)
 
        for (p = startport; p <= node->numports; p++) {
                if (node->ports[p]) {
-                       print_port(node, p);
+                       print_port(node, p, &header_printed);
                }
        }
 }
@@ -424,25 +427,19 @@ main(int argc, char **argv)
                ib_portid_t portid = {0};
 
                if (ib_resolve_portid_str_via(&portid, switch_guid_str, IB_DEST_GUID,
-                                       ibd_sm_id, ibmad_port) < 0) {
-                       fprintf(stderr, "can't resolve destination port %s %p\n",
-                               switch_guid_str, ibd_sm_id);
-                       rc = 1;
-                       goto close_port;
-               }
+                                       ibd_sm_id, ibmad_port) >= 0) {
+                       if ((fabric = ibnd_discover_fabric(ibmad_port, ibd_timeout, &portid, 1)) == NULL)
+                               IBWARN("Single node discover failed; attempting full scan\n");
+               } else
+                       IBWARN("Failed to resolve %s; attempting full scan\n", switch_guid_str);
+       }
 
-               if ((fabric = ibnd_discover_fabric(ibmad_port, ibd_timeout, &portid, 1)) == NULL) {
-                       fprintf(stderr, "discover failed\n");
-                       rc = 1;
-                       goto close_port;
-               }
-       } else {
+       if (!fabric) /* do a full scan */
                if ((fabric = ibnd_discover_fabric(ibmad_port, ibd_timeout, NULL, -1)) == NULL) {
                        fprintf(stderr, "discover failed\n");
                        rc = 1;
                        goto close_port;
                }
-       }
 
        report_suppressed();
 
index 7ad588e..ac8dcf4 100644 (file)
@@ -53,20 +53,20 @@ struct ibmad_port *srcport;
 /* for local link integrity */
 int error_port = 1;
 
-static int get_node_type(ib_portid_t *port)
+static uint16_t get_node_type(ib_portid_t *port)
 {
-       int node_type = IB_NODE_TYPE_CA;
+       uint16_t node_type = IB_NODE_TYPE_CA;
        uint8_t data[IB_SMP_DATA_SIZE];
 
        if (smp_query_via(data, port, IB_ATTR_NODE_INFO, 0, 0, srcport))
-               node_type = mad_get_field(data, 0, IB_NODE_TYPE_F);
+               node_type = (uint16_t)mad_get_field(data, 0, IB_NODE_TYPE_F);
        return node_type;
 }
 
 static void build_trap144(ib_mad_notice_attr_t * n, ib_portid_t *port)
 {
        n->generic_type = 0x80 | IB_NOTICE_TYPE_INFO;
-       n->g_or_v.generic.prod_type_lsb = cl_hton16((uint16_t) get_node_type(port));
+       n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port));
        n->g_or_v.generic.trap_num = cl_hton16(144);
        n->issuer_lid = cl_hton16((uint16_t) port->lid);
        n->data_details.ntc_144.lid = n->issuer_lid;
@@ -79,7 +79,7 @@ static void build_trap144(ib_mad_notice_attr_t * n, ib_portid_t *port)
 static void build_trap129(ib_mad_notice_attr_t * n, ib_portid_t *port)
 {
        n->generic_type = 0x80 | IB_NOTICE_TYPE_URGENT;
-       n->g_or_v.generic.prod_type_lsb = cl_hton16((uint16_t) get_node_type(port));
+       n->g_or_v.generic.prod_type_lsb = cl_hton16(get_node_type(port));
        n->g_or_v.generic.trap_num = cl_hton16(129);
        n->issuer_lid = cl_hton16((uint16_t) port->lid);
        n->data_details.ntc_129_131.lid = n->issuer_lid;
index 7985be1..06f39ae 100644 (file)
@@ -111,7 +111,7 @@ port_dump(umad_port_t *port, int alone)
        printf("%sBase lid: %d\n", pre, port->base_lid);
        printf("%sLMC: %d\n", pre, port->lmc);
        printf("%sSM lid: %d\n", pre, port->sm_lid);
-       printf("%sCapability mask: 0x%08x\n", pre, (unsigned)ntohll(port->capmask));
+       printf("%sCapability mask: 0x%08x\n", pre, ntohl(port->capmask));
        printf("%sPort GUID: 0x%016llx\n", pre, (long long unsigned)ntohll(port->port_guid));
        return 0;
 }
index 161fdd0..e78103c 100644 (file)
@@ -19,6 +19,7 @@ C_DEFINES = $(C_DEFINES) /DHAVE_CONFIG_H
 \r
 TARGETLIBS = \\r
        $(SDK_LIB_PATH)\kernel32.lib    \\r
+       $(SDK_LIB_PATH)\ws2_32.lib              \\r
 !if $(FREEBUILD)\r
        $(TARGETPATH)\*\libibmad.lib    \\r
        $(TARGETPATH)\*\libibumad.lib   \r
index 4dcd712..5920eda 100644 (file)
@@ -1470,7 +1470,7 @@ static int process_opt(void *context, int ch, char *optarg)
                node_print_desc = ALL_DESC;
                break;
        case 'c':
-               command = CLASS_PORT_INFO;
+               command = SAQUERY_CMD_CLASS_PORT_INFO;
                break;
        case 'S':
                query_type = IB_SA_ATTR_SERVICERECORD;
index b404816..aa27eb5 100644 (file)
@@ -282,8 +282,8 @@ enum MAD_FIELDS {
        IB_MAD_MKEY_F,
 
        /* word 9 (32-37 bytes) */
-       IB_DRSMP_DRSLID_F,
        IB_DRSMP_DRDLID_F,
+       IB_DRSMP_DRSLID_F,
 
        /* word 10,11 (36-43 bytes) */
        IB_SA_MKEY_F,
index 8c0e817..3eeca40 100644 (file)
@@ -14,6 +14,7 @@ USE_MSVCRT = 1
 \r
 SOURCES = \\r
        ibmad_main.cpp \\r
+       bm.c \\r
        dump.c \\r
        fields.c \\r
        gs.c \\r
diff --git a/ulp/libibmad/src/bm.c b/ulp/libibmad/src/bm.c
new file mode 100644 (file)
index 0000000..e335d92
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2004-2007 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.
+ *
+ */
+
+#if HAVE_CONFIG_H
+#  include <config.h>
+#endif                         /* HAVE_CONFIG_H */
+
+#include <string.h>
+
+#include <infiniband/mad.h>
+
+#undef DEBUG
+#define DEBUG  if (ibdebug)    IBWARN
+
+static inline int response_expected(int method)
+{
+       return method == IB_MAD_METHOD_GET ||
+           method == IB_MAD_METHOD_SET || method == IB_MAD_METHOD_TRAP;
+}
+
+uint8_t *bm_call_via(void *data, ib_portid_t * portid, ib_bm_call_t * call,
+                    struct ibmad_port * srcport)
+{
+       ib_rpc_t rpc = { 0 };
+       int resp_expected;
+       char data_with_bkey[IB_BM_BKEY_AND_DATA_SZ] = { 0 };
+
+       DEBUG("route %s data %p", portid2str(portid), data);
+       if (portid->lid <= 0) {
+               IBWARN("only lid routes are supported");
+               return 0;
+       }
+
+       resp_expected = response_expected(call->method);
+
+       rpc.mgtclass = IB_BOARD_MGMT_CLASS;
+
+       rpc.method = call->method;
+       rpc.attr.id = call->attrid;
+       rpc.attr.mod = call->mod;
+       rpc.timeout = resp_expected ? call->timeout : 0;
+       // send data and bkey
+       rpc.datasz = IB_BM_BKEY_AND_DATA_SZ;
+       rpc.dataoffs = IB_BM_BKEY_OFFS;
+
+       // copy data to a buffer which also includes the bkey
+       *((uint64_t *) data_with_bkey) = htonll(call->bkey);
+       memcpy(data_with_bkey + IB_BM_DATA_OFFS - IB_BM_BKEY_OFFS, data,
+              IB_BM_DATA_SZ);
+
+       DEBUG
+           ("method 0x%x attr 0x%x mod 0x%x datasz %d off %d res_ex %d bkey 0x%08x%08x",
+            rpc.method, rpc.attr.id, rpc.attr.mod, rpc.datasz, rpc.dataoffs,
+            resp_expected, (int)(call->bkey >> 32), (int)call->bkey);
+
+       portid->qp = 1;
+       if (!portid->qkey)
+               portid->qkey = IB_DEFAULT_QP1_QKEY;
+
+       if (resp_expected) {
+               /* FIXME: no RMPP for now */
+               if (mad_rpc
+                   (srcport, &rpc, portid, data_with_bkey, data_with_bkey))
+                       goto return_ok;
+               return NULL;
+       }
+
+       if (mad_send_via(&rpc, portid, 0, data_with_bkey, srcport) < 0)
+               return NULL;
+
+return_ok:
+       memcpy(data, data_with_bkey + IB_BM_DATA_OFFS - IB_BM_BKEY_OFFS,
+              IB_BM_DATA_SZ);
+       return data;
+}
index 1e93ff8..baea98e 100644 (file)
@@ -188,7 +188,7 @@ extend_dpath(struct ibnd_fabric *f, ib_portid_t *portid, int nextport)
                                        f->fabric.ibmad_port) < 0)
                                return -1;
 
-               portid->drpath.drslid = f->selfportid.lid;
+               portid->drpath.drslid = (uint16_t) f->selfportid.lid;
                portid->drpath.drdlid = 0xFFFF;
        }