void *
mps_read_extended_config_page(int fd, U8 ExtPageType, U8 PageVersion,
    U8 PageNumber, U32 PageAddress, U16 *IOCStatus)
{
	struct mps_ext_cfg_page_req req;
	void *buf;
	int error;

	if (IOCStatus != NULL)
		*IOCStatus = MPI2_IOCSTATUS_SUCCESS;
	bzero(&req, sizeof(req));
	req.header.PageVersion = PageVersion;
	req.header.PageNumber = PageNumber;
	req.header.ExtPageType = ExtPageType;
	req.page_address = PageAddress;
	if (ioctl(fd, MPSIO_READ_EXT_CFG_HEADER, &req) < 0)
		return (NULL);
	if (!IOC_STATUS_SUCCESS(req.ioc_status)) {
		if (IOCStatus != NULL)
			*IOCStatus = req.ioc_status;
		else
			warnx("Reading extended config page header failed: %s",
			    mps_ioc_status(req.ioc_status));
		errno = EIO;
		return (NULL);
	}
	req.len = req.header.ExtPageLength * 4;
	buf = malloc(req.len);
	req.buf = buf;
	bcopy(&req.header, buf, sizeof(req.header));
	if (ioctl(fd, MPSIO_READ_EXT_CFG_PAGE, &req) < 0) {
		error = errno;
		free(buf);
		errno = error;
		return (NULL);
	}
	if (!IOC_STATUS_SUCCESS(req.ioc_status)) {
		if (IOCStatus != NULL)
			*IOCStatus = req.ioc_status;
		else
			warnx("Reading extended config page failed: %s",
			    mps_ioc_status(req.ioc_status));
		free(buf);
		errno = EIO;
		return (NULL);
	}
	return (buf);
}
MPI2_IOC_FACTS_REPLY *
mps_get_iocfacts(int fd)
{
	MPI2_IOC_FACTS_REPLY *facts;
	MPI2_IOC_FACTS_REQUEST req;
	int error;

	facts = malloc(sizeof(MPI2_IOC_FACTS_REPLY));
	if (facts == NULL) {
		errno = ENOMEM;
		return (NULL);
	}

	bzero(&req, sizeof(MPI2_IOC_FACTS_REQUEST));
	req.Function = MPI2_FUNCTION_IOC_FACTS;

#if 1
	error = mps_pass_command(fd, &req, sizeof(MPI2_IOC_FACTS_REQUEST),
	    facts, sizeof(MPI2_IOC_FACTS_REPLY), NULL, 0, NULL, 0, 10);
#else
	error = mps_user_command(fd, &req, sizeof(MPI2_IOC_FACTS_REQUEST),
	    facts, sizeof(MPI2_IOC_FACTS_REPLY), NULL, 0, 0);
#endif
	if (error) {
		free(facts);
		return (NULL);
	}

	if (!IOC_STATUS_SUCCESS(facts->IOCStatus)) {
		free(facts);
		errno = EINVAL;
		return (NULL);
	}
	return (facts);
}
int
mps_read_ext_config_page_header(int fd, U8 ExtPageType, U8 PageNumber, U32 PageAddress, MPI2_CONFIG_PAGE_HEADER *header, U16 *ExtPageLength, U16 *IOCStatus)
{
	MPI2_CONFIG_REQUEST req;
	MPI2_CONFIG_REPLY reply;

	bzero(&req, sizeof(req));
	req.Function = MPI2_FUNCTION_CONFIG;
	req.Action = MPI2_CONFIG_ACTION_PAGE_HEADER;
	req.Header.PageType = MPI2_CONFIG_PAGETYPE_EXTENDED;
	req.ExtPageType = ExtPageType;
	req.Header.PageNumber = PageNumber;
	req.PageAddress = PageAddress;

	if (mps_pass_command(fd, &req, sizeof(req), &reply, sizeof(reply),
	    NULL, 0, NULL, 0, 30))
		return (errno);

	if (!IOC_STATUS_SUCCESS(reply.IOCStatus)) {
		if (IOCStatus != NULL)
			*IOCStatus = reply.IOCStatus;
		return (EIO);
	}
	if ((header == NULL) || (ExtPageLength == NULL))
		return (EINVAL);
	*header = reply.Header;
	*ExtPageLength = reply.ExtPageLength;
	return (0);
}
Exemple #4
0
int
mpt_write_config_page(int fd, void *buf, U16 *IOCStatus)
{
	CONFIG_PAGE_HEADER *hdr;
	struct mpt_cfg_page_req req;

	if (IOCStatus != NULL)
		*IOCStatus = MPI_IOCSTATUS_SUCCESS;
	bzero(&req, sizeof(req));
	req.buf = buf;
	hdr = buf;
	req.len = hdr->PageLength * 4;
	if (ioctl(fd, MPTIO_WRITE_CFG_PAGE, &req) < 0)
		return (errno);
	if (!IOC_STATUS_SUCCESS(req.ioc_status)) {
		if (IOCStatus != NULL) {
			*IOCStatus = req.ioc_status;
			return (0);
		}
		warnx("Writing config page failed: %s",
		    mpt_ioc_status(req.ioc_status));
		return (EIO);
	}
	return (0);
}
Exemple #5
0
int
mpt_read_config_page_header(int fd, U8 PageType, U8 PageNumber, U32 PageAddress,
    CONFIG_PAGE_HEADER *header, U16 *IOCStatus)
{
	struct mpt_cfg_page_req req;

	if (IOCStatus != NULL)
		*IOCStatus = MPI_IOCSTATUS_SUCCESS;
	bzero(&req, sizeof(req));
	req.header.PageType = PageType;
	req.header.PageNumber = PageNumber;
	req.page_address = PageAddress;
	if (ioctl(fd, MPTIO_READ_CFG_HEADER, &req) < 0)
		return (errno);
	if (!IOC_STATUS_SUCCESS(req.ioc_status)) {
		if (IOCStatus != NULL)
			*IOCStatus = req.ioc_status;
		else
			warnx("Reading config page header failed: %s",
			    mpt_ioc_status(req.ioc_status));
		return (EIO);
	}
	*header = req.header;
	return (0);
}
void *
mps_read_extended_config_page(int fd, U8 ExtPageType, U8 PageVersion,
    U8 PageNumber, U32 PageAddress, U16 *IOCStatus)
{
	MPI2_CONFIG_REQUEST req;
	MPI2_CONFIG_PAGE_HEADER header;
	MPI2_CONFIG_REPLY reply;
	U16 pagelen;
	void *buf;
	int error, len;

	if (IOCStatus != NULL)
		*IOCStatus = MPI2_IOCSTATUS_SUCCESS;
	bzero(&header, sizeof(header));
	error = mps_read_ext_config_page_header(fd, ExtPageType, PageNumber,
	    PageAddress, &header, &pagelen, IOCStatus);
	if (error) {
		errno = error;
		return (NULL);
	}

	bzero(&req, sizeof(req));
	req.Function = MPI2_FUNCTION_CONFIG;
	req.Action = MPI2_CONFIG_ACTION_PAGE_READ_CURRENT;
	req.PageAddress = PageAddress;
	req.Header = header;
	if (pagelen == 0)
		pagelen = 4;
	req.ExtPageLength = pagelen;
	req.ExtPageType = ExtPageType;

	len = pagelen * 4;
	buf = malloc(len);
	if (mps_pass_command(fd, &req, sizeof(req), &reply, sizeof(reply),
	    buf, len, NULL, 0, 30)) {
		error = errno;
		free(buf);
		errno = error;
		return (NULL);
	}
	if (!IOC_STATUS_SUCCESS(reply.IOCStatus)) {
		if (IOCStatus != NULL)
			*IOCStatus = reply.IOCStatus;
		else
			warnx("Reading extended config page failed: %s",
			    mps_ioc_status(reply.IOCStatus));
		free(buf);
		errno = EIO;
		return (NULL);
	}
	return (buf);
}
Exemple #7
0
int
mpt_raid_action(int fd, U8 Action, U8 VolumeBus, U8 VolumeID, U8 PhysDiskNum,
    U32 ActionDataWord, void *buf, int len, RAID_VOL0_STATUS *VolumeStatus,
    U32 *ActionData, int datalen, U16 *IOCStatus, U16 *ActionStatus, int write)
{
	struct mpt_raid_action raid_act;

	if (IOCStatus != NULL)
		*IOCStatus = MPI_IOCSTATUS_SUCCESS;
	if (datalen < 0 || (unsigned)datalen > sizeof(raid_act.action_data))
		return (EINVAL);
	bzero(&raid_act, sizeof(raid_act));
	raid_act.action = Action;
	raid_act.volume_bus = VolumeBus;
	raid_act.volume_id = VolumeID;
	raid_act.phys_disk_num = PhysDiskNum;
	raid_act.action_data_word = ActionDataWord;
	if (buf != NULL && len != 0) {
		raid_act.buf = buf;
		raid_act.len = len;
		raid_act.write = write;
	}

	if (ioctl(fd, MPTIO_RAID_ACTION, &raid_act) < 0)
		return (errno);

	if (!IOC_STATUS_SUCCESS(raid_act.ioc_status)) {
		if (IOCStatus != NULL) {
			*IOCStatus = raid_act.ioc_status;
			return (0);
		}
		warnx("RAID action failed: %s",
		    mpt_ioc_status(raid_act.ioc_status));
		return (EIO);
	}

	if (ActionStatus != NULL)
		*ActionStatus = raid_act.action_status;
	if (raid_act.action_status != MPI_RAID_ACTION_ASTATUS_SUCCESS) {
		if (ActionStatus != NULL)
			return (0);
		warnx("RAID action failed: %s",
		    mpt_raid_status(raid_act.action_status));
		return (EIO);
	}

	if (VolumeStatus != NULL)
		*((U32 *)VolumeStatus) = raid_act.volume_status;
	if (ActionData != NULL)
		bcopy(raid_act.action_data, ActionData, datalen);
	return (0);
}
void *
mps_read_config_page(int fd, U8 PageType, U8 PageNumber, U32 PageAddress,
    U16 *IOCStatus)
{
	struct mps_cfg_page_req req;
	void *buf;
	int error;

	error = mps_read_config_page_header(fd, PageType, PageNumber,
	    PageAddress, &req.header, IOCStatus);
	if (error) {
		errno = error;
		return (NULL);
	}

	if (req.header.PageLength == 0)
		req.header.PageLength = 4;
	req.len = req.header.PageLength * 4;
	buf = malloc(req.len);
	req.buf = buf;
	bcopy(&req.header, buf, sizeof(req.header));
	if (ioctl(fd, MPSIO_READ_CFG_PAGE, &req) < 0) {
		error = errno;
		free(buf);
		errno = error;
		return (NULL);
	}
	if (!IOC_STATUS_SUCCESS(req.ioc_status)) {
		if (IOCStatus != NULL)
			*IOCStatus = req.ioc_status;
		else
			warnx("Reading config page failed: 0x%x %s",
			    req.ioc_status, mps_ioc_status(req.ioc_status));
		free(buf);
		errno = EIO;
		return (NULL);
	}
	return (buf);
}
int
mps_read_config_page_header(int fd, U8 PageType, U8 PageNumber, U32 PageAddress,
    MPI2_CONFIG_PAGE_HEADER *header, U16 *IOCStatus)
{
	struct mps_cfg_page_req req;

	if (IOCStatus != NULL)
		*IOCStatus = MPI2_IOCSTATUS_SUCCESS;
	if (header == NULL)
		return (EINVAL);
	bzero(&req, sizeof(req));
	req.header.PageType = PageType;
	req.header.PageNumber = PageNumber;
	req.page_address = PageAddress;
	if (ioctl(fd, MPSIO_READ_CFG_HEADER, &req) < 0)
		return (errno);
	if (!IOC_STATUS_SUCCESS(req.ioc_status)) {
		if (IOCStatus != NULL)
			*IOCStatus = req.ioc_status;
		return (EIO);
	}
	bcopy(&req.header, header, sizeof(*header));
	return (0);
}