static int send_144_node_desc_update(void) { ib_portid_t sm_port; ib_portid_t selfportid; int selfport; ib_rpc_t trap_rpc; ib_mad_notice_attr_t notice; if (ib_resolve_self(&selfportid, &selfport, NULL)) IBERROR("can't resolve self"); if (ib_resolve_smlid(&sm_port, 0)) IBERROR("can't resolve SM destination port"); memset(&trap_rpc, 0, sizeof(trap_rpc)); trap_rpc.mgtclass = IB_SMI_CLASS; trap_rpc.method = IB_MAD_METHOD_TRAP; trap_rpc.trid = mad_trid(); trap_rpc.attr.id = NOTICE; trap_rpc.datasz = IB_SMP_DATA_SIZE; trap_rpc.dataoffs = IB_SMP_DATA_OFFS; memset(¬ice, 0, sizeof(notice)); notice.generic_type = 0x80 | IB_NOTICE_TYPE_INFO; notice.g_or_v.generic.prod_type_lsb = cl_hton16(IB_NODE_TYPE_CA); notice.g_or_v.generic.trap_num = cl_hton16(144); notice.issuer_lid = cl_hton16(selfportid.lid); notice.data_details.ntc_144.lid = cl_hton16(selfportid.lid); notice.data_details.ntc_144.local_changes = TRAP_144_MASK_OTHER_LOCAL_CHANGES; notice.data_details.ntc_144.change_flgs = TRAP_144_MASK_NODE_DESCRIPTION_CHANGE; return (mad_send(&trap_rpc, &sm_port, NULL, ¬ice)); }
static void dump_perfcounters(int extended, int timeout, uint16_t cap_mask, ib_portid_t *portid, int port, int aggregate) { char buf[1024]; if (extended != 1) { if (!port_performance_query(pc, portid, port, timeout)) IBERROR("perfquery"); if (aggregate) aggregate_perfcounters(); else mad_dump_perfcounters(buf, sizeof buf, pc, sizeof pc); } else { 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)) IBERROR("perfextquery"); if (aggregate) aggregate_perfcounters_ext(); else mad_dump_perfcounters_ext(buf, sizeof buf, pc, sizeof pc); } if (!aggregate) printf("# Port counters: %s port %d\n%s", portid2str(portid), port, buf); }
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)) IBERROR("perf reset"); } else { if (!port_performance_ext_reset(pc, portid, port, mask, timeout)) IBERROR("perf ext reset"); } }
static void read_nodedesc() { int i; if ((di_rootnode = di_init("/", DINFOCPYALL | DINFOFORCE)) == DI_NODE_NIL) { IBERROR("read_nodedesc di_init failure"); return; } for (i = 0; ib_hca_driver_list[i]; i++) do_driver_read_ioctl(ib_hca_driver_list[i]); di_fini(di_rootnode); }
static int update_nodedesc(char *cmn_nodedesc, char *hca_nodedesc, uint64_t guid, uint32_t update_flag) { int i, rc = 0; if ((di_rootnode = di_init("/", DINFOCPYALL | DINFOFORCE)) == DI_NODE_NIL) { IBERROR("di_init failure"); return (-1); } for (i = 0; ib_hca_driver_list[i]; i++) { rc = do_driver_update_ioctl(ib_hca_driver_list[i], cmn_nodedesc, hca_nodedesc, guid, update_flag); if (!rc) break; } if (rc) IBERROR("Updated failed for all HCA drivers"); di_fini(di_rootnode); return (rc); }
static void do_driver_read_ioctl(char *drivername) { di_node_t hcanode, childnode; char *devpath; char *access_devname; int devlength, devfd, rc = -1; uint64_t *hca_guid; if ((hcanode = di_drv_first_node(drivername, di_rootnode)) == DI_NODE_NIL) { return; } while (hcanode != DI_NODE_NIL) { childnode = di_child_node(hcanode); while (childnode != DI_NODE_NIL) { if (di_prop_lookup_int64(DDI_DEV_T_ANY, childnode, "hca-guid", (int64_t **)&hca_guid) != 1) { childnode = di_sibling_node(childnode); continue; } else { break; } } if (childnode == DI_NODE_NIL) { hcanode = di_drv_next_node(hcanode); continue; } devpath = di_devfs_path(hcanode); devlength = strlen(devpath_prefix) + strlen(devpath) + strlen(devpath_suffix) + 2; access_devname = malloc(devlength); (void) snprintf(access_devname, devlength, "%s%s%s", devpath_prefix, devpath, devpath_suffix); if ((devfd = open(access_devname, O_RDONLY)) < 0) { IBERROR("open device file %s failed", access_devname); free(access_devname); hcanode = di_drv_next_node(hcanode); continue; } if (strcmp(drivername, "hermon") == 0) { hermon_nodedesc_ioctl_t nodedesc_ioctl; if ((rc = ioctl(devfd, HERMON_IOCTL_GET_NODEDESC, (void *)&nodedesc_ioctl)) != 0) { IBERROR("hermon ioctl failure"); free(access_devname); close(devfd); hcanode = di_drv_next_node(hcanode); continue; } add_read_info_arr((char *)nodedesc_ioctl.node_desc_str, *hca_guid); } else { IBERROR("drivername != hermon: %s", drivername); } free(access_devname); close(devfd); hcanode = di_drv_next_node(hcanode); } }
static int do_driver_update_ioctl(char *drivername, char *node_desc, char *hca_desc, uint64_t inp_hca_guid, uint32_t update_flag) { di_node_t hcanode, childnode; char *devpath; char *access_devname; int devlength, devfd, rc = -1; uint64_t *hca_guid; char *desc_str = (node_desc ? node_desc : hca_desc); if ((hcanode = di_drv_first_node(drivername, di_rootnode)) == DI_NODE_NIL) { return (-1); } while (hca_desc && hcanode != DI_NODE_NIL) { childnode = di_child_node(hcanode); while (childnode != DI_NODE_NIL) { if (di_prop_lookup_int64(DDI_DEV_T_ANY, childnode, "hca-guid", (int64_t **)&hca_guid) != 1) { childnode = di_sibling_node(childnode); continue; } else { break; } } if (*hca_guid == inp_hca_guid) break; hcanode = di_drv_next_node(hcanode); } if ((hca_desc && childnode == DI_NODE_NIL) || hcanode == DI_NODE_NIL) { IBERROR("matching GUID not found"); return (-1); } devpath = di_devfs_path(hcanode); devlength = strlen(devpath_prefix) + strlen(devpath) + strlen(devpath_suffix) + 2; access_devname = malloc(devlength); (void) snprintf(access_devname, devlength, "%s%s%s", devpath_prefix, devpath, devpath_suffix); if ((devfd = open(access_devname, O_RDONLY)) < 0) { IBERROR("open device file %s failed", access_devname); free(access_devname); return (rc); } if (strcmp(drivername, "hermon") == 0) { hermon_nodedesc_ioctl_t nodedesc_ioctl; strncpy(nodedesc_ioctl.node_desc_str, desc_str, 64); if (update_flag & NODEDESC_UPDATE_STRING) nodedesc_ioctl.node_desc_update_flag = HERMON_NODEDESC_UPDATE_STRING; else if (update_flag & NODEDESC_UPDATE_HCA_STRING) nodedesc_ioctl.node_desc_update_flag = HERMON_NODEDESC_UPDATE_HCA_STRING; else { IBERROR("Invalid option"); exit(-1); } if ((rc = ioctl(devfd, HERMON_IOCTL_SET_NODEDESC, (void *)&nodedesc_ioctl)) != 0) { IBERROR("hermon ioctl failure"); } } else { IBERROR("drivername != hermon: %s", drivername); } free(access_devname); close(devfd); return (rc); }
int main(int argc, char **argv) { int mgmt_classes[4] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS, IB_PERFORMANCE_CLASS}; ib_portid_t *sm_id = 0, sm_portid = {0}; ib_portid_t portid = {0}; extern int ibdebug; int dest_type = IB_DEST_LID; int timeout = 0; /* use default */ int mask = 0xffff, all_ports = 0; int reset = 0, reset_only = 0; int port = 0; int udebug = 0; char *ca = 0; int ca_port = 0; int extended = 0; uint16_t cap_mask; int all_ports_loop = 0; int loop_ports = 0; int node_type, num_ports = 0; uint8_t data[IB_SMP_DATA_SIZE]; int start_port = 1; int enhancedport0; int i; static char const str_opts[] = "C:P:s:t:dGealrRVhu"; static const struct option long_opts[] = { { "C", 1, 0, 'C'}, { "P", 1, 0, 'P'}, { "debug", 0, 0, 'd'}, { "Guid", 0, 0, 'G'}, { "extended", 0, 0, 'e'}, { "all_ports", 0, 0, 'a'}, { "loop_ports", 0, 0, 'l'}, { "reset_after_read", 0, 0, 'r'}, { "Reset_only", 0, 0, 'R'}, { "sm_portid", 1, 0, 's'}, { "timeout", 1, 0, 't'}, { "Version", 0, 0, 'V'}, { "help", 0, 0, 'h'}, { "usage", 0, 0, 'u'}, { } }; argv0 = argv[0]; while (1) { int ch = getopt_long(argc, argv, str_opts, long_opts, NULL); if ( ch == -1 ) break; switch(ch) { case 'C': ca = optarg; break; case 'P': ca_port = strtoul(optarg, 0, 0); break; case 'e': extended = 1; break; case 'a': all_ports++; port = ALL_PORTS; break; case 'l': loop_ports++; break; case 'd': ibdebug++; madrpc_show_errors(1); umad_debug(udebug); udebug++; break; case 'G': dest_type = IB_DEST_GUID; break; case 's': if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0) IBERROR("can't resolve SM destination port %s", optarg); sm_id = &sm_portid; break; case 'r': reset++; break; case 'R': reset_only++; break; case 't': timeout = strtoul(optarg, 0, 0); madrpc_set_timeout(timeout); break; case 'V': fprintf(stderr, "%s %s\n", argv0, get_build_version() ); exit(-1); default: usage(); break; } } argc -= optind; argv += optind; if (argc > 1) port = strtoul(argv[1], 0, 0); if (argc > 2) mask = strtoul(argv[2], 0, 0); madrpc_init(ca, ca_port, mgmt_classes, 4); if (argc) { if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0) IBERROR("can't resolve destination port %s", argv[0]); } else { if (ib_resolve_self(&portid, &port, 0) < 0) IBERROR("can't resolve self port %s", argv[0]); } /* PerfMgt ClassPortInfo is a required attribute */ if (!perf_classportinfo_query(pc, &portid, port, timeout)) IBERROR("classportinfo query"); /* ClassPortInfo should be supported as part of libibmad */ memcpy(&cap_mask, pc+2, sizeof(cap_mask)); /* CapabilityMask */ cap_mask = ntohs(cap_mask); if (!(cap_mask & 0x100)) { /* bit 8 is AllPortSelect */ if (!all_ports && port == ALL_PORTS) IBERROR("AllPortSelect not supported"); if (all_ports) all_ports_loop = 1; } if (all_ports_loop || (loop_ports && (all_ports || port == ALL_PORTS))) { if (smp_query(data, &portid, IB_ATTR_NODE_INFO, 0, 0) < 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); if (!num_ports) 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) IBERROR("smp query nodeinfo failed"); enhancedport0 = mad_get_field(data, 0, IB_SW_ENHANCED_PORT0_F); if (enhancedport0) start_port = 0; } if (all_ports_loop && !loop_ports) IBWARN("Emulating AllPortSelect by iterating through all ports"); } if (reset_only) goto do_reset; if (all_ports_loop || (loop_ports && (all_ports || port == ALL_PORTS))) { for (i = start_port; i <= num_ports; i++) dump_perfcounters(extended, timeout, cap_mask, &portid, i, (all_ports_loop && !loop_ports)); if (all_ports_loop && !loop_ports) { if (extended != 1) output_aggregate_perfcounters(&portid); else output_aggregate_perfcounters_ext(&portid); } } else dump_perfcounters(extended, timeout, cap_mask, &portid, port, 0); if (!reset) exit(0); do_reset: if (all_ports_loop || (loop_ports && (all_ports || port == ALL_PORTS))) { for (i = start_port; i <= num_ports; i++) reset_counters(extended, timeout, mask, &portid, i); } else reset_counters(extended, timeout, mask, &portid, port); exit(0); }
dsc* EVAL_value(qli_nod* node) { /************************************** * * E V A L _ v a l u e * ************************************** * * Functional description * Evaluate a value node. * **************************************/ DSC *values[4]; // Start by evaluating sub-expressions (where appropriate) dsc* desc = &node->nod_desc; fb_assert(node->nod_count < 5); qli_nod** ptr = node->nod_arg; const qli_nod* const* const end_ptr = ptr + node->nod_count; for (dsc** value = values; ptr < end_ptr; ptr++, value++) { *value = EVAL_value(*ptr); if (node->nod_flags & nod_partial) break; } switch (node->nod_type) { case nod_edit_blob: return execute_edit(node); case nod_rpt_max: case nod_rpt_min: case nod_rpt_total: case nod_rpt_average: if (!(IPTR) node->nod_arg[e_stt_default]) desc->dsc_missing = DSC_missing; case nod_rpt_count: case nod_constant: return desc; case nod_variable: { qli_fld* field = (qli_fld*) node->nod_arg[e_fld_field]; desc->dsc_missing = (field->fld_flags & FLD_missing) ? DSC_missing : 0; } return desc; case nod_field: return EVAL_value(node->nod_arg[e_fld_reference]); case nod_reference: return EVAL_parameter(node->nod_import); case nod_null: return desc; case nod_add: if ((values[0]->dsc_missing & DSC_missing) || (values[1]->dsc_missing & DSC_missing)) { desc->dsc_missing = DSC_missing; return desc; } desc->dsc_missing = FALSE; if (node->nod_flags & nod_date) { double d1 = MOVQ_date_to_double(values[0]) + MOVQ_get_double(values[1]); MOVQ_double_to_date(d1, (SLONG*) desc->dsc_address); } else if (desc->dsc_dtype == dtype_long) { *((SLONG*) desc->dsc_address) = MOVQ_get_long(values[0], desc->dsc_scale) + MOVQ_get_long(values[1], desc->dsc_scale); } else *((double*) desc->dsc_address) = MOVQ_get_double(values[0]) + MOVQ_get_double(values[1]); return desc; case nod_subtract: if ((values[0]->dsc_missing & DSC_missing) || (values[1]->dsc_missing & DSC_missing)) { desc->dsc_missing = DSC_missing; return desc; } desc->dsc_missing = FALSE; if (node->nod_flags & nod_date) { *((double*) desc->dsc_address) = MOVQ_date_to_double(values[0]) - MOVQ_date_to_double(values[1]); } else if (desc->dsc_dtype == dtype_long) { *((SLONG*) desc->dsc_address) = MOVQ_get_long(values[0], desc->dsc_scale) - MOVQ_get_long(values[1], desc->dsc_scale); } else *((double*) desc->dsc_address) = MOVQ_get_double(values[0]) - MOVQ_get_double(values[1]); return desc; case nod_divide: if ((values[0]->dsc_missing & DSC_missing) || (values[1]->dsc_missing & DSC_missing)) { desc->dsc_missing = DSC_missing; return desc; } desc->dsc_missing = FALSE; *((double*) desc->dsc_address) = MOVQ_get_double(values[0]) / MOVQ_get_double(values[1]); return desc; case nod_multiply: if ((values[0]->dsc_missing & DSC_missing) || (values[1]->dsc_missing & DSC_missing)) { desc->dsc_missing = DSC_missing; return desc; } desc->dsc_missing = FALSE; if (desc->dsc_dtype == dtype_long) { *((SLONG*) desc->dsc_address) = MOVQ_get_long(values[0], values[0]->dsc_scale) * MOVQ_get_long(values[1], values[1]->dsc_scale); } else *((double*) desc->dsc_address) = MOVQ_get_double(values[0]) * MOVQ_get_double(values[1]); return desc; case nod_negate: if (values[0]->dsc_missing & DSC_missing) { desc->dsc_missing = DSC_missing; return desc; } desc->dsc_missing = FALSE; switch (desc->dsc_dtype) { case dtype_short: *((SSHORT*) desc->dsc_address) = -MOVQ_get_long(values[0], desc->dsc_scale); break; case dtype_long: *((SLONG*) desc->dsc_address) = -MOVQ_get_long(values[0], desc->dsc_scale); break; // lets throw arithmetic not supported until fixed //case dtype_int64: // *((SINT64*) desc->dsc_address) = -MOVQ_get_long(values[0], desc->dsc_scale); // break; case dtype_real: *((float*) desc->dsc_address) = -MOVQ_get_double(values[0]); break; case dtype_double: *((double*) desc->dsc_address) = -MOVQ_get_double(values[0]); break; default: IBERROR(30); // Msg30 data type not supported for arithmetic } return desc; case nod_prompt: if (!prompt[0][0]) { ERRQ_msg_get(499, prompt[0], sizeof(prompt[0])); // Msg499 Re-enter ERRQ_msg_get(500, prompt[1], sizeof(prompt[1])); // Msg500 Enter } return execute_prompt(node); case nod_concatenate: return execute_concatenate(node, values[0], values[1]); case nod_function: return execute_function(node); case nod_max: case nod_min: case nod_count: case nod_average: case nod_total: case nod_from: return execute_statistical(node); case nod_running_count: *(SLONG*) (desc->dsc_address) += 1; return desc; case nod_running_total: { dsc* desc2 = EVAL_value(node->nod_arg[e_stt_value]); if (desc2) { if (desc2->dsc_missing & DSC_missing) return desc; if (desc->dsc_dtype == dtype_long) *(SLONG*) desc->dsc_address += MOVQ_get_long(desc2, desc->dsc_scale); else *(double*) desc->dsc_address += MOVQ_get_double(desc2); } } return desc; case nod_format: { UCHAR* p = desc->dsc_address; PIC_edit(values[0], (pics*) node->nod_arg[e_fmt_picture], (TEXT**) &p, desc->dsc_length); desc->dsc_length = p - desc->dsc_address; } return desc; case nod_user_name: IBERROR(31); // Msg31 user name is supported only in RSEs temporarily case nod_parameter: case nod_position: case nod_substr: case nod_via: default: ERRQ_bugcheck(29); // Msg29 EVAL_value: not finished return NULL; } }
int main(int argc, char **argv) { int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS}; ib_portid_t portid = {0}; ib_portid_t *sm_id = 0, sm_portid = {0}; int timeout; int multicast = 0, startlid = 0, endlid = 0; char *err; char *ca = 0; int ca_port = 0; static char const str_opts[] = "C:P:t:s:danvDGMVhu"; static const struct option long_opts[] = { { "C", 1, 0, 'C'}, { "P", 1, 0, 'P'}, { "debug", 0, 0, 'd'}, { "all", 0, 0, 'a'}, { "no_dests", 0, 0, 'n'}, { "verbose", 0, 0, 'v'}, { "Direct", 0, 0, 'D'}, { "Guid", 0, 0, 'G'}, { "Multicast", 0, 0, 'M'}, { "timeout", 1, 0, 't'}, { "s", 1, 0, 's'}, { "Version", 0, 0, 'V'}, { "help", 0, 0, 'h'}, { "usage", 0, 0, 'u'}, { } }; argv0 = argv[0]; while (1) { int ch = getopt_long(argc, argv, str_opts, long_opts, NULL); if ( ch == -1 ) break; switch(ch) { case 'C': ca = optarg; break; case 'P': ca_port = strtoul(optarg, 0, 0); break; case 'a': dump_all++; break; case 'd': ibdebug++; break; case 'D': dest_type = IB_DEST_DRPATH; break; case 'G': dest_type = IB_DEST_GUID; break; case 'M': multicast++; break; case 'n': brief++; break; case 's': if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0) IBERROR("can't resolve SM destination port %s", optarg); sm_id = &sm_portid; break; case 't': timeout = strtoul(optarg, 0, 0); madrpc_set_timeout(timeout); break; case 'v': madrpc_show_errors(1); verbose++; break; case 'V': fprintf(stderr, "%s %s\n", argv0, get_build_version() ); exit(-1); default: usage(); break; } } argc -= optind; argv += optind; if (!argc) usage(); if (argc > 1) startlid = strtoul(argv[1], 0, 0); if (argc > 2) endlid = strtoul(argv[2], 0, 0); madrpc_init(ca, ca_port, mgmt_classes, 3); if (!argc) { if (ib_resolve_self(&portid, 0, 0) < 0) IBERROR("can't resolve self addr"); } else { if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0) IBERROR("can't resolve destination port %s", argv[1]); } if (multicast) err = dump_multicast_tables(&portid, startlid, endlid); else err = dump_unicast_tables(&portid, startlid, endlid); if (err) IBERROR("dump tables: %s", err); exit(0); }
int main(int argc, char **argv) { int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS}; int ping_class = IB_VENDOR_OPENIB_PING_CLASS; ib_portid_t *sm_id = 0, sm_portid = {0}; int timeout = 0, udebug = 0, server = 0, flood = 0; int oui = IB_OPENIB_OUI; uint64_t rtt; unsigned count = ~0; extern int ibdebug; char *err; char *ca = 0; int ca_port = 0; static char const str_opts[] = "C:P:t:s:c:o:devGfSVhu"; static const struct option long_opts[] = { { "C", 1, 0, 'C'}, { "P", 1, 0, 'P'}, { "debug", 0, 0, 'd'}, { "err_show", 0, 0, 'e'}, { "verbose", 0, 0, 'v'}, { "Guid", 0, 0, 'G'}, { "s", 1, 0, 's'}, { "timeout", 1, 0, 't'}, { "c", 1, 0, 'c'}, { "flood", 0, 0, 'f'}, { "o", 1, 0, 'o'}, { "Server", 0, 0, 'S'}, { "Version", 0, 0, 'V'}, { "help", 0, 0, 'h'}, { "usage", 0, 0, 'u'}, { } }; argv0 = argv[0]; while (1) { int ch = getopt_long(argc, argv, str_opts, long_opts, NULL); if ( ch == -1 ) break; switch(ch) { case 'C': ca = optarg; break; case 'P': ca_port = strtoul(optarg, 0, 0); break; case 'c': count = strtoul(optarg, 0, 0); break; case 'd': ibdebug++; madrpc_show_errors(1); umad_debug(udebug); udebug++; break; case 'e': madrpc_show_errors(1); break; case 'f': flood++; break; case 'G': dest_type = IB_DEST_GUID; break; case 'o': oui = strtoul(optarg, 0, 0); break; case 's': if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0) IBERROR("can't resolve SM destination port %s", optarg); sm_id = &sm_portid; break; case 'S': server++; break; case 't': timeout = strtoul(optarg, 0, 0); madrpc_set_timeout(timeout); break; case 'v': verbose++; break; case 'V': fprintf(stderr, "%s %s\n", argv0, get_build_version() ); exit(-1); default: usage(); break; } } argc -= optind; argv += optind; if (!argc && !server) usage(); madrpc_init(ca, ca_port, mgmt_classes, 3); if (server) { if (mad_register_server(ping_class, 0, 0, oui) < 0) IBERROR("can't serve class %d on this port", ping_class); get_host_and_domain(host_and_domain, sizeof host_and_domain); if ((err = ibping_serv())) IBERROR("ibping to %s: %s", portid2str(&portid), err); exit(0); } if (mad_register_client(ping_class, 0) < 0) IBERROR("can't register ping class %d on this port", ping_class); if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0) IBERROR("can't resolve destination port %s", argv[0]); signal(SIGINT, report); signal(SIGTERM, report); start = getcurrenttime(); while (count-- > 0) { ntrans++; if ((rtt = ibping(&portid, flood)) == ~0ull) { DEBUG("ibping to %s failed", portid2str(&portid)); lost++; } else { if (rtt < minrtt) minrtt = rtt; if (rtt > maxrtt) maxrtt = rtt; total_rtt += rtt; replied++; } if (!flood) sleep(1); } report(0); exit(-1); }
static void edit_alpha(const dsc* desc, pics* picture, TEXT** output, USHORT max_length) { /************************************** * * e d i t _ a l p h a * ************************************** * * Functional description * Edit data from a descriptor through an edit string to a running * output pointer. * **************************************/ Firebird::VaryStr<512> temp; const TEXT* p = NULL; const USHORT l = MOVQ_get_string(desc, &p, &temp, sizeof(temp)); const TEXT* const end = p + l; picture->pic_pointer = picture->pic_string; picture->pic_count = 0; TEXT* out = *output; while (p < end) { if ((out - *output) >= max_length) break; TEXT c = generate(picture); if (!c || c == '?') break; c = UPPER(c); switch (c) { case 'X': *out++ = *p++; break; case 'A': if ((*p >= 'a' && *p <= 'z') || (*p >= 'A' && *p <= 'Z')) *out++ = *p++; else IBERROR(69); // Msg 69 conversion error break; case 'B': *out++ = ' '; break; case '"': case '\'': case '\\': literal(picture, c, &out); break; default: *out++ = c; break; } } *output = out; }
int main(int argc, char **argv) { int mgmt_classes[1] = { IB_SA_CLASS }; int ping_class = IB_VENDOR_OPENIB_PING_CLASS; uint64_t rtt; char *err; const struct ibdiag_opt opts[] = { {"count", 'c', 1, "<num>", "stop after count packets"}, {"flood", 'f', 0, NULL, "flood destination"}, {"oui", 'o', 1, NULL, "use specified OUI number"}, {"Server", 'S', 0, NULL, "start in server mode"}, {0} }; char usage_args[] = "<dest lid|guid>"; ibdiag_process_opts(argc, argv, NULL, "DKy", opts, process_opt, usage_args, NULL); argc -= optind; argv += optind; if (!argc && !server) ibdiag_show_usage(); srcport = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 1); if (!srcport) IBERROR("Failed to open '%s' port '%d'", ibd_ca, ibd_ca_port); if (server) { 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); if ((err = ibping_serv())) IBERROR("ibping to %s: %s", portid2str(&portid), err); exit(0); } if (mad_register_client_via(ping_class, 0, srcport) < 0) IBERROR("can't register ping class %d on this port", ping_class); if (resolve_portid_str(ibd_ca, ibd_ca_port, &portid, argv[0], ibd_dest_type, ibd_sm_id, srcport) < 0) IBERROR("can't resolve destination port %s", argv[0]); signal(SIGINT, report); signal(SIGTERM, report); start = cl_get_time_stamp(); while (count-- > 0) { ntrans++; if ((rtt = ibping(&portid, flood)) == ~0ull) { DEBUG("ibping to %s failed", portid2str(&portid)); lost++; } else { if (rtt < minrtt) minrtt = rtt; if (rtt > maxrtt) maxrtt = rtt; total_rtt += rtt; replied++; } if (!flood) sleep(1); } report(0); mad_rpc_close_port(srcport); exit(-1); }
static int process_opt(int ch, char *optarg) { char *endp; long val; switch (ch) { case 'z': read_ibdiag_config(optarg); break; case 'h': ibdiag_show_usage(); break; case 'V': fprintf(stderr, "%s %s\n", prog_name, get_build_version()); exit(0); case 'e': madrpc_show_errors(1); break; case 'v': ibverbose++; break; case 'd': ibdebug++; madrpc_show_errors(1); umad_debug(ibdebug - 1); break; case 'C': ibd_ca = optarg; break; case 'P': ibd_ca_port = strtoul(optarg, 0, 0); break; case 'D': ibd_dest_type = IB_DEST_DRPATH; break; case 'L': ibd_dest_type = IB_DEST_LID; break; case 'G': ibd_dest_type = IB_DEST_GUID; break; case 't': errno = 0; val = strtol(optarg, &endp, 0); if (errno || (endp && *endp != '\0') || val <= 0 || val > INT_MAX) IBERROR("Invalid timeout \"%s\". Timeout requires a " "positive integer value < %d.", optarg, INT_MAX); else { madrpc_set_timeout((int)val); ibd_timeout = (int)val; } break; case 's': /* srcport is not required when resolving via IB_DEST_LID */ if (resolve_portid_str(ibd_ca, ibd_ca_port, &sm_portid, optarg, IB_DEST_LID, 0, NULL) < 0) IBERROR("cannot resolve SM destination port %s", optarg); ibd_sm_id = &sm_portid; break; case 'K': show_keys = 1; break; case 'y': errno = 0; ibd_mkey = strtoull(optarg, &endp, 0); if (errno || *endp != '\0') { errno = 0; ibd_mkey = strtoull(getpass("M_Key: "), &endp, 0); if (errno || *endp != '\0') { IBERROR("Bad M_Key"); } } break; default: return -1; } return 0; }
int main(int argc, char **argv) { int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS}; ib_portid_t *sm_id = 0, sm_portid = {0}; ib_portid_t portid = {0}; extern int ibdebug; int dest_type = IB_DEST_LID; int timeout = 0; /* use default */ int show_lid = 0, show_gid = 0; int port = 0; char *ca = 0; int ca_port = 0; static char const str_opts[] = "C:P:t:s:dDGglLVhu"; static const struct option long_opts[] = { { "C", 1, 0, 'C'}, { "P", 1, 0, 'P'}, { "debug", 0, 0, 'd'}, { "Direct", 0, 0, 'D'}, { "Guid", 0, 0, 'G'}, { "gid_show", 0, 0, 'g'}, { "lid_show", 0, 0, 'l'}, { "Lid_show", 0, 0, 'L'}, { "timeout", 1, 0, 't'}, { "sm_port", 1, 0, 's'}, { "Version", 0, 0, 'V'}, { "help", 0, 0, 'h'}, { "usage", 0, 0, 'u'}, { } }; argv0 = argv[0]; while (1) { int ch = getopt_long(argc, argv, str_opts, long_opts, NULL); if ( ch == -1 ) break; switch(ch) { case 'C': ca = optarg; break; case 'P': ca_port = strtoul(optarg, 0, 0); break; case 'd': ibdebug++; break; case 'D': dest_type = IB_DEST_DRPATH; break; case 'g': show_gid++; break; case 'G': dest_type = IB_DEST_GUID; break; case 'l': show_lid++; break; case 'L': show_lid = -100; break; case 's': if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0) IBERROR("can't resolve SM destination port %s", optarg); sm_id = &sm_portid; break; case 't': timeout = strtoul(optarg, 0, 0); madrpc_set_timeout(timeout); break; case 'V': fprintf(stderr, "%s %s\n", argv0, get_build_version() ); exit(-1); default: usage(); break; } } argc -= optind; argv += optind; if (argc > 1) port = strtoul(argv[1], 0, 0); if (!show_lid && !show_gid) show_lid = show_gid = 1; madrpc_init(ca, ca_port, mgmt_classes, 3); if (argc) { if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0) IBERROR("can't resolve destination port %s", argv[0]); } else { if (ib_resolve_self(&portid, &port, 0) < 0) IBERROR("can't resolve self port %s", argv[0]); } if (ib_resolve_addr(&portid, port, show_lid, show_gid) < 0) IBERROR("can't resolve requested address"); exit(0); }
int main(int argc, char **argv) { int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS}; ib_portid_t portid = {0}; ib_portid_t *sm_id = 0, sm_portid = {0}; extern int ibdebug; int err; int timeout = 0, udebug = 0; char *ca = 0; int ca_port = 0; int port_op = 0; /* default to query */ int speed = 15; int is_switch = 1; int state, physstate, lwe, lws, lwa, lse, lss, lsa; int peerlocalportnum, peerlwe, peerlws, peerlwa, peerlse, peerlss, peerlsa; int width, peerwidth, peerspeed; uint8_t data[IB_SMP_DATA_SIZE]; ib_portid_t peerportid = {0}; int portnum = 0; ib_portid_t selfportid = {0}; int selfport = 0; static char const str_opts[] = "C:P:t:s:devDGVhu"; static const struct option long_opts[] = { { "C", 1, 0, 'C'}, { "P", 1, 0, 'P'}, { "debug", 0, 0, 'd'}, { "err_show", 0, 0, 'e'}, { "verbose", 0, 0, 'v'}, { "Direct", 0, 0, 'D'}, { "Guid", 0, 0, 'G'}, { "timeout", 1, 0, 't'}, { "s", 1, 0, 's'}, { "Version", 0, 0, 'V'}, { "help", 0, 0, 'h'}, { "usage", 0, 0, 'u'}, { } }; argv0 = argv[0]; while (1) { int ch = getopt_long(argc, argv, str_opts, long_opts, NULL); if ( ch == -1 ) break; switch(ch) { case 'd': ibdebug++; madrpc_show_errors(1); umad_debug(udebug); udebug++; break; case 'e': madrpc_show_errors(1); break; case 'D': dest_type = IB_DEST_DRPATH; break; case 'G': dest_type = IB_DEST_GUID; break; case 'C': ca = optarg; break; case 'P': ca_port = strtoul(optarg, 0, 0); break; case 's': if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0) IBERROR("can't resolve SM destination port %s", optarg); sm_id = &sm_portid; break; case 't': timeout = strtoul(optarg, 0, 0); madrpc_set_timeout(timeout); break; case 'v': verbose++; break; case 'V': fprintf(stderr, "%s %s\n", argv0, get_build_version() ); exit(-1); default: usage(); break; } } argc -= optind; argv += optind; if (argc < 2) usage(); madrpc_init(ca, ca_port, mgmt_classes, 3); if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0) IBERROR("can't resolve destination port %s", argv[0]); /* First, make sure it is a switch port if it is a "set" */ if (argc >= 3) { if (!strcmp(argv[2], "enable")) port_op = 1; else if (!strcmp(argv[2], "disable")) port_op = 2; else if (!strcmp(argv[2], "reset")) port_op = 3; else if (!strcmp(argv[2], "speed")) { if (argc < 4) IBERROR("speed requires an additional parameter"); port_op = 4; /* Parse speed value */ speed = strtoul(argv[3], 0, 0); if (speed > 15) IBERROR("invalid speed value %d", speed); } } err = get_node_info(&portid, data); if (err < 0) IBERROR("smp query nodeinfo failed"); if (err) { /* not switch */ if (port_op == 0) /* query op */ is_switch = 0; else if (port_op != 4) /* other than speed op */ IBERROR("smp query nodeinfo: Node type not switch"); } if (argc-1 > 0) portnum = strtol(argv[1], 0, 0); if (port_op) printf("Initial PortInfo:\n"); else printf("PortInfo:\n"); err = get_port_info(&portid, data, portnum, port_op); if (err < 0) IBERROR("smp query portinfo failed"); /* Only if one of the "set" options is chosen */ if (port_op) { if (port_op == 1) /* Enable port */ mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 2); /* Polling */ else if ((port_op == 2) || (port_op == 3)) { /* Disable port */ mad_set_field(data, 0, IB_PORT_STATE_F, 1); /* Down */ mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 3); /* Disabled */ } else if (port_op == 4) { /* Set speed */ mad_set_field(data, 0, IB_PORT_LINK_SPEED_ENABLED_F, speed); mad_set_field(data, 0, IB_PORT_STATE_F, 0); mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 0); } err = set_port_info(&portid, data, portnum, port_op); if (err < 0) IBERROR("smp set portinfo failed"); if (port_op == 3) { /* Reset port - so also enable */ mad_set_field(data, 0, IB_PORT_PHYS_STATE_F, 2); /* Polling */ err = set_port_info(&portid, data, portnum, port_op); if (err < 0) IBERROR("smp set portinfo failed"); } } else { /* query op */ /* only compare peer port if switch port */ if (is_switch) { /* First, exclude SP0 */ if (portnum) { /* Now, make sure PortState is Active */ /* Or is PortPhysicalState LinkUp sufficient ? */ mad_decode_field(data, IB_PORT_STATE_F, &state); mad_decode_field(data, IB_PORT_PHYS_STATE_F, &physstate); if (state == 4) { /* Active */ mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, &lwe ); mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, &lws); mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, &lwa); mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, &lss); mad_decode_field(data, IB_PORT_LINK_SPEED_ACTIVE_F, &lsa); mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, &lse); /* Setup portid for peer port */ memcpy(&peerportid, &portid, sizeof(peerportid)); peerportid.drpath.cnt = 1; peerportid.drpath.p[1] = portnum; /* Set DrSLID to local lid */ if (ib_resolve_self(&selfportid, &selfport, 0) < 0) IBERROR("could not resolve self"); peerportid.drpath.drslid = selfportid.lid; peerportid.drpath.drdlid = 0xffff; /* Get peer port NodeInfo to obtain peer port number */ err = get_node_info(&peerportid, data); if (err < 0) IBERROR("smp query nodeinfo failed"); mad_decode_field(data, IB_NODE_LOCAL_PORT_F, &peerlocalportnum); printf("Peer PortInfo:\n"); /* Get peer port characteristics */ err = get_port_info(&peerportid, data, peerlocalportnum, port_op); if (err < 0) IBERROR("smp query peer portinfofailed"); mad_decode_field(data, IB_PORT_LINK_WIDTH_ENABLED_F, &peerlwe ); mad_decode_field(data, IB_PORT_LINK_WIDTH_SUPPORTED_F, &peerlws); mad_decode_field(data, IB_PORT_LINK_WIDTH_ACTIVE_F, &peerlwa); mad_decode_field(data, IB_PORT_LINK_SPEED_SUPPORTED_F, &peerlss); mad_decode_field(data, IB_PORT_LINK_SPEED_ACTIVE_F, &peerlsa); mad_decode_field(data, IB_PORT_LINK_SPEED_ENABLED_F, &peerlse); /* Now validate peer port characteristics */ /* Examine Link Width */ width = get_link_width(lwe, lws); peerwidth = get_link_width(peerlwe, peerlws); validate_width(width, peerwidth, lwa); /* Examine Link Speed */ speed = get_link_speed(lse, lss); peerspeed = get_link_speed(peerlse, peerlss); validate_speed(speed, peerspeed, lsa); } } } } exit(0); }
int main(int argc, char **argv) { int rc; char *nodedesc = NULL, *hcadesc = NULL; uint32_t update_flag = 0; struct utsname uts_name; uint64_t hca_guid; boolean_t guid_inited = B_FALSE; extern int ibdebug; char nodename[64]; static char const str_opts[] = "N:H:G:vd"; static const struct option long_opts[] = { { "Node_Descriptor", 1, 0, 'N'}, { "HCA_Description", 1, 0, 'H'}, { "GUID", 1, 0, 'G'}, { "verbose", 0, 0, 'v'}, { "debug", 0, 0, 'd'}, { } }; argv0 = argv[0]; while (1) { int ch = getopt_long(argc, argv, str_opts, long_opts, NULL); if (ch == -1) break; switch (ch) { case 'N': nodedesc = nodedesc_substr_cat(argv, argc, B_TRUE); if (!nodedesc) { usage(); rc = -1; goto free_and_ret; } update_flag |= NODEDESC_UPDATE_STRING; break; case 'H': hcadesc = nodedesc_substr_cat(argv, argc, B_FALSE); if (!hcadesc) { usage(); rc = -1; goto free_and_ret; } update_flag |= NODEDESC_UPDATE_HCA_STRING; break; case 'G': guid_inited = B_TRUE; hca_guid = (uint64_t)strtoull(optarg, 0, 0); break; case 'v' : update_flag |= NODEDESC_READ; break; case 'd': ibdebug++; break; default: usage(); rc = -1; goto free_and_ret; } } if (update_flag & NODEDESC_READ) { if (nodedesc || hcadesc || guid_inited == B_TRUE) { usage(); rc = -1; goto free_and_ret; } read_nodedesc(); update_read_info_hwnames(); print_read_info(); return (0); } if (hcadesc && guid_inited == B_FALSE) { IBERROR("No GUID specified for HCA Node descriptor"); usage(); rc = -1; goto free_and_ret; } if (nodedesc) { rc = update_nodedesc(nodedesc, NULL, 0, NODEDESC_UPDATE_STRING); if (rc) { IBERROR("write common node descriptor " "failed"); rc = -1; goto free_and_ret; } } if (hcadesc) { rc = update_nodedesc(NULL, hcadesc, hca_guid, NODEDESC_UPDATE_HCA_STRING); if (rc) { IBERROR("update_hca_noddesc failed"); rc = -1; goto free_and_ret; } return (0); } if (nodedesc == NULL) { if (uname(&uts_name) < 0) { IBERROR("Node descriptor unspecified" "& uts_name failed"); rc = -1; goto free_and_ret; } /* * The common nodedesc string can have max 64 chars. * We can accomodate 63 chars from uname and alike * option -N, we append a space to the nodename. */ (void) strncpy(nodename, uts_name.nodename, 63); if (nodename[strlen(nodename)] != ' ') (void) strncat(nodename, " ", 1); rc = update_nodedesc(nodename, NULL, 0, NODEDESC_UPDATE_STRING); if (rc) { IBERROR("write common node descriptor failed"); rc = -1; } } free_and_ret: if (nodedesc) free(nodedesc); if (hcadesc) free(hcadesc); return (rc); }
int main(int argc, char **argv) { ibnd_fabric_t *fabric = NULL; char *orig_cache_file = NULL; char *new_cache_file = NULL; struct guids guids; const struct ibdiag_opt opts[] = { {"switchguid", 1, 1, "BEFOREGUID:AFTERGUID", "Specify before and after switchguid to edit"}, {"caguid", 2, 1, "BEFOREGUID:AFTERGUID", "Specify before and after caguid to edit"}, {"sysimgguid", 3, 1, "BEFOREGUID:AFTERGUID", "Specify before and after sysimgguid to edit"}, {"portguid", 4, 1, "NODEGUID:BEFOREGUID:AFTERGUID", "Specify before and after port guid to edit"}, {0} }; char *usage_args = "<orig.cache> <new.cache>"; ibdiag_process_opts(argc, argv, NULL, "CDdeGKLPstvy", opts, process_opt, usage_args, NULL); argc -= optind; argv += optind; orig_cache_file = argv[0]; new_cache_file = argv[1]; if (!orig_cache_file) IBERROR("original cache file not specified"); if (!new_cache_file) IBERROR("new cache file not specified"); if ((fabric = ibnd_load_fabric(orig_cache_file, 0)) == NULL) IBERROR("loading original cached fabric failed"); if (switchguid_flag) { guids.before = switchguid_before; guids.after = switchguid_after; guids.found = 0; ibnd_iter_nodes_type(fabric, replace_node_guid, IB_NODE_SWITCH, &guids); if (!guids.found) IBERROR("switchguid = %" PRIx64 " not found", switchguid_before); } if (caguid_flag) { guids.before = caguid_before; guids.after = caguid_after; guids.found = 0; ibnd_iter_nodes_type(fabric, replace_node_guid, IB_NODE_CA, &guids); if (!guids.found) IBERROR("caguid = %" PRIx64 " not found", caguid_before); } if (sysimgguid_flag) { guids.before = sysimgguid_before; guids.after = sysimgguid_after; guids.found = 0; ibnd_iter_nodes(fabric, replace_sysimgguid, &guids); if (!guids.found) IBERROR("sysimgguid = %" PRIx64 " not found", sysimgguid_before); } if (portguid_flag) { guids.searchguid = portguid_nodeguid; guids.searchguid_found = 0; guids.before = portguid_before; guids.after = portguid_after; guids.found = 0; ibnd_iter_nodes(fabric, replace_portguid, &guids); if (!guids.searchguid_found) IBERROR("nodeguid = %" PRIx64 " not found", portguid_nodeguid); if (!guids.found) IBERROR("portguid = %" PRIx64 " not found", portguid_before); } if (ibnd_cache_fabric(fabric, new_cache_file, 0) < 0) IBERROR("caching new cache data failed"); ibnd_destroy_fabric(fabric); exit(0); }
int main(int argc, char **argv) { struct ibnd_config config = { 0 }; ibnd_fabric_t *fabric = NULL; ibnd_fabric_t *diff_fabric = NULL; const struct ibdiag_opt opts[] = { {"full", 'f', 0, NULL, "show full information (ports' speed and width)"}, {"show", 's', 0, NULL, "show more information"}, {"list", 'l', 0, NULL, "list of connected nodes"}, {"grouping", 'g', 0, NULL, "show grouping"}, {"Hca_list", 'H', 0, NULL, "list of connected CAs"}, {"Switch_list", 'S', 0, NULL, "list of connected switches"}, {"Router_list", 'R', 0, NULL, "list of connected routers"}, {"node-name-map", 1, 1, "<file>", "node name map file"}, {"cache", 2, 1, "<file>", "filename to cache ibnetdiscover data to"}, {"load-cache", 3, 1, "<file>", "filename of ibnetdiscover cache to load"}, {"diff", 4, 1, "<file>", "filename of ibnetdiscover cache to diff"}, {"diffcheck", 5, 1, "<key(s)>", "specify checks to execute for --diff"}, {"ports", 'p', 0, NULL, "obtain a ports report"}, {"max_hops", 'm', 0, NULL, "report max hops discovered by the library"}, {"outstanding_smps", 'o', 1, NULL, "specify the number of outstanding SMP's which should be " "issued during the scan"}, {0} }; char usage_args[] = "[topology-file]"; ibdiag_process_opts(argc, argv, &config, "DGKLs", opts, process_opt, usage_args, NULL); f = stdout; argc -= optind; argv += optind; if (ibd_timeout) config.timeout_ms = ibd_timeout; config.flags = ibd_ibnetdisc_flags; if (argc && !(f = fopen(argv[0], "w"))) IBERROR("can't open file %s for writing", argv[0]); config.mkey = ibd_mkey; node_name_map = open_node_name_map(node_name_map_file); if (diff_cache_file && !(diff_fabric = ibnd_load_fabric(diff_cache_file, 0))) IBERROR("loading cached fabric for diff failed\n"); if (load_cache_file) { if ((fabric = ibnd_load_fabric(load_cache_file, 0)) == NULL) IBERROR("loading cached fabric failed\n"); } else { if ((fabric = ibnd_discover_fabric(ibd_ca, ibd_ca_port, NULL, &config)) == NULL) IBERROR("discover failed\n"); } if (ports_report) ibnd_iter_nodes(fabric, dump_ports_report, NULL); else if (list) list_nodes(fabric, list); else if (diff_fabric) diff(diff_fabric, fabric); else dump_topology(group, fabric); if (cache_file) if (ibnd_cache_fabric(fabric, cache_file, 0) < 0) IBERROR("caching ibnetdiscover data failed\n"); ibnd_destroy_fabric(fabric); if (diff_fabric) ibnd_destroy_fabric(diff_fabric); close_node_name_map(node_name_map); exit(0); }
int main(int argc, char **argv) { int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS}; ib_portid_t portid = {0}; ib_portid_t *sm_id = 0, sm_portid = {0}; extern int ibdebug; int timeout = 0, udebug = 0; char *ca = 0; int ca_port = 0; char *err; op_fn_t *fn; static char const str_opts[] = "C:P:t:s:devDcGVhu"; static const struct option long_opts[] = { { "C", 1, 0, 'C'}, { "P", 1, 0, 'P'}, { "debug", 0, 0, 'd'}, { "err_show", 0, 0, 'e'}, { "verbose", 0, 0, 'v'}, { "Direct", 0, 0, 'D'}, { "combined", 0, 0, 'c'}, { "Guid", 0, 0, 'G'}, { "smlid", 1, 0, 's'}, { "timeout", 1, 0, 't'}, { "node-name-map", 1, 0, 1}, { "Version", 0, 0, 'V'}, { "help", 0, 0, 'h'}, { "usage", 0, 0, 'u'}, { } }; argv0 = argv[0]; while (1) { int ch = getopt_long(argc, argv, str_opts, long_opts, NULL); if ( ch == -1 ) break; switch(ch) { case 1: node_name_map_file = strdup(optarg); break; case 'd': ibdebug++; madrpc_show_errors(1); umad_debug(udebug); udebug++; break; case 'e': madrpc_show_errors(1); break; case 'D': dest_type = IB_DEST_DRPATH; break; case 'c': dest_type = IB_DEST_DRSLID; break; case 'G': dest_type = IB_DEST_GUID; break; case 'C': ca = optarg; break; case 'P': ca_port = strtoul(optarg, 0, 0); break; case 's': if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0) IBERROR("can't resolve SM destination port %s", optarg); sm_id = &sm_portid; break; case 't': timeout = strtoul(optarg, 0, 0); madrpc_set_timeout(timeout); break; case 'v': verbose++; break; case 'V': fprintf(stderr, "%s %s\n", argv0, get_build_version() ); exit(-1); default: usage(); break; } } argc -= optind; argv += optind; if (argc < 2) usage(); if (!(fn = match_op(argv[0]))) IBERROR("operation '%s' not supported", argv[0]); madrpc_init(ca, ca_port, mgmt_classes, 3); node_name_map = open_node_name_map(node_name_map_file); if (dest_type != IB_DEST_DRSLID) { if (ib_resolve_portid_str(&portid, argv[1], dest_type, sm_id) < 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); } else { char concat[64]; memset(concat, 0, 64); snprintf(concat, sizeof(concat), "%s %s", argv[1], argv[2]); if (ib_resolve_portid_str(&portid, concat, dest_type, sm_id) < 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); exit(0); }
int main(int argc, char **argv) { int mgmt_classes[4] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS, IB_MLX_VENDOR_CLASS}; ib_portid_t *sm_id = 0, sm_portid = {0}; ib_portid_t portid = {0}; extern int ibdebug; int dest_type = IB_DEST_LID; int timeout = 0; /* use default */ int port = 0; char buf[1024]; int udebug = 0; char *ca = 0; int ca_port = 0; ib_vendor_call_t call; is3_general_info_t *gi; is3_config_space_t *cs; int general_info = 0; int xmit_wait = 0; int i; static char const str_opts[] = "C:P:s:t:dNwGVhu"; static const struct option long_opts[] = { { "C", 1, 0, 'C'}, { "P", 1, 0, 'P'}, { "N", 1, 0, 'N'}, { "w", 1, 0, 'w'}, { "debug", 0, 0, 'd'}, { "Guid", 0, 0, 'G'}, { "sm_portid", 1, 0, 's'}, { "timeout", 1, 0, 't'}, { "Version", 0, 0, 'V'}, { "help", 0, 0, 'h'}, { "usage", 0, 0, 'u'}, { } }; argv0 = argv[0]; while (1) { int ch = getopt_long(argc, argv, str_opts, long_opts, NULL); if ( ch == -1 ) break; switch(ch) { case 'C': ca = optarg; break; case 'P': ca_port = strtoul(optarg, 0, 0); break; case 'N': general_info = 1; break; case 'w': xmit_wait = 1; break; case 'd': ibdebug++; madrpc_show_errors(1); umad_debug(udebug); udebug++; break; case 'G': dest_type = IB_DEST_GUID; break; case 's': if (ib_resolve_portid_str(&sm_portid, optarg, IB_DEST_LID, 0) < 0) IBERROR("can't resolve SM destination port %s", optarg); sm_id = &sm_portid; break; case 't': timeout = strtoul(optarg, 0, 0); madrpc_set_timeout(timeout); break; case 'V': fprintf(stderr, "%s %s\n", argv0, get_build_version() ); exit(-1); default: usage(); break; } } argc -= optind; argv += optind; if (argc > 1) port = strtoul(argv[1], 0, 0); madrpc_init(ca, ca_port, mgmt_classes, 4); if (argc) { if (ib_resolve_portid_str(&portid, argv[0], dest_type, sm_id) < 0) IBERROR("can't resolve destination port %s", argv[0]); } else { if (ib_resolve_self(&portid, &port, 0) < 0) IBERROR("can't resolve self port %s", argv[0]); } /* Only General Info and Port Xmit Wait Counters */ /* queries are currently supported */ if (!general_info && !xmit_wait) IBERROR("at least one of -N and -w must be specified"); /* These are Mellanox specific vendor MADs */ /* but vendors change the VendorId so how know for sure ? */ /* Would need a list of these and it might not be complete */ /* so for right now, punt on this */ memset(&call, 0, sizeof(call)); call.mgmt_class = IB_MLX_VENDOR_CLASS; call.method = IB_MAD_METHOD_GET; call.timeout = timeout; 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)) IBERROR("classportinfo query"); memset(&buf, 0, sizeof(buf)); call.attrid = IB_MLX_IS3_GENERAL_INFO; if (!ib_vendor_call(&buf, &portid, &call)) IBERROR("vendstat"); gi = (is3_general_info_t *)&buf; if (general_info) { /* dump IS3 general info here */ printf("hw_dev_rev: 0x%04x\n", ntohs(gi->hw_info.hw_revision)); printf("hw_dev_id: 0x%04x\n", ntohs(gi->hw_info.device_id)); printf("hw_uptime: 0x%08x\n", ntohl(gi->hw_info.uptime)); printf("fw_version: %02d.%02d.%02d\n", gi->fw_info.major, gi->fw_info.minor, gi->fw_info.sub_minor); printf("fw_build_id: 0x%04x\n", ntohl(gi->fw_info.build_id)); printf("fw_date: %02d/%02d/%04x\n", gi->fw_info.month, gi->fw_info.day, ntohs(gi->fw_info.year)); printf("fw_psid: '%s'\n", gi->fw_info.psid); printf("fw_ini_ver: %d\n", ntohl(gi->fw_info.ini_file_version)); printf("sw_version: %02d.%02d.%02d\n", gi->sw_info.major, gi->sw_info.minor, gi->sw_info.sub_minor); } if (xmit_wait) { if (ntohs(gi->hw_info.device_id) != IS3_DEVICE_ID) IBERROR("Unsupported device ID 0x%x", ntohs(gi->hw_info.device_id)); memset(&buf, 0, sizeof(buf)); call.attrid = IB_MLX_IS3_CONFIG_SPACE_ACCESS; /* Limit of 18 accesses per MAD ? */ call.mod = 2 << 22 | 16 << 16; /* 16 records */ /* Set record addresses for each port */ 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)) IBERROR("vendstat"); for (i = 0; i < 16; i++) if (cs->record[i].data) /* PortXmitWait is 32 bit counter */ printf("Port %d: PortXmitWait 0x%x\n", i + 4, ntohl(cs->record[i].data)); /* port 4 is first port */ /* Last 8 ports is another query */ memset(&buf, 0, sizeof(buf)); call.attrid = IB_MLX_IS3_CONFIG_SPACE_ACCESS; call.mod = 2 << 22 | 8 << 16; /* 8 records */ /* Set record addresses for each port */ 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)) IBERROR("vendstat"); for (i = 0; i < 8; i++) if (cs->record[i].data) /* PortXmitWait is 32 bit counter */ printf("Port %d: PortXmitWait 0x%x\n", i < 4 ? i + 21 : i - 3, ntohl(cs->record[i].data)); } exit(0); }
int main(int argc, char **argv) { struct ibnd_config config = { 0 }; int resolved = -1; ib_portid_t portid = { 0 }; int rc = 0; ibnd_fabric_t *fabric = NULL; int mgmt_classes[4] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS, IB_PERFORMANCE_CLASS }; const struct ibdiag_opt opts[] = { {"suppress", 's', 1, "<err1,err2,...>", "suppress errors listed"}, {"suppress-common", 'c', 0, NULL, "suppress some of the common counters"}, {"node-name-map", 1, 1, "<file>", "node name map file"}, {"port-guid", 'G', 1, "<port_guid>", "report the node containing the port specified by <port_guid>"}, {"", 'S', 1, "<port_guid>", "Same as \"-G\" for backward compatibility"}, {"Direct", 'D', 1, "<dr_path>", "report the node containing the port specified by <dr_path>"}, {"report-port", 'r', 0, NULL, "report port link information"}, {"threshold-file", 8, 1, NULL, "specify an alternate threshold file, default: " DEF_THRES_FILE}, {"GNDN", 'R', 0, NULL, "(This option is obsolete and does nothing)"}, {"data", 2, 0, NULL, "include data counters for ports with errors"}, {"switch", 3, 0, NULL, "print data for switches only"}, {"ca", 4, 0, NULL, "print data for CA's only"}, {"router", 5, 0, NULL, "print data for routers only"}, {"details", 6, 0, NULL, "include transmit discard details"}, {"counters", 9, 0, NULL, "print data counters only"}, {"clear-errors", 'k', 0, NULL, "Clear error counters after read"}, {"clear-counts", 'K', 0, NULL, "Clear data counters after read"}, {"load-cache", 7, 1, "<file>", "filename of ibnetdiscover cache to load"}, {"outstanding_smps", 'o', 1, NULL, "specify the number of outstanding SMP's which should be " "issued during the scan"}, {0} }; char usage_args[] = ""; memset(suppressed_fields, 0, sizeof suppressed_fields); ibdiag_process_opts(argc, argv, &config, "cDGKLnRrSs", opts, process_opt, usage_args, NULL); argc -= optind; argv += optind; if (!node_type_to_print) node_type_to_print = PRINT_ALL; ibmad_port = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 4); if (!ibmad_port) IBERROR("Failed to open port; %s:%d\n", ibd_ca, ibd_ca_port); smp_mkey_set(ibmad_port, ibd_mkey); if (ibd_timeout) { mad_rpc_set_timeout(ibmad_port, ibd_timeout); config.timeout_ms = ibd_timeout; } config.flags = ibd_ibnetdisc_flags; config.mkey = ibd_mkey; node_name_map = open_node_name_map(node_name_map_file); if (dr_path && load_cache_file) { fprintf(stderr, "Cannot specify cache and direct route path\n"); exit(-1); } /* limit the scan the fabric around the target */ if (dr_path) { if ((resolved = resolve_portid_str(ibd_ca, ibd_ca_port, &portid, dr_path, IB_DEST_DRPATH, NULL, ibmad_port)) < 0) IBWARN("Failed to resolve %s; attempting full scan", dr_path); } else if (port_guid_str) { if ((resolved = resolve_portid_str(ibd_ca, ibd_ca_port, &portid, port_guid_str, IB_DEST_GUID, ibd_sm_id, ibmad_port)) < 0) IBWARN("Failed to resolve %s; attempting full scan", port_guid_str); } if (load_cache_file) { if ((fabric = ibnd_load_fabric(load_cache_file, 0)) == NULL) { fprintf(stderr, "loading cached fabric failed\n"); exit(-1); } } else { if (resolved >= 0) { if (!config.max_hops) config.max_hops = 1; if (!(fabric = ibnd_discover_fabric(ibd_ca, ibd_ca_port, &portid, &config))) IBWARN("Single node discover failed;" " attempting full scan"); } if (!fabric && !(fabric = ibnd_discover_fabric(ibd_ca, ibd_ca_port, NULL, &config))) { fprintf(stderr, "discover failed\n"); rc = -1; goto close_port; } } set_thresholds(threshold_file); if (port_guid_str) { ibnd_port_t *port = ibnd_find_port_guid(fabric, port_guid); if (port) print_node(port->node, NULL); else fprintf(stderr, "Failed to find node: %s\n", port_guid_str); } else if (dr_path) { ibnd_port_t *port = ibnd_find_port_dr(fabric, dr_path); uint8_t ni[IB_SMP_DATA_SIZE] = { 0 }; if (!smp_query_via(ni, &portid, IB_ATTR_NODE_INFO, 0, ibd_timeout, ibmad_port)) { rc = -1; goto destroy_fabric; } mad_decode_field(ni, IB_NODE_PORT_GUID_F, &(port_guid)); port = ibnd_find_port_guid(fabric, port_guid); if (port) { print_node(port->node, NULL); } else fprintf(stderr, "Failed to find node: %s\n", dr_path); } else ibnd_iter_nodes(fabric, print_node, NULL); rc = print_summary(); if (rc) rc = 1; destroy_fabric: ibnd_destroy_fabric(fabric); close_port: mad_rpc_close_port(ibmad_port); close_node_name_map(node_name_map); exit(rc); }