예제 #1
0
파일: imemory.c 프로젝트: nirmoy/opa-ff
// GID of form hValue:lValue
// values must be base 16, as such 0x prefix is optional for both hValue and
// lValue
// whitespace is permitted before and after :
FSTATUS StringToGid(uint64 *hValue, uint64 *lValue, const char* str, char **endptr, boolean skip_trail_whitespace)
{
	FSTATUS status;
	char *end;

	status = StringToUint64(hValue, str, &end, 16, TRUE);
	if (status != FSUCCESS)
		return status;
	if (end == NULL  || *end != ':')
		return FERROR;
	end++;
	return StringToUint64(lValue, end, endptr, 16, skip_trail_whitespace);
}
예제 #2
0
파일: cgroup.cpp 프로젝트: noxiouz/porto
TError TCgroup::GetUint64(const std::string &knob, uint64_t &value) const {
    std::string string;
    TError error = Get(knob, string);
    if (!error)
        error = StringToUint64(string, value);
    return error;
}
예제 #3
0
파일: cgroup.cpp 프로젝트: noxiouz/porto
// Cpuacct
TError TCpuacctSubsystem::Usage(TCgroup &cg, uint64_t &value) const {
    std::string s;
    TError error = cg.Get("cpuacct.usage", s);
    if (error)
        return error;
    return StringToUint64(s, value);
}
예제 #4
0
파일: imemory.c 프로젝트: nirmoy/opa-ff
FSTATUS StringToUint8(uint8 *value, const char* str, char **endptr, int base, boolean skip_trail_whitespace)
{
	uint64 temp;
	FSTATUS status;

	status = StringToUint64(&temp, str, endptr, base, skip_trail_whitespace);
	if (status != FSUCCESS)
		return status;
	if (temp > IB_UINT8_MAX)
		return FINVALID_SETTING;
	*value = (uint8)temp;
	return FSUCCESS;
}
예제 #5
0
파일: imemory.c 프로젝트: nirmoy/opa-ff
// Byte Count as an integer followed by an optional suffix of:
// K, KB, M, MB, G or GB
// (K==KB, etc)
// converted to an absolute number of bytes
FSTATUS StringToUint64Bytes(uint64 *value, const char* str, char **endptr, int base, boolean skip_trail_whitespace)
{
	char *end;
	FSTATUS status;
	uint64 temp;

	status = StringToUint64(&temp, str, &end, base, skip_trail_whitespace);
	if (status != FSUCCESS)
		return status;
	if (end) {
		char *units = end;
		// skip whitespace
		while (isspace(*units)) {
			units++;
		}
		// parse optional units
		if (strncmp(units, "KB",2) == 0) {
			temp *= 1024;
			end = units+2;
		} else if (strncmp(units, "K",1) == 0) {
			temp *= 1024;
			end = units+1;
		} else if (strncmp(units, "MB",2) == 0) {
			temp *= 1024*1024;
			end = units+2;
		} else if (strncmp(units, "M",1) == 0) {
			temp *= 1024*1024;
			end = units+1;
		} else if (strncmp(units, "GB",2) == 0) {
			temp *= (1024*1024*1024ULL);
			end = units+2;
		} else if (strncmp(units, "G",1) == 0) {
			temp *= (1024*1024*1024ULL);
			end = units+1;
		}
	}
	
	// skip whitespace
	if (end && skip_trail_whitespace) {
		while (isspace(*end)) {
			end++;
		}
	}
	if (endptr)
		*endptr = end;
	else if (end && *end != '\0')
		return FERROR;
	*value = temp;
	return FSUCCESS;
}
예제 #6
0
파일: cgroup.cpp 프로젝트: noxiouz/porto
TError TBlkioSubsystem::GetStatLine(const std::vector<std::string> &lines,
                                    const size_t i,
                                    const std::string &name,
                                    uint64_t &val) const {
    std::vector<std::string> tokens;
    TError error = SplitString(lines[i], ' ', tokens);
    if (error)
        return error;

    if (tokens.size() < 3 || tokens[1] != name)
        return TError(EError::Unknown, "Unexpected field in blkio statistics");

    return StringToUint64(tokens[2], val);
}
예제 #7
0
int main(int argc, char *argv[])
{
	char				*cmdName;
	const char			*opts="DvqSt:l:h:o:m:C:i:s:";
	char				parameter[100];
	char				strParameter[100];
	int32				integerParameter = 0;
	char				*p;
	EUI64				destPortGuid = -1;
	int					c;
	int					i;
	uint8				hfi = 1;
	uint8				port = -1;
	IB_PATH_RECORD		path;
	uint16				sessionID = 0;
	int32				metaIndex = -1;
	uint32				numPorts;
	uint32				linkWidth;
	uint32				linkSpeed;
	uint32				port1LinkWidth;
	uint32				fmEnabled;
	uint32				linkCRCMode;
	uint32				vCU;
	uint32				extLoopbackAllowed;
	VENDOR_MAD			mad;
	FSTATUS				status = FSUCCESS;
	uint8				nodeDescription[NODE_DESC_SIZE];
	struct              oib_port *oib_port_session = NULL;

	// determine how we've been invoked
	cmdName = strrchr(argv[0], '/');			// Find last '/' in path
	if (cmdName != NULL) {
		cmdName++;								// Skip over last '/'
	} else {
		cmdName = argv[0];
	}

	// Initialize

	strParameter[0] = '\0';


	// parse options and parameters
	while (-1 != (c = getopt(argc, argv, opts))) {
		switch (c) {
			case 'D':
				g_debugMode = 1;
				oib_set_dbg(stderr);
				break;

			case 't':
				errno = 0;
				strncpy(parameter, optarg, sizeof(parameter)-1);
				parameter[sizeof(parameter)-1] = 0;
				if ((p = strchr(parameter, ',')) != NULL) {
					*p = '\0';
				}
				if (FSUCCESS != StringToUint64(&destPortGuid, parameter, NULL, 0, TRUE)) {
					fprintf(stderr, "%s: Error: Invalid GUID: %s\n", cmdName, optarg);
					usage(cmdName);
				}
				break;

			case 'l':
#if !LIST_FILE_SUPPORTED
				fprintf(stderr, "Error: l option is not supported at this time\n");
				exit(1);
#endif
				break;

			case 'v':
				oib_set_dbg(stderr);
				g_verbose = 1;
				break;

			case 'q':
				g_quiet = 1;
				break;

			case 'h':
				if (FSUCCESS != StringToUint8(&hfi, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "%s: Error: Invalid HFI Number: %s\n", cmdName, optarg);
					usage(cmdName);
				}
				g_gotHfi = 1;
				break;

			case 'o':
				if (FSUCCESS != StringToUint8(&port, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "%s: Error: Invalid Port Number: %s\n", cmdName, optarg);
					usage(cmdName);
				}
				g_gotPort = 1;
				break;

			case 'C':
				if (!g_configNum) {
					if (FSUCCESS != StringToUint8(&g_configNum, optarg, NULL, 0, TRUE)) {
						fprintf(stderr, "%s: Error: Invalid Config-option Number: %s\n", cmdName, optarg);
						usage(cmdName);
					}
				} else {
					fprintf(stderr, "%s: Error: Only one instance of -C allowed\n\n", cmdName);
					usage(cmdName);
				}
				break;

			case 's':
				g_gotStrParam = 1;
				strcpy(strParameter, optarg);
				break;

			case 'i':
				g_gotIntParam = 1;
				if (FSUCCESS != StringToInt32(&integerParameter, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "%s: Error: Invalid integer parameter: %s\n", cmdName, optarg);
					usage(cmdName);
				}
				break;

			case 'S':
				g_gotSave = 1;
				break;

			default:
				usage(cmdName);
				break;

		}
	}

	// user has requested display of help
	if (argc == 1) {
		usage(cmdName);
		exit(0);
	}

	if (-1 == destPortGuid) {
		fprintf(stderr, "%s: Error: Must specify a target GUID\n", cmdName);
		exit(1);
	}

	if (g_configNum == 0) {
		fprintf(stderr, "%s: Error: must enter a configuration option number\n", cmdName);
		exit(1);
	}

	if (g_quiet && (g_debugMode || g_verbose)) {
		fprintf(stderr, "%s: Error: Can not specify both -q and -D|-v\n", cmdName);
		exit(1);
	}

	if (!port) {
		fprintf(stderr, "%s: Error: Invalid port number, First Port is 1\n", cmdName);
		exit(1);
	}
	if (port == (uint8)-1)
		port = 0;			// first active port

	// Get the LID

	status = oib_open_port_by_num(&oib_port_session, hfi, port);
	if (status != FSUCCESS) {
		fprintf(stderr, "%s: Error: Unable to open fabric interface.\n", cmdName);
		exit(1);
	}

	if (getDestPath(oib_port_session, destPortGuid, cmdName, &path) != FSUCCESS) {
		fprintf(stderr, "%s: Error finding destination path\n", cmdName);
		status = FERROR;
		goto err_exit;
	}

	// Send a ClassPortInfo to see if the switch is responding

	status = sendClassPortInfoMad(oib_port_session, &path, &mad);
	if (status != FSUCCESS) {
		fprintf(stderr, "%s: Error: Failed to send/rcv ClassPortInfo\n", cmdName);
		goto err_exit;
	}

	// Get a session ID

	sessionID = getSessionID(oib_port_session, &path);
	if (sessionID == (uint16)-1) {
		fprintf(stderr, "%s: Error: Failed to obtain sessionID\n", cmdName);
		status = FERROR;
		goto err_exit;
	}

	// Perform the config option

	switch (g_configNum) {
		case 1:
			if (!g_gotStrParam) {
				fprintf(stderr, "%s: Error: must enter a string parameter (-s) with configuration option 1\n", cmdName);
				status = FERROR;
			} else if (strlen(strParameter) > 63) {
				fprintf(stderr, "%s: Error: Invalid node description: %s\n", cmdName, strParameter);
				status = FERROR;
			} else {
				metaIndex = getMetaDataIndexByField(systemMetaData, systemMetaDataSize, "NODE_STRING");
			}
			if (metaIndex < 0) {
				fprintf(stderr, "%s: Error: can not find NODE_STRING in metaData table\n", cmdName);
				status = FERROR;
			}
			if (status == FSUCCESS) {
				strncpy((char*)nodeDescription, strParameter, NODE_DESC_SIZE);
				nodeDescription[NODE_DESC_SIZE-1]=0;
				status = sendSysTableAccessSetMad(oib_port_session, &path, &mad, sessionID, (uint8)metaIndex, 
												  (uint8)NODE_DESC_SIZE, nodeDescription);
				if (status != FSUCCESS) {
					fprintf(stderr, "%s: Error: Failed to send/rcv SysTableAccessSet MAD\n", cmdName);
					status = FERROR;
				}
			}
			break;

		case 2:
			fprintf(stderr, "%s: Error: vendor key no longer supported\n", cmdName);
			status = FERROR;
			break;

		case 3:
			fprintf(stderr, "%s: Error: MTU Capability no longer supported\n", cmdName);
			status = FERROR;
			break;

		case 4:
			fprintf(stderr, "%s: Error: VL Capability no longer supported\n", cmdName);
			status = FERROR;
			break;

		case 5:
			if (!g_gotIntParam) {
				fprintf(stderr, "%s: Error: must enter a integer parameter (-i) with configuration option 5\n", cmdName);
				status = FERROR;
			} else if ((integerParameter < 1) || (integerParameter > 15)) {
				fprintf(stderr, "%s: Error: bad integer value %d; must be 1-1X, 2-2X, 3-2X_1X, 4-3X, 5-3_1X, 6-3X_2X, 7-3X_2X_1X, 8-4X, 9-4X_1X, 10-4X_2X, 11-4X_2X_1X, 12-4X_3X, 13-4X_3X_1X, 14-4X_3X_2X, 15-4X_3X_2X_1X\n", cmdName, integerParameter);
				status = FERROR;
			} else {
				metaIndex = getMetaDataIndexByField(&portMetaData[0], portMetaDataSize, "LINK_WIDTH_SUPPORTED");
				if (metaIndex < 0) {
					fprintf(stderr, "%s: Error: can not find LINK WIDTH SUPPORTED in metaData table\n", cmdName);
					status = FERROR;
				}
			}
			if (status == FSUCCESS) {
				numPorts = getNumPorts(oib_port_session, &path, sessionID);
				linkWidth = integerParameter;
				// make sure that port1 always has 4x enabled
				port1LinkWidth = linkWidth | 0x8;

				linkWidth = ntoh32(linkWidth);
				port1LinkWidth = ntoh32(port1LinkWidth);

				// first set port 1
				status = sendPortTableAccessSetMad(oib_port_session, &path, &mad, sessionID, 
												   (uint8)metaIndex, 1, 4, (uint8 *)&port1LinkWidth);
				if (status != FSUCCESS) {
					fprintf(stderr, "%s: Error: Failed to send/rcv PortTableAccessSet MAD for port %d\n", cmdName, 1);
					status = FERROR;
				}

				// now set ports 2 through numPorts
				for (i = 2; i <= numPorts; i++) {
					status = sendPortTableAccessSetMad(oib_port_session, &path, &mad, sessionID, 
													   (uint8)metaIndex, i, 4, (uint8 *)&linkWidth);
					if (status != FSUCCESS) {
						fprintf(stderr, "%s: Error: Failed to send/rcv PortTableAccessSet MAD for port %d\n", cmdName, i);
						status = FERROR;
					}
				}
			}
			break;

		case 7:
			if (!g_gotIntParam) {
				fprintf(stderr, "%s: Error: must enter a integer parameter (-i) with configuration option 7\n", cmdName);
				status = FERROR;
			} else if ((integerParameter < 1) || (integerParameter > 3)) {
				fprintf(stderr, "%s: Error: bad integer value %d; must be 1 for 12G, 2 for 25G, 3 for 12G/25G\n", cmdName, integerParameter);
				status = FERROR;
			} else {
				metaIndex = getMetaDataIndexByField(&portMetaData[0], portMetaDataSize, "LINK_SPEED_SUPPORTED");
				if (metaIndex < 0) {
					fprintf(stderr, "%s: Error: can not find LINK SPEED SUPPORTED in metaData table\n", cmdName);
					status = FERROR;
				}
			}
			if (status == FSUCCESS) {
				numPorts = getNumPorts(oib_port_session, &path, sessionID);
				linkSpeed = integerParameter;

				linkSpeed = ntoh32(linkSpeed);
				// set ports 1 through numPorts
				for (i = 1; i <= numPorts; i++) {
					status = sendPortTableAccessSetMad(oib_port_session, &path, &mad, sessionID, 
													   (uint8)metaIndex, i, 4, (uint8 *)&linkSpeed);
					if (status != FSUCCESS) {
						fprintf(stderr, "%s: Error: Failed to send/rcv PortTableAccessSet MAD for port %d\n", cmdName, i);
						status = FERROR;
					}
				}
			}
			break;
		case 8:
			if (!g_gotIntParam) {
				fprintf(stderr, "%s: Error: must enter an integer paramemter (-i) with configuration option 8\n", cmdName);
				status = FERROR;
			} else if ((integerParameter < 0) || (integerParameter > 1)) {
				fprintf(stderr, "%s: Error: bad integer value %d; must be 0 for disable or 1 for enable\n", cmdName, integerParameter);
				status = FERROR;
			} else {
				metaIndex = getMetaDataIndexByField(&portMetaData[0], portMetaDataSize, "FM_ENABLED");
				if (metaIndex < 0) {
					fprintf(stderr, "%s: Error: can not find FM ENABLED in metaData table\n", cmdName);
					status = FERROR;
				}
			}
			if (status == FSUCCESS) {
				numPorts = getNumPorts(oib_port_session, &path, sessionID);
				fmEnabled = integerParameter;

				fmEnabled = ntoh32(fmEnabled);
				// set ports 1 through numPorts
				for (i = 1; i <= numPorts; i++) {
					status = sendPortTableAccessSetMad(oib_port_session, &path, &mad, sessionID,
													   (uint8)metaIndex, i, 4, (uint8 *)&fmEnabled);
					if (status != FSUCCESS) {
						fprintf(stderr, "%s: Error: Failed to send/rcv PortTableAccessSet MAD for port %d\n", cmdName, i);
						status = FERROR;
					}
				}
			}
			break;
		case 9:	
			if (!g_gotIntParam) {
				fprintf(stderr, "%s: Error: must enter an integer paramemter (-i) with configuration option 9\n", cmdName);
				status = FERROR;
			} else if ((integerParameter < 0) || (integerParameter > 7)) {
				fprintf(stderr, "%s: Error: bad integer value %d; must be 0-16b, 1-14b/16b, 2-48b/16b, 3-48b/14b/16b, 4-per lane/16b, 5-per lane/14b/16b, 6-per lane/48b/16b, 7-per lane/48b/14b/16b\n", cmdName, integerParameter);
				status = FERROR;
			} else {
				metaIndex = getMetaDataIndexByField(&portMetaData[0], portMetaDataSize, "LTP_CRC_MODE_SUPPORTED");
				if (metaIndex < 0) {
					fprintf(stderr, "%s: Error: can not find CRC in metaData table\n", cmdName);
					status = FERROR;
				}
			}
			if (status == FSUCCESS) {
				numPorts = getNumPorts(oib_port_session, &path, sessionID);
				linkCRCMode = integerParameter;

				linkCRCMode = ntoh32(linkCRCMode);
				// set ports 1 through numPorts
				for (i = 1; i <= numPorts; i++) {
					status = sendPortTableAccessSetMad(oib_port_session, &path, &mad, sessionID,
													   (uint8)metaIndex, i, 4, (uint8 *)&linkCRCMode);
					if (status != FSUCCESS) {
						fprintf(stderr, "%s: Error: Failed to send/rcv PortTableAccessSet MAD for port %d\n", cmdName, i);
						status = FERROR;
					}
				}
			}
			break;
		case 10:
			if (!g_gotIntParam) {
				fprintf(stderr, "%s: Error: must enter an integer paramemter (-i) with configuration option 10\n", cmdName);
				status = FERROR;
			} else if (integerParameter < 0 || integerParameter > 7) { 
				fprintf(stderr, "%s: Error: bad integer value %d; Must be 0-7", cmdName, integerParameter);
				status = FERROR;
			} else {
				metaIndex = getMetaDataIndexByField(&portMetaData[0], portMetaDataSize, "VCU");
				if (metaIndex < 0) {
					fprintf(stderr, "%s: Error: can not find vCU in metaData table\n", cmdName);
					status = FERROR;
				}
			}
			if (status == FSUCCESS) {
				numPorts = getNumPorts(oib_port_session, &path, sessionID);
				vCU = integerParameter;

				vCU = ntoh32(vCU);
				// set ports 1 through numPorts
				for (i = 1; i <= numPorts; i++) {
					status = sendPortTableAccessSetMad(oib_port_session, &path, &mad, sessionID,
													   (uint8)metaIndex, i, 4, (uint8 *)&vCU);
					if (status != FSUCCESS) {
						fprintf(stderr, "%s: Error: Failed to send/rcv PortTableAccessSet MAD for port %d\n", cmdName, i);
						status = FERROR;
					}
				}
			}
			break;
		case 11:
			if (!g_gotIntParam) {
				fprintf(stderr, "%s: Error: must enter an integer paramemter (-i) with configuration option 11\n", cmdName);
				status = FERROR;
			} else if (integerParameter < 0 || integerParameter > 1) {
				fprintf(stderr, "%s: Error: bad integer value %d; must be 0 for disable or 1 for enable\n", cmdName, integerParameter);
				status = FERROR;
			} else {
				metaIndex = getMetaDataIndexByField(&portMetaData[0], portMetaDataSize, "EXTERNAL_LOOPBACK_ALLOWED");
				if (metaIndex < 0) {
					fprintf(stderr, "%s: Error: can not find EXTERNAL LOOPBACK ALLOWED in metaData table\n", cmdName);
					status = FERROR;
				}
			}
			if (status == FSUCCESS) {
				numPorts = getNumPorts(oib_port_session, &path, sessionID);
				extLoopbackAllowed = integerParameter;

				extLoopbackAllowed = ntoh32(extLoopbackAllowed);
				// set ports 1 through numPorts
				for (i = 1; i <= numPorts; i++) {
					status = sendPortTableAccessSetMad(oib_port_session, &path, &mad, sessionID,
													   (uint8)metaIndex, i, 4, (uint8 *)&extLoopbackAllowed);
					if (status != FSUCCESS) {
						fprintf(stderr, "%s: Error: Failed to send/rcv PortTableAccessSet MAD for port %d\n", cmdName, i);
						status = FERROR;
					}
				}
			}
			break;
		default:
			if (sessionID>0) releaseSession(oib_port_session, &path, sessionID);
			fprintf(stderr, "Error: Invalid configuration option number %d\n", g_configNum);
			usage(cmdName);
			break;
	}

	if (g_gotSave) {
		// save configuration to make change permanent
		status = sendSaveConfigMad(oib_port_session, &path, &mad, sessionID);
		if (status != FSUCCESS) {
			fprintf(stderr, "%s: Error: Failed to send/rcv SaveConfig MAD\n", cmdName);
			status = FERROR;
		}
	}

	if (sessionID>0) releaseSession(oib_port_session, &path, sessionID);

	printf("opaswconfigure completed\n");

err_exit:
	if (oib_port_session != NULL) {
		oib_close_port(oib_port_session);
	}

	if (status == FSUCCESS)
		exit(0);
	else
		exit(1);

}
예제 #8
0
파일: saquery.c 프로젝트: nirmoy/opa-ff
int main(int argc, char ** argv)
{
    int                 c;
    uint8               hfi         = 1;
    uint8               port        = 0;
	int					index;
	QUERY				query;
	OutputStringMap_t	*outputTypeMap = NULL;

	memset(&query, 0, sizeof(query));	// initialize reserved fields

	// default query for this application is for all node records
	query.InputType 	= InputTypeNoInput;
	query.OutputType 	= OutputTypeStlNodeRecord;

	// process command line arguments
	while (-1 != (c = getopt_long(argc,argv, "vIh:p:l:k:i:t:s:n:g:u:m:d:P:G:a:A:o:S:L:", options, &index)))
    {
        switch (c)
        {
            case '$':
                Usage_full();
                break;
            case 'v':
                g_verbose++;
				if (g_verbose>1) oib_set_dbg(stderr);
				if (g_verbose>2) umad_debug(g_verbose-2);
                break;
			case 'I':   // issue query in legacy InfiniBand format (IB)
				g_IB = 1;
				query.OutputType = OutputTypeNodeRecord;
				break;
            case 'h':	// hfi to issue query from
				if (FSUCCESS != StringToUint8(&hfi, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid HFI Number: %s\n", optarg);
					Usage();
				}
                break;
            case 'p':	// port to issue query from
				if (FSUCCESS != StringToUint8(&port, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid Port Number: %s\n", optarg);
					Usage();
				}
                break;

            case 'l':	// query by lid
				multiInputCheck(query.InputType);
				query.InputType = InputTypeLid;
				if (FSUCCESS != StringToUint16(&query.InputValue.Lid, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid LID: %s\n", optarg);
					Usage();
				}
                break;
            case 'k':	// query by pkey
				multiInputCheck(query.InputType);
				query.InputType = InputTypePKey;
				if (FSUCCESS != StringToUint16(&query.InputValue.PKey, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid PKey: %s\n", optarg);
					Usage();
				}
				break;
            case 'i':	// query by vfindex
				multiInputCheck(query.InputType);
				query.InputType = InputTypeIndex;
				if (FSUCCESS != StringToUint16(&query.InputValue.vfIndex, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid vfIndex: %s\n", optarg);
					Usage();
				}
				break;
            case 'S':	// query by serviceId
				multiInputCheck(query.InputType);
				query.InputType = InputTypeServiceId;
				if (FSUCCESS != StringToUint64(&query.InputValue.ServiceId, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid ServiceId: %s\n", optarg);
					Usage();
				}
				break;
            case 'L':	// query by service level
				multiInputCheck(query.InputType);
				query.InputType = InputTypeSL;
				if (FSUCCESS != StringToUint8(&query.InputValue.SL, optarg, NULL, 0, TRUE)
					|| query.InputValue.SL > 15) {
					fprintf(stderr, "opasaquery: Invalid SL: %s\n", optarg);
					Usage();
				}
                break;
            case 't':	// query by node type
				multiInputCheck(query.InputType);
				query.InputType = InputTypeNodeType;
				query.InputValue.TypeOfNode = checkNodeType(optarg);
                break;
            case 's':	// query by system image guid
				multiInputCheck(query.InputType);
				query.InputType = InputTypeSystemImageGuid;
				if (FSUCCESS != StringToUint64(&query.InputValue.Guid, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid GUID: %s\n", optarg);
					Usage();
				}
                break;
            case 'n':	// query by node guid
				multiInputCheck(query.InputType);
				query.InputType = InputTypeNodeGuid;
				if (FSUCCESS != StringToUint64(&query.InputValue.Guid, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid GUID: %s\n", optarg);
					Usage();
				}
                break;
            case 'g':	// query by port guid
				multiInputCheck(query.InputType);
				query.InputType = InputTypePortGuid;
				if (FSUCCESS != StringToUint64(&query.InputValue.Guid, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid GUID: %s\n", optarg);
					Usage();
				}
                break;
            case 'u':	// query by gid
				multiInputCheck(query.InputType);
				query.InputType = InputTypePortGid;
				if (FSUCCESS != StringToGid(&query.InputValue.Gid.AsReg64s.H,&query.InputValue.Gid.AsReg64s.L, optarg, NULL, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid GID: %s\n", optarg);
					Usage();
				}
                break;
            case 'm':	// query by multicast gid
				multiInputCheck(query.InputType);
				query.InputType = InputTypeMcGid;
				if (FSUCCESS != StringToGid(&query.InputValue.Gid.AsReg64s.H,&query.InputValue.Gid.AsReg64s.L, optarg, NULL, TRUE)) {
					fprintf(stderr, "opasaquery: Invalid GID: %s\n", optarg);
					Usage();
				}
                break;
            case 'd':	// query by node description
				multiInputCheck(query.InputType);
				query.InputType = InputTypeNodeDesc;
				query.InputValue.NodeDesc.NameLength = MIN(strlen(optarg), NODE_DESCRIPTION_ARRAY_SIZE);
				strncpy((char*)query.InputValue.NodeDesc.Name, optarg, NODE_DESCRIPTION_ARRAY_SIZE);
                break;
			case 'P':	// query by source:dest port guids
				{
					char *p;
					multiInputCheck(query.InputType);
					query.InputType = InputTypePortGuidPair;
					if (FSUCCESS != StringToUint64(&query.InputValue.PortGuidPair.SourcePortGuid, optarg, &p, 0, TRUE)
						|| ! p || *p == '\0') {
						fprintf(stderr, "opasaquery: Invalid GUID Pair: %s\n", optarg);
						Usage();
					}
					if (FSUCCESS != StringToUint64(&query.InputValue.PortGuidPair.DestPortGuid, p, NULL, 0, TRUE)) {
						fprintf(stderr, "opasaquery: Invalid GUID Pair: %s\n", optarg);
						Usage();
					}
				}
                break;
			case 'G':	// query by source:dest port gids
				{
					char *p;
					multiInputCheck(query.InputType);
					query.InputType = InputTypeGidPair;
					if (FSUCCESS != StringToGid(&query.InputValue.GidPair.SourceGid.AsReg64s.H,&query.InputValue.GidPair.SourceGid.AsReg64s.L, optarg, &p, TRUE)
						|| ! p || *p == '\0') {
						fprintf(stderr, "opasaquery: Invalid GID Pair: %s\n", optarg);
						Usage();
					}
					if (FSUCCESS != StringToGid(&query.InputValue.GidPair.DestGid.AsReg64s.H,&query.InputValue.GidPair.DestGid.AsReg64s.L, p, NULL, TRUE)) {
						fprintf(stderr, "opasaquery: Invalid GID Pair: %s\n", optarg);
						Usage();
					}
				}
				break;
			case 'a':	// multipath query by src1:src2:...;dest1:dest2:... port guids
				{
					char *p =optarg;
					int i = 0;
					errno = 0;
					multiInputCheck(query.InputType);
					query.InputType = InputTypePortGuidList;
					do {
						if (FSUCCESS != StringToUint64(&query.InputValue.PortGuidList.GuidList[i], p, &p, 0, TRUE)) {
							fprintf(stderr, "opasaquery: Invalid GUID List: %s\n", optarg);
							Usage();
						}
						i++;
						query.InputValue.PortGuidList.SourceGuidCount++;
					} while (p && *p != '\0' && *p != ';');
					if (p && *p != '\0')
					{
						p++; // skip the semi-colon.
						do {
							if (FSUCCESS != StringToUint64(&query.InputValue.PortGuidList.GuidList[i], p, &p, 0, TRUE)) {
								fprintf(stderr, "opasaquery: Invalid GUID List: %s\n", optarg);
								Usage();
							}
							i++;
							query.InputValue.PortGuidList.DestGuidCount++;
						} while (p && *p != '\0');
					} else {
						Usage();
					}
				}
                break;
			case 'A':	// multipath query by src1:src2:...;dest1:dest2:... gids
				{
					char *p=optarg;
					int i = 0;
					errno = 0;
					multiInputCheck(query.InputType);
					query.InputType = InputTypeGidList;
					do {
						if (FSUCCESS != StringToGid(&query.InputValue.GidList.GidList[i].AsReg64s.H,&query.InputValue.GidList.GidList[i].AsReg64s.L, p, &p, TRUE)) {
							fprintf(stderr, "opasaquery: Invalid GID List: %s\n", optarg);
							Usage();
						}
						i++;
						query.InputValue.GidList.SourceGidCount++;
					} while (p && *p != '\0' && *p != ';');
					if (p && *p != '\0')
					{
						p++; // skip the semi-colon
						do {
							if (FSUCCESS != StringToGid(&query.InputValue.GidList.GidList[i].AsReg64s.H,&query.InputValue.GidList.GidList[i].AsReg64s.L, p, &p, TRUE)) {
								fprintf(stderr, "opasaquery: Invalid GID List: %s\n", optarg);
								Usage();
							}
							i++;
							query.InputValue.GidList.DestGidCount++;
						} while (p && *p != '\0');
					} else {
						Usage();
					}
				}
                break;

            case 'o':	// select output record desired
				outputTypeMap = GetOutputTypeMap(optarg);
                break;
            default:
                fprintf(stderr, "opasaquery: Invalid option -%c\n", c);
                Usage();
                break;
        }
    } /* end while */

	if (optind < argc)
	{
		Usage();
	}

	if (NULL != outputTypeMap)
		query.OutputType = GetOutputType(outputTypeMap); 

	PrintDestInitFile(&g_dest, stdout);
	if (g_verbose)
		PrintDestInitFile(&g_dbgDest, stdout);
	else
		PrintDestInitNone(&g_dbgDest);

	if(oib_open_port_by_num(&sa_oib_session,hfi,port) != 0)
	{
		fprintf(stderr, "opasaquery: Could not open oib session.\n");
		return FERROR;
	}

	// perform the query and display output
	do_query(sa_oib_session, &query);

	oib_close_port(sa_oib_session);

	if (g_exitstatus == 2)
		Usage();

	return g_exitstatus;
}
예제 #9
0
파일: opaswquery.c 프로젝트: 01org/opa-ff
int main(int argc, char *argv[])
{
	char				*cmdName;
	const char			*opts="Dvqt:l:h:o:m:Q:i:";
	char				parameter[100];
	char				*p;
	EUI64				destPortGuid = -1;
	int					c;
	int					i;
	uint8				hfi = 0;
	uint8				port = 0;
	IB_PATH_RECORD		path;
	uint16				sessionID;
	uint32				regValue;
	uint32				fanSpeed[OPASW_PSOC_FAN_CTRL_TACHS];
	char				tempStrs[I2C_OPASW_TEMP_SENSOR_COUNT][TEMP_STR_LENGTH];
	uint32				psStatus;
	uint8				fwVersion[40];
	vpd_fruInfo_rec_t	vpdInfo;
	char				mfgID[10];
	char				mfgDate[20];
	char				mfgTime[10];
	uint8				nodeDesc[80];
	opasw_ini_descriptor_get_t tableDescriptors;
	table_parsed_data_t	*portParsedDataTable=NULL;
	uint32				numPorts;
	uint32				portEntrySize;
	uint8				memoryData[200];
	uint8				boardID;
	VENDOR_MAD			mad;
	FSTATUS				status = FSUCCESS;
	uint32				asicVersion;
	uint8				chipStep;
	uint8				chipRev;



	table_parsed_data_t	*portPtrs=NULL;
	uint32				portLinkWidthSupportedIndex;
	uint32				portLinkSpeedSupportedIndex;
	uint32				portFMEnabledIndex;
	uint32				portLinkCRCModeIndex;
	uint32				portvCUIndex;
	uint32				portExternalLoopbackAllowedIndex;
	char				portLinkCRCModeValue[35];
	char				portLinkWidthSupportedText[20];
	char				portLinkSpeedSupportedText[20];
	struct              oib_port *oib_port_session = NULL;

	// determine how we've been invoked
	cmdName = strrchr(argv[0], '/');			// Find last '/' in path
	if (cmdName != NULL) {
		cmdName++;								// Skip over last '/'
	} else {
		cmdName = argv[0];
	}

	// Initialize


	// parse options and parameters
	while (-1 != (c = getopt(argc, argv, opts))) {
		switch (c) {
			case 'D':
				g_debugMode = 1;
				oib_set_dbg(stderr);
				break;

			case 't':
				errno = 0;
				strncpy(parameter, optarg, sizeof(parameter)-1);
				parameter[sizeof(parameter)-1] = 0;
				if ((p = strchr(parameter, ',')) != NULL) {
					*p = '\0';
				}
				if (FSUCCESS != StringToUint64(&destPortGuid, parameter, NULL, 0, TRUE)) {
					fprintf(stderr, "%s: Error: Invalid GUID: %s\n", cmdName, optarg);
					usage(cmdName);
				}
				break;

			case 'l':
#if !LIST_FILE_SUPPORTED
				fprintf(stderr, "Error: l option is not supported at this time\n");
				exit(1);
#endif
				break;

			case 'v':
				oib_set_dbg(stderr);
				g_verbose = 1;
				break;

			case 'q':
				g_quiet = 1;
				break;

			case 'h':
				if (FSUCCESS != StringToUint8(&hfi, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "%s: Error: Invalid HFI Number: %s\n", cmdName, optarg);
					usage(cmdName);
				}
				g_gotHfi = 1;
				break;

			case 'o':
				if (FSUCCESS != StringToUint8(&port, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "%s: Error: Invalid Port Number: %s\n", cmdName, optarg);
					usage(cmdName);
				}
				g_gotPort = 1;
				break;

			case 'Q':
				if (FSUCCESS != StringToUint8(&g_queryNum, optarg, NULL, 0, TRUE)) {
					fprintf(stderr, "%s: Error: Invalid Query Number: %s\n", cmdName, optarg);
					usage(cmdName);
				}
				break;

			case 'i':
				if (FSUCCESS != StringToInt8(&g_intParam, optarg, NULL, 0, TRUE)
					|| g_intParam < 0) {
					fprintf(stderr, "%s: Error: Invalid integer parameter: %s\n", cmdName, optarg);
					usage(cmdName);
				}
				break;

			default:
				usage(cmdName);
				break;

		}
	}

	// user has requested display of help
	if (argc == 1) {
		usage(cmdName);
		exit(0);
	}

	if (-1 == destPortGuid) {
		fprintf(stderr, "%s: Error: Must specify a target GUID\n", cmdName);
		exit(1);
	}

	if (g_queryNum == 0) {
		fprintf(stderr, "%s: Error: must enter a query number\n", cmdName);
		exit(1);
	}

	if ((g_queryNum == 8) && ((g_intParam > MAX_PS) || (g_intParam < MIN_PS))) {
		fprintf(stderr, "%s: Error: Query number 8 - must use -i for valid Power Supply number %d - %d\n", cmdName, MIN_PS, MAX_PS);
		usage(cmdName);
	}

	if (g_quiet && (g_debugMode || g_verbose)) {
		fprintf(stderr, "%s: Error: Can not specify both -q and -D|-v\n", cmdName);
		exit(1);
	}

	// Get the path

	status = oib_open_port_by_num(&oib_port_session, hfi, port);
	if (status != 0) {
		fprintf(stderr, "%s: Error: Unable to open fabric interface.\n", cmdName);
		exit(1);
	}

	if (getDestPath(oib_port_session, destPortGuid, cmdName, &path) != FSUCCESS) {
		fprintf(stderr, "%s: Error: Failed to get destination path\n", cmdName);
		goto err_exit;
	}

	// Send a ClassPortInfo to see if the switch is responding

	status = sendClassPortInfoMad(oib_port_session, &path, &mad);
	if (status != FSUCCESS) {
		fprintf(stderr, "%s: Error: Failed to send/rcv ClassPortInfo\n", cmdName);
		goto err_exit;
	}

	// Get a session ID

	sessionID = getSessionID(oib_port_session, &path);
	if (sessionID == (uint16)-1) {
		fprintf(stderr, "%s: Error: Failed to obtain sessionID\n", cmdName);
		status = FERROR;
		goto err_exit;
	}

	// Send the test mad

	switch (g_queryNum) {
		case 1:
			fprintf(stderr, "Error: Module type query no longer supported.\n");
			status = FERROR;
			break;

		case 2:
			status = sendRegisterAccessMad(oib_port_session, &path, &mad, sessionID, 
										   (uint8)0x6f, &regValue, 1);
			if (status != FSUCCESS) {
				fprintf(stderr, "Error: Failed to access register - status %d\n", status);
				break;
			}
			printf("Switch has booted from %s firmware image\n", (regValue & EEPROM_MASK) ? "failsafe" : "primary");
			break;

		case 3:
			status = getFwVersion(oib_port_session, &path, &mad, sessionID, fwVersion);
			if (status != FSUCCESS) {
				fprintf(stderr, "Error: Failed to acquire fw version - status %d\n", status);
				break;
			}
			printf("FW Version is %s\n", fwVersion);
			break;

		case 4:
			status = getVPDInfo(oib_port_session, &path, &mad, sessionID, OPASW_MODULE, &vpdInfo);
			if (status != FSUCCESS) {
				fprintf(stderr, "Error: Failed to access vpd info - status %d\n", status);
				break;
			}
			snprintf(mfgID, sizeof(mfgID), "%02x%02x%02x", vpdInfo.mfgID[0] & 0xff, vpdInfo.mfgID[1] & 0xff, vpdInfo.mfgID[2] & 0xff);
			snprintf(mfgDate, sizeof(mfgDate), "%d-%02d-%d", vpdInfo.mfgMonth, vpdInfo.mfgDay, vpdInfo.mfgYear + 2000);
			snprintf(mfgTime, sizeof(mfgTime), "%02d:%02d", vpdInfo.mfgHours, vpdInfo.mfgMins);
			printf("VPD \"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"\n",
				vpdInfo.serialNum,
				vpdInfo.partNum,
				vpdInfo.model,
				vpdInfo.version,
				vpdInfo.mfgName,
				vpdInfo.productName,
				mfgID,
				mfgDate,
				mfgTime);
			break;

		case 5:
			status = getNodeDescription(oib_port_session, &path, sessionID, nodeDesc);
			if (status != FSUCCESS) {
				fprintf(stderr, "Error: Failed to acquire node description - status %d\n", status);
				break;
			}
			printf("Node description is %s\n", nodeDesc);
			break;
		case 6:
			status = getTempReadings(oib_port_session, &path, &mad, sessionID, tempStrs);

			for (i=0; i<I2C_OPASW_TEMP_SENSOR_COUNT; i++) {
				printf("SENSOR %d: %s ", i, tempStrs[i]);
			}
			printf("\n");
			if (status != FSUCCESS) {
				fprintf(stderr, "Error: Failed to get one or more temperature readings - status %s\n",
					iba_fstatus_msg(status & 0xFF));
			}
			break;
		case 7:
			for (i = 0; i < OPASW_PSOC_FAN_CTRL_TACHS; i++) {
				status = getFanSpeed(oib_port_session, &path, &mad, sessionID,
									 (uint32)i, &fanSpeed[i]);
				if (status != FSUCCESS) {
					fprintf(stderr, "Error: Failed to get fan speed for fan %d - status %d\n", i, status);
					break;
				}
				if (g_verbose) {
					printf("Fan speed is %d\n", fanSpeed[i]);
				}
				// TODO: stl1baseboard.c only reports the speed itself, not FAST/SLOW/NORMAL, so I can't confirm that this matches
				if (fanSpeed[i] > MAX_FAN_SPEED) 
					printf("FAN %d:FAST ", i);
				else if (fanSpeed[i] < MIN_FAN_SPEED)
					printf("FAN %d:SLOW ", i);
				else
					printf("FAN %d:NORMAL ", i);
			}
			printf("\n");
			break;

		case 8:
			status = getPowerSupplyStatus(oib_port_session, &path, &mad, sessionID, g_intParam, 
										  &psStatus);
			if (status != FSUCCESS) {
				fprintf(stderr, "Error: Failed to get power supply status for ps %d - status %d\n", g_intParam, status);
				break;
			}
			switch (psStatus) {
				case PS_ONLINE:
					printf("PS %d: ONLINE\n", g_intParam);
					break;
				case PS_OFFLINE:
					printf("PS %d: OFFLINE\n", g_intParam);
					break;
				case PS_NOT_PRESENT:
					printf("PS %d: NOT PRESENT\n", g_intParam);
					break;
				case PS_INVALID:
					printf("PS %d: INVALID\n", g_intParam);
					break;
				default:  
					fprintf(stderr, "Error: Failed to get power supply status for ps %d\n", g_intParam); 
					break;
			}
			break;

		case 9:
			status = getAsicVersion(oib_port_session, &path, &mad, sessionID, &asicVersion);
			if (status != FSUCCESS) {
				fprintf(stderr, "Error: Failed to get ASIC version - status %d\n", status);
				break;
			}

			chipStep = (asicVersion & ASIC_CHIP_STEP_MASK) >> ASIC_CHIP_STEP_SHFT;
			chipRev = (asicVersion & ASIC_CHIP_REV_MASK) >> ASIC_CHIP_REV_SHFT;
			printf("ASIC Version: V");
			if (chipRev == 0) {
				switch (chipStep) {
					case ASIC_CHIP_STEP_A:
						printf("1\n");
						break;
					case ASIC_CHIP_STEP_B:
						printf("2\n");
						break;
					case ASIC_CHIP_STEP_C:
						printf("3\n");
						break;
					default:
						printf("0\n");
						break;
				}
			} else {
				printf("0\n");
			}
			break;

		case 10:
			printf("Session ID: %d\n", sessionID);
			break;
		case 11:
			{
				/* query port 2 */
				int dest_port_query=1;
				printf("Switch configuration values\n");
				status = sendIniDescriptorGetMad(oib_port_session, &path, &mad, sessionID, &tableDescriptors);
				if (status != FSUCCESS) {
					fprintf(stderr, "%s: Error: Failed to get ini descriptors - status %d\n", cmdName, status);
					goto retErr;
				}
				numPorts = getNumPorts(oib_port_session, &path, sessionID);

				if( numPorts <= 0){
					fprintf(stderr,"error in fetching port records\n");
					goto retErr;
				}
				portEntrySize = tableDescriptors.portDataLen / numPorts;
				status = sendMemAccessGetMad(oib_port_session, &path, &mad, sessionID, tableDescriptors.portDataAddr + (dest_port_query * portEntrySize), portEntrySize*4, memoryData);
				if (status != FSUCCESS) {
					printf("Mem Access MAD Failed \n");
					goto retErr;
				}

				if (g_verbose) {
					printf("MemoryData dump:\n");
					opaswDisplayBuffer((char *)memoryData, portEntrySize * 4);
				}
				portParsedDataTable = malloc(tableDescriptors.portMetaDataLen * sizeof(table_parsed_data_t));
				if(portParsedDataTable == NULL)
				{
					fprintf(stderr,"Not enough memory \n");
					goto retErr;
				}
				status = parseDataTable(&portMetaData[0], memoryData, portMetaDataSize, portParsedDataTable, 0);
				if(status != FSUCCESS) {
					fprintf(stderr," failed: parseDataTable \n");
					goto retErr;
				}
				portPtrs = portParsedDataTable;
				portLinkWidthSupportedIndex = getMetaDataIndexByField(&portMetaData[0], tableDescriptors.portMetaDataLen, "LINK_WIDTH_SUPPORTED");
				portLinkSpeedSupportedIndex = getMetaDataIndexByField(&portMetaData[0], tableDescriptors.portMetaDataLen, "LINK_SPEED_SUPPORTED");
				portFMEnabledIndex = getMetaDataIndexByField(&portMetaData[0], tableDescriptors.portMetaDataLen, "FM_ENABLED");
				portLinkCRCModeIndex = getMetaDataIndexByField(&portMetaData[0], tableDescriptors.portMetaDataLen, "LTP_CRC_MODE_SUPPORTED");
				portvCUIndex = getMetaDataIndexByField(&portMetaData[0], tableDescriptors.portMetaDataLen, "VCU");
				portExternalLoopbackAllowedIndex = getMetaDataIndexByField(&portMetaData[0], tableDescriptors.portMetaDataLen, "EXTERNAL_LOOPBACK_ALLOWED");

				status = getNodeDescription(oib_port_session, &path, sessionID, nodeDesc);
				if (status != FSUCCESS) {
					fprintf(stderr, "Error: Failed to acquire node description - status %d\n", status);
					goto retErr;
				}
#define PRINT_REC(str,fmt,arg...)  printf("        %-*s : "fmt,35,str,arg);

				StlLinkWidthToText(portPtrs[portLinkWidthSupportedIndex].val.intVal, portLinkWidthSupportedText, 20);
				StlLinkSpeedToText(portPtrs[portLinkSpeedSupportedIndex].val.intVal, portLinkSpeedSupportedText, 20);

				PRINT_REC("Link Width"," %s\n", portLinkWidthSupportedText);
				PRINT_REC("Link Speed"," %s\n", portLinkSpeedSupportedText);
				PRINT_REC("FM Enabled"," %s\n", portPtrs[portFMEnabledIndex].val.intVal ? "Yes" : "No");
				PRINT_REC("Link CRC Mode"," %s\n", StlPortLtpCrcModeVMAToText(portPtrs[portLinkCRCModeIndex].val.intVal,portLinkCRCModeValue,sizeof(portLinkCRCModeValue)));
				PRINT_REC("vCU"," %d\n", portPtrs[portvCUIndex].val.intVal);
				PRINT_REC("External Loopback Allowed"," %s\n", portPtrs[portExternalLoopbackAllowedIndex].val.intVal ? "Yes" : "No");
				PRINT_REC("Node Description"," %s\n", strlen((const char *)nodeDesc)==0?(const char *)"no description":(char *)nodeDesc);
retErr:
				if(portParsedDataTable)
					free(portParsedDataTable);
				break;
			}
		case 12:
			status = getBoardID(oib_port_session, &path, &mad, sessionID, &boardID);
			if (status != FSUCCESS) {
				fprintf(stderr, "Error: Failed to get board id - status %d\n", status);
				break;
			}
			printf("BoardID: 0x%02x\n", boardID);
			break;

		default:
			fprintf(stderr, "Error: Invalid query number %d\n", g_queryNum);
			releaseSession(oib_port_session, &path, sessionID);
			usage(cmdName);
			break;
	}

	releaseSession(oib_port_session, &path, sessionID);

	printf("opaswquery completed\n");

err_exit:
	if (oib_port_session != NULL) {
		oib_close_port(oib_port_session);
	}

	if (status == FSUCCESS)
		exit(0);
	else
		exit(1);

}