static int recv_mlnx_ext_port_info(smp_engine_t * engine, ibnd_smp_t * smp, uint8_t * mad, void *cb_data) { ibnd_fabric_t *fabric = ((ibnd_scan_t *) engine->user_data)->fabric; ibnd_node_t *node = cb_data; ibnd_port_t *port; uint8_t *ext_port_info = mad + IB_SMP_DATA_OFFS; uint8_t port_num, local_port; port_num = (uint8_t) mad_get_field(mad, 0, IB_MAD_ATTRMOD_F); port = node->ports[port_num]; if (!port) { IBND_ERROR("Failed to find 0x%" PRIx64 " port %u\n", node->guid, port_num); return -1; } memcpy(port->ext_info, ext_port_info, sizeof(port->ext_info)); local_port = (uint8_t) mad_get_field(port->info, 0, IB_PORT_LOCAL_PORT_F); debug_port(&smp->path, port); if (port_num && mad_get_field(port->info, 0, IB_PORT_PHYS_STATE_F) == IB_PORT_PHYS_STATE_LINKUP && ((node->type == IB_NODE_SWITCH && port_num != local_port) || (node == fabric->from_node && port_num == fabric->from_portnum))) { int rc = 0; ib_portid_t path = smp->path; if (node->type != IB_NODE_SWITCH && node == fabric->from_node && path.drpath.cnt > 1) rc = retract_dpath(engine, &path); else { /* we can't proceed through an HCA with DR */ if (path.lid == 0 || node->type == IB_NODE_SWITCH) rc = extend_dpath(engine, &path, port_num); } if (rc > 0) { struct ni_cbdata * cbdata = malloc(sizeof(*cbdata)); cbdata->node = node; cbdata->port_num = port_num; query_node_info(engine, &path, cbdata); } } return 0; }
int main(int argc, char **argv) try { Args args(argc, argv, "PORT BAUD"); DebugPort debug_port(args); args.ExpectEnd(); ScopeGlobalAsioThread global_asio_thread; NullDataHandler handler; auto port = debug_port.Open(*asio_thread, handler); ConsoleOperationEnvironment env; if (!port->WaitConnected(env)) { fprintf(stderr, "Failed to connect the port\n"); return EXIT_FAILURE; } char buffer[4096]; while (true) { switch (port->WaitRead(env, std::chrono::minutes(1))) { case Port::WaitResult::READY: break; case Port::WaitResult::TIMEOUT: continue; case Port::WaitResult::FAILED: return EXIT_FAILURE; case Port::WaitResult::CANCELLED: return EXIT_SUCCESS; } int nbytes = port->Read(buffer, sizeof(buffer)); if (nbytes < 0) break; fwrite((const void *)buffer, 1, nbytes, stdout); } return EXIT_SUCCESS; } catch (const std::exception &exception) { PrintException(exception); return EXIT_FAILURE; }
int main(int argc, char **argv) try { Args args(argc, argv, "PORT BAUD [NAME=VALUE] [NAME] ..."); DebugPort debug_port(args); ScopeGlobalAsioThread global_asio_thread; NullDataHandler handler; auto port = debug_port.Open(*asio_thread, handler); ConsoleOperationEnvironment env; if (!port->WaitConnected(env)) { fprintf(stderr, "Failed to connect the port\n"); return EXIT_FAILURE; } VegaDevice device(*port); while (!args.IsEmpty()) { const char *p = args.GetNext(); char *q = strdup(p); char *v = strchr(q, '='); if (v == NULL) { if (!device.RequestSetting(q, env)) printf("Error\n"); } else { *v++ = 0; if (!device.SendSetting(q, atoi(v), env)) printf("Error\n"); } free(q); } return EXIT_SUCCESS; } catch (const std::exception &exception) { PrintException(exception); return EXIT_FAILURE; }
int main(int argc, char **argv) try { Args args(argc, argv, "DRIVER PORT BAUD"); tstring _driver_name = args.ExpectNextT(); const TCHAR *driver_name = _driver_name.c_str(); DebugPort debug_port(args); args.ExpectEnd(); ScopeGlobalAsioThread global_asio_thread; auto port = debug_port.Open(*asio_thread, *(DataHandler *)nullptr); const struct DeviceRegister *driver = FindDriverByName(driver_name); if (driver == NULL) { _ftprintf(stderr, _T("No such driver: %s\n"), driver_name); return EXIT_FAILURE; } ConsoleOperationEnvironment env; if (!port->WaitConnected(env)) { fprintf(stderr, "Failed to connect the port\n"); return EXIT_FAILURE; } assert(driver->CreateOnPort != NULL); Device *device = driver->CreateOnPort(debug_port.GetConfig(), *port); assert(device != NULL); device->EnableNMEA(env); delete device; return EXIT_SUCCESS; } catch (const std::exception &exception) { PrintException(exception); return EXIT_FAILURE; }
int main(int argc, char **argv) try { const char *const usage = "PORT BAUD COMMAND\n\n" "Where COMMAND is one of:" "\n\tinfo" "\n\treboot" "\n\tpoweroff" "\n\tstartlogger" "\n\tstoplogger" "\n\tpilots" "\n\tnavpoints" ; Args args(argc, argv, usage); DebugPort debug_port(args); const char *command = args.ExpectNext(); args.ExpectEnd(); ScopeGlobalAsioThread global_asio_thread; auto port = debug_port.Open(*asio_thread, *(DataHandler *)nullptr); ConsoleOperationEnvironment env; if (!port->WaitConnected(env)) { fprintf(stderr, "Failed to connect the port\n"); return EXIT_FAILURE; } CAI302Device device(debug_port.GetConfig(), *port); if (!RunCommand(device, command, env)) { fprintf(stderr, "error\n"); return EXIT_FAILURE; } return EXIT_SUCCESS; } catch (const std::exception &exception) { PrintException(exception); return EXIT_FAILURE; }
static int recv_port_info(smp_engine_t * engine, ibnd_smp_t * smp, uint8_t * mad, void *cb_data) { ibnd_scan_t *scan = (ibnd_scan_t *)engine->user_data; ibnd_fabric_t *fabric = scan->fabric; ibnd_node_t *node = cb_data; ibnd_port_t *port; uint8_t *port_info = mad + IB_SMP_DATA_OFFS; uint8_t port_num, local_port; int phystate, ispeed, espeed; uint8_t *info; uint32_t cap_mask; port_num = (uint8_t) mad_get_field(mad, 0, IB_MAD_ATTRMOD_F); local_port = (uint8_t) mad_get_field(port_info, 0, IB_PORT_LOCAL_PORT_F); /* this may have been created before */ port = node->ports[port_num]; if (!port) { port = node->ports[port_num] = calloc(1, sizeof(*port)); if (!port) { IBND_ERROR("Failed to allocate 0x%" PRIx64 " port %u\n", node->guid, port_num); return -1; } port->guid = mad_get_field64(node->info, 0, IB_NODE_PORT_GUID_F); } memcpy(port->info, port_info, sizeof(port->info)); port->node = node; port->portnum = port_num; port->ext_portnum = 0; port->base_lid = (uint16_t) mad_get_field(port->info, 0, IB_PORT_LID_F); port->lmc = (uint8_t) mad_get_field(port->info, 0, IB_PORT_LMC_F); if (port_num == 0) { node->smalid = port->base_lid; node->smalmc = port->lmc; } else if (node->type == IB_NODE_SWITCH) { port->base_lid = node->smalid; port->lmc = node->smalmc; } add_to_portguid_hash(port, fabric->portstbl); if ((scan->cfg->flags & IBND_CONFIG_MLX_EPI) && is_mlnx_ext_port_info_supported(port)) { phystate = mad_get_field(port->info, 0, IB_PORT_PHYS_STATE_F); ispeed = mad_get_field(port->info, 0, IB_PORT_LINK_SPEED_ACTIVE_F); if (port->node->type == IB_NODE_SWITCH) info = (uint8_t *)&port->node->ports[0]->info; else info = (uint8_t *)&port->info; cap_mask = mad_get_field(info, 0, IB_PORT_CAPMASK_F); if (cap_mask & CL_NTOH32(IB_PORT_CAP_HAS_EXT_SPEEDS)) espeed = mad_get_field(port->info, 0, IB_PORT_LINK_SPEED_EXT_ACTIVE_F); else espeed = 0; if (phystate == IB_PORT_PHYS_STATE_LINKUP && ispeed == IB_LINK_SPEED_ACTIVE_10 && espeed == IB_LINK_SPEED_EXT_ACTIVE_NONE) { /* LinkUp/QDR */ query_mlnx_ext_port_info(engine, &smp->path, node, port_num); return 0; } } debug_port(&smp->path, port); if (port_num && mad_get_field(port->info, 0, IB_PORT_PHYS_STATE_F) == IB_PORT_PHYS_STATE_LINKUP && ((node->type == IB_NODE_SWITCH && port_num != local_port) || (node == fabric->from_node && port_num == fabric->from_portnum))) { int rc = 0; ib_portid_t path = smp->path; if (node->type != IB_NODE_SWITCH && node == fabric->from_node && path.drpath.cnt > 1) rc = retract_dpath(engine, &path); else { /* we can't proceed through an HCA with DR */ if (path.lid == 0 || node->type == IB_NODE_SWITCH) rc = extend_dpath(engine, &path, port_num); } if (rc > 0) { struct ni_cbdata * cbdata = malloc(sizeof(*cbdata)); cbdata->node = node; cbdata->port_num = port_num; query_node_info(engine, &path, cbdata); } } return 0; }