diff --git a/usr.sbin/mpsutil/mps_cmd.c b/usr.sbin/mpsutil/mps_cmd.c index f0ff98c2442b..a9cb269abc5f 100644 --- a/usr.sbin/mpsutil/mps_cmd.c +++ b/usr.sbin/mpsutil/mps_cmd.c @@ -1,766 +1,803 @@ /*- * Copyright (c) 2015 Baptiste Daroussin * * Copyright (c) 2015 Netflix, Inc. * Written by: Scott Long * * Copyright (c) 2008 Yahoo!, Inc. * All rights reserved. * Written by: John Baldwin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __RCSID("$FreeBSD$"); #include #include #include #include #include +#include #include #include #include #include #include #include #include "mpsutil.h" #include #include #ifndef USE_MPT_IOCTLS #define USE_MPT_IOCTLS #endif static const char *mps_ioc_status_codes[] = { "Success", /* 0x0000 */ "Invalid function", "Busy", "Invalid scatter-gather list", "Internal error", "Reserved", "Insufficient resources", "Invalid field", "Invalid state", /* 0x0008 */ "Operation state not supported", NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x0010 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x0018 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, "Invalid configuration action", /* 0x0020 */ "Invalid configuration type", "Invalid configuration page", "Invalid configuration data", "No configuration defaults", "Unable to commit configuration change", NULL, NULL, NULL, /* 0x0028 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x0030 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x0038 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, "Recovered SCSI error", /* 0x0040 */ "Invalid SCSI bus", "Invalid SCSI target ID", "SCSI device not there", "SCSI data overrun", "SCSI data underrun", "SCSI I/O error", "SCSI protocol error", "SCSI task terminated", /* 0x0048 */ "SCSI residual mismatch", "SCSI task management failed", "SCSI I/O controller terminated", "SCSI external controller terminated", "EEDP guard error", "EEDP reference tag error", "EEDP application tag error", NULL, /* 0x0050 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x0058 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, "SCSI target priority I/O", /* 0x0060 */ "Invalid SCSI target port", "Invalid SCSI target I/O index", "SCSI target aborted", "No connection retryable", "No connection", "FC aborted", "Invalid FC receive ID", "FC did invalid", /* 0x0068 */ "FC node logged out", "Transfer count mismatch", "STS data not set", "FC exchange canceled", "Data offset error", "Too much write data", "IU too short", "ACK NAK timeout", /* 0x0070 */ "NAK received", NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 0x0078 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, "LAN device not found", /* 0x0080 */ "LAN device failure", "LAN transmit error", "LAN transmit aborted", "LAN receive error", "LAN receive aborted", "LAN partial packet", "LAN canceled", NULL, /* 0x0088 */ NULL, NULL, NULL, NULL, NULL, NULL, NULL, "SAS SMP request failed", /* 0x0090 */ "SAS SMP data overrun", NULL, NULL, NULL, NULL, NULL, NULL, "Inband aborted", /* 0x0098 */ "No inband connection", NULL, NULL, NULL, NULL, NULL, NULL, "Diagnostic released", /* 0x00A0 */ }; struct mprs_pass_thru { uint64_t PtrRequest; uint64_t PtrReply; uint64_t PtrData; uint32_t RequestSize; uint32_t ReplySize; uint32_t DataSize; uint32_t DataDirection; uint64_t PtrDataOut; uint32_t DataOutSize; uint32_t Timeout; }; struct mprs_btdh_mapping { uint16_t TargetID; uint16_t Bus; uint16_t DevHandle; uint16_t Reserved; }; +static void adjust_iocfacts_endianness(MPI2_IOC_FACTS_REPLY *facts); + const char * mps_ioc_status(U16 IOCStatus) { static char buffer[16]; IOCStatus &= MPI2_IOCSTATUS_MASK; if (IOCStatus < sizeof(mps_ioc_status_codes) / sizeof(char *) && mps_ioc_status_codes[IOCStatus] != NULL) return (mps_ioc_status_codes[IOCStatus]); snprintf(buffer, sizeof(buffer), "Status: 0x%04x", IOCStatus); return (buffer); } #ifdef USE_MPT_IOCTLS int mps_map_btdh(int fd, uint16_t *devhandle, uint16_t *bus, uint16_t *target) { int error; struct mprs_btdh_mapping map; map.Bus = *bus; map.TargetID = *target; map.DevHandle = *devhandle; if ((error = ioctl(fd, MPTIOCTL_BTDH_MAPPING, &map)) != 0) { error = errno; warn("Failed to map bus/target/device"); return (error); } *bus = map.Bus; *target = map.TargetID; *devhandle = map.DevHandle; return (0); } int mps_set_slot_status(int fd, U16 handle, U16 slot, U32 status) { MPI2_SEP_REQUEST req; MPI2_SEP_REPLY reply; bzero(&req, sizeof(req)); req.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR; req.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS; req.Flags = MPI2_SEP_REQ_FLAGS_ENCLOSURE_SLOT_ADDRESS; req.EnclosureHandle = handle; req.Slot = slot; req.SlotStatus = status; if (mps_pass_command(fd, &req, sizeof(req), &reply, sizeof(reply), NULL, 0, NULL, 0, 30) != 0) return (errno); - if (!IOC_STATUS_SUCCESS(reply.IOCStatus)) + if (!IOC_STATUS_SUCCESS(le16toh(reply.IOCStatus))) return (EIO); return (0); } int mps_read_config_page_header(int fd, U8 PageType, U8 PageNumber, U32 PageAddress, MPI2_CONFIG_PAGE_HEADER *header, 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 = PageType; 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 (!IOC_STATUS_SUCCESS(le16toh(reply.IOCStatus))) { if (IOCStatus != NULL) *IOCStatus = reply.IOCStatus; return (EIO); } if (header == NULL) return (EINVAL); *header = reply.Header; return (0); } 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; + req.PageAddress = htole32(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 (!IOC_STATUS_SUCCESS(le16toh(reply.IOCStatus))) { if (IOCStatus != NULL) - *IOCStatus = reply.IOCStatus; + *IOCStatus = le16toh(reply.IOCStatus); return (EIO); } if ((header == NULL) || (ExtPageLength == NULL)) return (EINVAL); *header = reply.Header; *ExtPageLength = reply.ExtPageLength; return (0); } void * mps_read_config_page(int fd, U8 PageType, U8 PageNumber, U32 PageAddress, U16 *IOCStatus) { MPI2_CONFIG_REQUEST req; MPI2_CONFIG_PAGE_HEADER header; MPI2_CONFIG_REPLY reply; void *buf; int error, len; bzero(&header, sizeof(header)); error = mps_read_config_page_header(fd, PageType, PageNumber, PageAddress, &header, 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.PageAddress = htole32(PageAddress); req.Header = header; if (req.Header.PageLength == 0) req.Header.PageLength = 4; len = req.Header.PageLength * 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); } + reply.IOCStatus = le16toh(reply.IOCStatus); if (!IOC_STATUS_SUCCESS(reply.IOCStatus)) { if (IOCStatus != NULL) *IOCStatus = reply.IOCStatus; else warnx("Reading config page failed: 0x%x %s", reply.IOCStatus, mps_ioc_status(reply.IOCStatus)); free(buf); errno = EIO; return (NULL); } return (buf); } 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.PageAddress = htole32(PageAddress); req.Header = header; if (pagelen == 0) - pagelen = 4; + pagelen = htole16(4); req.ExtPageLength = pagelen; req.ExtPageType = ExtPageType; - len = pagelen * 4; + len = le16toh(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); } + reply.IOCStatus = le16toh(reply.IOCStatus); 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); } int mps_firmware_send(int fd, unsigned char *fw, uint32_t len, bool bios) { MPI2_FW_DOWNLOAD_REQUEST req; MPI2_FW_DOWNLOAD_REPLY reply; bzero(&req, sizeof(req)); bzero(&reply, sizeof(reply)); req.Function = MPI2_FUNCTION_FW_DOWNLOAD; req.ImageType = bios ? MPI2_FW_DOWNLOAD_ITYPE_BIOS : MPI2_FW_DOWNLOAD_ITYPE_FW; - req.TotalImageSize = len; + req.TotalImageSize = htole32(len); req.MsgFlags = MPI2_FW_DOWNLOAD_MSGFLGS_LAST_SEGMENT; if (mps_user_command(fd, &req, sizeof(req), &reply, sizeof(reply), fw, len, 0)) { return (-1); } return (0); } int mps_firmware_get(int fd, unsigned char **firmware, bool bios) { MPI2_FW_UPLOAD_REQUEST req; MPI2_FW_UPLOAD_REPLY reply; int size; *firmware = NULL; bzero(&req, sizeof(req)); bzero(&reply, sizeof(reply)); req.Function = MPI2_FUNCTION_FW_UPLOAD; req.ImageType = bios ? MPI2_FW_DOWNLOAD_ITYPE_BIOS : MPI2_FW_DOWNLOAD_ITYPE_FW; if (mps_user_command(fd, &req, sizeof(req), &reply, sizeof(reply), NULL, 0, 0)) { return (-1); } if (reply.ActualImageSize == 0) { return (-1); } - size = reply.ActualImageSize; + size = le32toh(reply.ActualImageSize); *firmware = calloc(size, sizeof(unsigned char)); if (*firmware == NULL) { warn("calloc"); return (-1); } if (mps_user_command(fd, &req, sizeof(req), &reply, sizeof(reply), *firmware, size, 0)) { free(*firmware); return (-1); } return (size); } #else 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); } 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); } + req.ioc_status = le16toh(req.ioc_status); 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); } 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; + req.page_address = htole32(PageAddress); if (ioctl(fd, MPSIO_READ_EXT_CFG_HEADER, &req) < 0) return (NULL); + req.ioc_status = le16toh(req.ioc_status); 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); } + req.ioc_status = le16toh(req.ioc_status); 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); } #endif int mps_open(int unit) { char path[MAXPATHLEN]; snprintf(path, sizeof(path), "/dev/mp%s%d", is_mps ? "s": "r", unit); return (open(path, O_RDWR)); } int mps_user_command(int fd, void *req, uint32_t req_len, void *reply, uint32_t reply_len, void *buffer, int len, uint32_t flags) { struct mps_usr_command cmd; bzero(&cmd, sizeof(struct mps_usr_command)); cmd.req = req; cmd.req_len = req_len; cmd.rpl = reply; cmd.rpl_len = reply_len; cmd.buf = buffer; cmd.len = len; cmd.flags = flags; if (ioctl(fd, is_mps ? MPSIO_MPS_COMMAND : MPRIO_MPR_COMMAND, &cmd) < 0) return (errno); return (0); } int mps_pass_command(int fd, void *req, uint32_t req_len, void *reply, uint32_t reply_len, void *data_in, uint32_t datain_len, void *data_out, uint32_t dataout_len, uint32_t timeout) { struct mprs_pass_thru pass; bzero(&pass, sizeof(pass)); pass.PtrRequest = (uint64_t)(uintptr_t)req; pass.PtrReply = (uint64_t)(uintptr_t)reply; pass.RequestSize = req_len; pass.ReplySize = reply_len; if (datain_len && dataout_len) { pass.PtrData = (uint64_t)(uintptr_t)data_in; pass.PtrDataOut = (uint64_t)(uintptr_t)data_out; pass.DataSize = datain_len; pass.DataOutSize = dataout_len; if (is_mps) { pass.DataDirection = MPS_PASS_THRU_DIRECTION_BOTH; } else { pass.DataDirection = MPR_PASS_THRU_DIRECTION_BOTH; } } else if (datain_len) { pass.PtrData = (uint64_t)(uintptr_t)data_in; pass.DataSize = datain_len; if (is_mps) { pass.DataDirection = MPS_PASS_THRU_DIRECTION_READ; } else { pass.DataDirection = MPR_PASS_THRU_DIRECTION_READ; } } else if (dataout_len) { pass.PtrData = (uint64_t)(uintptr_t)data_out; pass.DataSize = dataout_len; if (is_mps) { pass.DataDirection = MPS_PASS_THRU_DIRECTION_WRITE; } else { pass.DataDirection = MPR_PASS_THRU_DIRECTION_WRITE; } } else { if (is_mps) { pass.DataDirection = MPS_PASS_THRU_DIRECTION_NONE; } else { pass.DataDirection = MPR_PASS_THRU_DIRECTION_NONE; } } pass.Timeout = timeout; if (ioctl(fd, MPTIOCTL_PASS_THRU, &pass) < 0) return (errno); return (0); } MPI2_IOC_FACTS_REPLY * mps_get_iocfacts(int fd) { MPI2_IOC_FACTS_REPLY *facts; MPI2_IOC_FACTS_REQUEST req; char msgver[8], sysctlname[128]; size_t len, factslen; int error; snprintf(sysctlname, sizeof(sysctlname), "dev.%s.%d.msg_version", is_mps ? "mps" : "mpr", mps_unit); factslen = sizeof(MPI2_IOC_FACTS_REPLY); len = sizeof(msgver); error = sysctlbyname(sysctlname, msgver, &len, NULL, 0); if (error == 0) { if (strncmp(msgver, "2.6", sizeof(msgver)) == 0) factslen += 4; } facts = malloc(factslen); if (facts == NULL) { errno = ENOMEM; return (NULL); } bzero(&req, factslen); req.Function = MPI2_FUNCTION_IOC_FACTS; #if 1 error = mps_pass_command(fd, &req, sizeof(MPI2_IOC_FACTS_REQUEST), facts, factslen, NULL, 0, NULL, 0, 10); #else error = mps_user_command(fd, &req, sizeof(MPI2_IOC_FACTS_REQUEST), facts, factslen, NULL, 0, 0); #endif if (error) { free(facts); return (NULL); } if (!IOC_STATUS_SUCCESS(facts->IOCStatus)) { free(facts); errno = EINVAL; return (NULL); } + adjust_iocfacts_endianness(facts); return (facts); } +static void +adjust_iocfacts_endianness(MPI2_IOC_FACTS_REPLY *facts) +{ + facts->MsgVersion = le16toh(facts->MsgVersion); + facts->HeaderVersion = le16toh(facts->HeaderVersion); + facts->Reserved1 = le16toh(facts->Reserved1); + facts->IOCExceptions = le16toh(facts->IOCExceptions); + facts->IOCStatus = le16toh(facts->IOCStatus); + facts->IOCLogInfo = le32toh(facts->IOCLogInfo); + facts->RequestCredit = le16toh(facts->RequestCredit); + facts->ProductID = le16toh(facts->ProductID); + facts->IOCCapabilities = le32toh(facts->IOCCapabilities); + facts->IOCRequestFrameSize = + le16toh(facts->IOCRequestFrameSize); + facts->FWVersion.Word = le32toh(facts->FWVersion.Word); + facts->MaxInitiators = le16toh(facts->MaxInitiators); + facts->MaxTargets = le16toh(facts->MaxTargets); + facts->MaxSasExpanders = le16toh(facts->MaxSasExpanders); + facts->MaxEnclosures = le16toh(facts->MaxEnclosures); + facts->ProtocolFlags = le16toh(facts->ProtocolFlags); + facts->HighPriorityCredit = le16toh(facts->HighPriorityCredit); + facts->MaxReplyDescriptorPostQueueDepth = + le16toh(facts->MaxReplyDescriptorPostQueueDepth); + facts->MaxDevHandle = le16toh(facts->MaxDevHandle); + facts->MaxPersistentEntries = + le16toh(facts->MaxPersistentEntries); + facts->MinDevHandle = le16toh(facts->MinDevHandle); +} diff --git a/usr.sbin/mpsutil/mps_flash.c b/usr.sbin/mpsutil/mps_flash.c index 22beaae79bb0..a0cc4a877b7d 100644 --- a/usr.sbin/mpsutil/mps_flash.c +++ b/usr.sbin/mpsutil/mps_flash.c @@ -1,245 +1,246 @@ /*- * Copyright (c) 2015 Baptiste Daroussin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __RCSID("$FreeBSD$"); #include #include #include +#include #include #include #include #include #include #include #include #include #include "mpsutil.h" MPS_TABLE(top, flash); static int flash_save(int argc, char **argv) { const char *firmware_file; unsigned char *firmware_buffer = NULL; int error, fd, size; bool bios = false; ssize_t written = 0, ret = 0; if (argc < 2) { warnx("missing argument: expecting 'firmware' or bios'"); return (EINVAL); } if (strcmp(argv[1], "bios") == 0) { bios = true; } else if (strcmp(argv[1], "firmware") != 0) { warnx("Invalid argument '%s', expecting 'firmware' or 'bios'", argv[1]); } if (argc > 4) { warnx("save %s: extra arguments", argv[1]); return (EINVAL); } firmware_file = argv[1]; if (argc == 3) { firmware_file = argv[2]; } fd = mps_open(mps_unit); if (fd < 0) { error = errno; warn("mps_open"); return (error); } if ((size = mps_firmware_get(fd, &firmware_buffer, bios)) < 0) { warnx("Fail to save %s", argv[1]); close(fd); return (1); } close(fd); if (size > 0) { fd = open(firmware_file, O_CREAT | O_TRUNC | O_RDWR, 0644); if (fd <0) { error = errno; warn("open"); free(firmware_buffer); return (error); } while (written != size) { if ((ret = write(fd, firmware_buffer + written, size - written)) <0) { error = errno; warn("write"); free(firmware_buffer); close(fd); return (error); } written += ret; } close(fd); } free(firmware_buffer); printf("%s successfully saved as %s\n", argv[1], firmware_file); return (0); } MPS_COMMAND(flash, save, flash_save, "[firmware|bios] [file]", "Save firmware/bios into a file"); static int flash_update(int argc, char **argv) { int error, fd; unsigned char *mem = NULL; struct stat st; bool bios = false; MPI2_FW_IMAGE_HEADER *fwheader; MPI2_IOC_FACTS_REPLY *facts; if (argc < 2) { warnx("missing argument: expecting 'firmware' or bios'"); return (EINVAL); } if (strcmp(argv[1], "bios") == 0) { bios = true; } else if (strcmp(argv[1], "firmware") != 0) { warnx("Invalid argument '%s', expecting 'firmware' or 'bios'", argv[1]); } if (argc > 4) { warnx("update firmware: extra arguments"); return (EINVAL); } if (argc != 3) { warnx("no firmware specified"); return (EINVAL); } if (stat(argv[2], &st) == -1) { error = errno; warn("stat"); return (error); } fd = open(argv[2], O_RDONLY); if (fd < 0) { error = errno; warn("open"); return (error); } mem = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); if (mem == MAP_FAILED) { error = errno; warn("mmap"); close(fd); return (error); } close(fd); fd = mps_open(mps_unit); if (fd < 0) { error = errno; warn("mps_open"); munmap(mem, st.st_size); return (error); } if ((facts = mps_get_iocfacts(fd)) == NULL) { warnx("could not get controller IOCFacts\n"); munmap(mem, st.st_size); close(fd); return (EINVAL); } if (bios) { /* Check boot record magic number */ if (((mem[0x01]<<8) + mem[0x00]) != 0xaa55) { warnx("Invalid bios: no boot record magic number"); munmap(mem, st.st_size); close(fd); free(facts); return (1); } if ((st.st_size % 512) != 0) { warnx("Invalid bios: size not a multiple of 512"); munmap(mem, st.st_size); close(fd); free(facts); return (1); } } else { fwheader = (MPI2_FW_IMAGE_HEADER *)mem; - if (fwheader->VendorID != MPI2_MFGPAGE_VENDORID_LSI) { + if (le16toh(fwheader->VendorID) != MPI2_MFGPAGE_VENDORID_LSI) { warnx("Invalid firmware:"); warnx(" Expected Vendor ID: %04x", MPI2_MFGPAGE_VENDORID_LSI); - warnx(" Image Vendor ID: %04x", fwheader->VendorID); + warnx(" Image Vendor ID: %04x", le16toh(fwheader->VendorID)); munmap(mem, st.st_size); close(fd); free(facts); return (1); } - if (fwheader->ProductID != facts->ProductID) { + if (le16toh(fwheader->ProductID) != facts->ProductID) { warnx("Invalid image:"); warnx(" Expected Product ID: %04x", facts->ProductID); - warnx(" Image Product ID: %04x", fwheader->ProductID); + warnx(" Image Product ID: %04x", le16toh(fwheader->ProductID)); munmap(mem, st.st_size); close(fd); free(facts); return (1); } } printf("Updating %s...\n", argv[1]); if (mps_firmware_send(fd, mem, st.st_size, bios) < 0) { warnx("Fail to update %s", argv[1]); munmap(mem, st.st_size); close(fd); free(facts); return (1); } munmap(mem, st.st_size); close(fd); free(facts); printf("%s successfully updated\n", argv[1]); return (0); } MPS_COMMAND(flash, update, flash_update, "[firmware|bios] file", "Update firmware/bios"); diff --git a/usr.sbin/mpsutil/mps_show.c b/usr.sbin/mpsutil/mps_show.c index bb790fe21229..620bb5e27f89 100644 --- a/usr.sbin/mpsutil/mps_show.c +++ b/usr.sbin/mpsutil/mps_show.c @@ -1,819 +1,820 @@ /*- * Copyright (c) 2015 Netflix, Inc. * Written by: Scott Long * * Copyright (c) 2008 Yahoo!, Inc. * All rights reserved. * Written by: John Baldwin * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the author nor the names of any co-contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __RCSID("$FreeBSD$"); #include #include +#include #include #include #include #include #include #include #include "mpsutil.h" static char * get_device_speed(uint8_t rate); static char * get_device_type(uint32_t di); static int show_all(int ac, char **av); static int show_devices(int ac, char **av); static int show_enclosures(int ac, char **av); static int show_expanders(int ac, char **av); MPS_TABLE(top, show); #define STANDALONE_STATE "ONLINE" static int show_adapter(int ac, char **av) { MPI2_CONFIG_PAGE_SASIOUNIT_0 *sas0; MPI2_CONFIG_PAGE_SASIOUNIT_1 *sas1; MPI2_SAS_IO_UNIT0_PHY_DATA *phy0; MPI2_SAS_IO_UNIT1_PHY_DATA *phy1; MPI2_CONFIG_PAGE_MAN_0 *man0; MPI2_CONFIG_PAGE_BIOS_3 *bios3; MPI2_IOC_FACTS_REPLY *facts; U16 IOCStatus; char *speed, *minspeed, *maxspeed, *isdisabled, *type; char devhandle[5], ctrlhandle[5]; int error, fd, v, i; if (ac != 1) { warnx("show adapter: extra arguments"); return (EINVAL); } fd = mps_open(mps_unit); if (fd < 0) { error = errno; warn("mps_open"); return (error); } man0 = mps_read_man_page(fd, 0, NULL); if (man0 == NULL) { error = errno; warn("Failed to get controller info"); return (error); } if (man0->Header.PageLength < sizeof(*man0) / 4) { warnx("Invalid controller info"); return (EINVAL); } printf("mp%s%d Adapter:\n", is_mps ? "s": "r", mps_unit); printf(" Board Name: %.16s\n", man0->BoardName); printf(" Board Assembly: %.16s\n", man0->BoardAssembly); printf(" Chip Name: %.16s\n", man0->ChipName); printf(" Chip Revision: %.16s\n", man0->ChipRevision); free(man0); bios3 = mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_BIOS, 3, 0, NULL); if (bios3 == NULL) { error = errno; warn("Failed to get BIOS page 3 info"); return (error); } - v = bios3->BiosVersion; + v = le32toh(bios3->BiosVersion); printf(" BIOS Revision: %d.%02d.%02d.%02d\n", ((v & 0xff000000) >> 24), ((v &0xff0000) >> 16), ((v & 0xff00) >> 8), (v & 0xff)); free(bios3); if ((facts = mps_get_iocfacts(fd)) == NULL) { printf("could not get controller IOCFacts\n"); close(fd); return (errno); } v = facts->FWVersion.Word; printf("Firmware Revision: %d.%02d.%02d.%02d\n", ((v & 0xff000000) >> 24), ((v &0xff0000) >> 16), ((v & 0xff00) >> 8), (v & 0xff)); printf(" Integrated RAID: %s\n", (facts->IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_INTEGRATED_RAID) ? "yes" : "no"); free(facts); fd = mps_open(mps_unit); if (fd < 0) { error = errno; warn("mps_open"); return (error); } sas0 = mps_read_extended_config_page(fd, MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT, MPI2_SASIOUNITPAGE0_PAGEVERSION, 0, 0, &IOCStatus); if (sas0 == NULL) { error = errno; warn("Error retrieving SAS IO Unit page %d", IOCStatus); free(sas0); close(fd); return (error); } sas1 = mps_read_extended_config_page(fd, MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT, MPI2_SASIOUNITPAGE1_PAGEVERSION, 1, 0, &IOCStatus); if (sas1 == NULL) { error = errno; warn("Error retrieving SAS IO Unit page %d", IOCStatus); free(sas0); close(fd); return (error); } printf("\n"); printf("%-8s%-12s%-11s%-10s%-8s%-7s%-7s%s\n", "PhyNum", "CtlrHandle", "DevHandle", "Disabled", "Speed", "Min", "Max", "Device"); for (i = 0; i < sas0->NumPhys; i++) { phy0 = &sas0->PhyData[i]; phy1 = &sas1->PhyData[i]; if (phy0->PortFlags & MPI2_SASIOUNIT0_PORTFLAGS_DISCOVERY_IN_PROGRESS) { printf("Discovery still in progress\n"); continue; } if (phy0->PhyFlags & MPI2_SASIOUNIT0_PHYFLAGS_PHY_DISABLED) isdisabled = "Y"; else isdisabled = "N"; minspeed = get_device_speed(phy1->MaxMinLinkRate); maxspeed = get_device_speed(phy1->MaxMinLinkRate >> 4); - type = get_device_type(phy0->ControllerPhyDeviceInfo); + type = get_device_type(le32toh(phy0->ControllerPhyDeviceInfo)); - if (phy0->AttachedDevHandle != 0) { - snprintf(devhandle, 5, "%04x", phy0->AttachedDevHandle); + if (le16toh(phy0->AttachedDevHandle) != 0) { + snprintf(devhandle, 5, "%04x", le16toh(phy0->AttachedDevHandle)); snprintf(ctrlhandle, 5, "%04x", - phy0->ControllerDevHandle); + le16toh(phy0->ControllerDevHandle)); speed = get_device_speed(phy0->NegotiatedLinkRate); } else { snprintf(devhandle, 5, " "); snprintf(ctrlhandle, 5, " "); speed = " "; } printf("%-8d%-12s%-11s%-10s%-8s%-7s%-7s%s\n", i, ctrlhandle, devhandle, isdisabled, speed, minspeed, maxspeed, type); } free(sas0); free(sas1); printf("\n"); close(fd); return (0); } MPS_COMMAND(show, adapter, show_adapter, "", "display controller information") static int show_iocfacts(int ac, char **av) { MPI2_IOC_FACTS_REPLY *facts; uint8_t *fb; char tmpbuf[128]; int error, fd; fd = mps_open(mps_unit); if (fd < 0) { error = errno; warn("mps_open"); return (error); } if ((facts = mps_get_iocfacts(fd)) == NULL) { printf("could not get controller IOCFacts\n"); close(fd); return (errno); } fb = (uint8_t *)facts; #define IOCCAP "\3ScsiTaskFull" "\4DiagTrace" "\5SnapBuf" "\6ExtBuf" \ "\7EEDP" "\10BiDirTarg" "\11Multicast" "\14TransRetry" "\15IR" \ "\16EventReplay" "\17RaidAccel" "\20MSIXIndex" "\21HostDisc" \ "\22FastPath" "\23RDPQArray" "\24AtomicReqDesc" "\25PCIeSRIOV" bzero(tmpbuf, sizeof(tmpbuf)); mps_parse_flags(facts->IOCCapabilities, IOCCAP, tmpbuf, sizeof(tmpbuf)); printf(" MsgVersion: %d.%d\n", facts->MsgVersion >> 8, facts->MsgVersion & 0xff); printf(" MsgLength: %d\n", facts->MsgLength); printf(" Function: 0x%x\n", facts->Function); printf(" HeaderVersion: %02d,%02d\n", facts->HeaderVersion >> 8, facts->HeaderVersion & 0xff); printf(" IOCNumber: %d\n", facts->IOCNumber); printf(" MsgFlags: 0x%x\n", facts->MsgFlags); printf(" VP_ID: %d\n", facts->VP_ID); printf(" VF_ID: %d\n", facts->VF_ID); printf(" IOCExceptions: %d\n", facts->IOCExceptions); printf(" IOCStatus: %d\n", facts->IOCStatus); printf(" IOCLogInfo: 0x%x\n", facts->IOCLogInfo); printf(" MaxChainDepth: %d\n", facts->MaxChainDepth); printf(" WhoInit: 0x%x\n", facts->WhoInit); printf(" NumberOfPorts: %d\n", facts->NumberOfPorts); printf(" MaxMSIxVectors: %d\n", facts->MaxMSIxVectors); printf(" RequestCredit: %d\n", facts->RequestCredit); printf(" ProductID: 0x%x\n", facts->ProductID); printf(" IOCCapabilities: 0x%x %s\n", facts->IOCCapabilities, tmpbuf); printf(" FWVersion: %02d.%02d.%02d.%02d\n", facts->FWVersion.Struct.Major, facts->FWVersion.Struct.Minor, facts->FWVersion.Struct.Unit, facts->FWVersion.Struct.Dev); printf(" IOCRequestFrameSize: %d\n", facts->IOCRequestFrameSize); if (is_mps == 0) printf(" MaxChainSegmentSize: %d\n", (uint16_t)(fb[0x26])); printf(" MaxInitiators: %d\n", facts->MaxInitiators); printf(" MaxTargets: %d\n", facts->MaxTargets); printf(" MaxSasExpanders: %d\n", facts->MaxSasExpanders); printf(" MaxEnclosures: %d\n", facts->MaxEnclosures); bzero(tmpbuf, sizeof(tmpbuf)); mps_parse_flags(facts->ProtocolFlags, "\4NvmeDevices\2ScsiTarget\1ScsiInitiator", tmpbuf, sizeof(tmpbuf)); printf(" ProtocolFlags: 0x%x %s\n", facts->ProtocolFlags, tmpbuf); printf(" HighPriorityCredit: %d\n", facts->HighPriorityCredit); printf("MaxRepDescPostQDepth: %d\n", facts->MaxReplyDescriptorPostQueueDepth); printf(" ReplyFrameSize: %d\n", facts->ReplyFrameSize); printf(" MaxVolumes: %d\n", facts->MaxVolumes); printf(" MaxDevHandle: %d\n", facts->MaxDevHandle); printf("MaxPersistentEntries: %d\n", facts->MaxPersistentEntries); printf(" MinDevHandle: %d\n", facts->MinDevHandle); if (is_mps == 0) printf(" CurrentHostPageSize: %d\n", (uint8_t)(fb[0x3e])); free(facts); return (0); } MPS_COMMAND(show, iocfacts, show_iocfacts, "", "Show IOC Facts Message"); static int show_adapters(int ac, char **av) { MPI2_CONFIG_PAGE_MAN_0 *man0; MPI2_IOC_FACTS_REPLY *facts; int unit, fd, error; printf("Device Name\t Chip Name Board Name Firmware\n"); for (unit = 0; unit < MPS_MAX_UNIT; unit++) { fd = mps_open(unit); if (fd < 0) continue; facts = mps_get_iocfacts(fd); if (facts == NULL) { error = errno; warn("Faled to get controller iocfacts"); close(fd); return (error); } man0 = mps_read_man_page(fd, 0, NULL); if (man0 == NULL) { error = errno; warn("Failed to get controller info"); close(fd); free(facts); return (error); } if (man0->Header.PageLength < sizeof(*man0) / 4) { warnx("Invalid controller info"); close(fd); free(man0); free(facts); return (EINVAL); } printf("/dev/mp%s%d\t%16s %16s %08x\n", is_mps ? "s": "r", unit, man0->ChipName, man0->BoardName, facts->FWVersion.Word); free(man0); free(facts); close(fd); } return (0); } MPS_COMMAND(show, adapters, show_adapters, "", "Show a summary of all adapters"); static char * get_device_type(uint32_t di) { if (di & 0x4000) return ("SEP Target "); if (di & 0x2000) return ("ATAPI Target "); if (di & 0x400) return ("SAS Target "); if (di & 0x200) return ("STP Target "); if (di & 0x100) return ("SMP Target "); if (di & 0x80) return ("SATA Target "); if (di & 0x70) return ("SAS Initiator "); if (di & 0x8) return ("SATA Initiator"); if ((di & 0x7) == 0) return ("No Device "); return ("Unknown Device"); } static char * get_enc_type(uint32_t flags, int *issep) { char *type; *issep = 0; switch (flags & 0xf) { case 0x01: type = "Direct Attached SES-2"; *issep = 1; break; case 0x02: type = "Direct Attached SGPIO"; break; case 0x03: type = "Expander SGPIO"; break; case 0x04: type = "External SES-2"; *issep = 1; break; case 0x05: type = "Direct Attached GPIO"; break; case 0x0: default: return ("Unknown"); } return (type); } static char * mps_device_speed[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "1.5", "3.0", "6.0", "12 " }; static char * get_device_speed(uint8_t rate) { char *speed; rate &= 0xf; if (rate >= sizeof(mps_device_speed)) return ("Unk"); if ((speed = mps_device_speed[rate]) == NULL) return ("???"); return (speed); } static char * mps_page_name[] = { "IO Unit", "IOC", "BIOS", NULL, NULL, NULL, NULL, NULL, "RAID Volume", "Manufacturing", "RAID Physical Disk", NULL, NULL, NULL, NULL, NULL, "SAS IO Unit", "SAS Expander", "SAS Device", "SAS PHY", "Log", "Enclosure", "RAID Configuration", "Driver Persistent Mapping", "SAS Port", "Ethernet Port", "Extended Manufacturing" }; static char * get_page_name(u_int page) { char *name; if (page >= sizeof(mps_page_name)) return ("Unknown"); if ((name = mps_page_name[page]) == NULL) return ("Unknown"); return (name); } static int show_all(int ac, char **av) { int error; printf("Adapter:\n"); error = show_adapter(ac, av); printf("Devices:\n"); error = show_devices(ac, av); printf("Enclosures:\n"); error = show_enclosures(ac, av); printf("Expanders:\n"); error = show_expanders(ac, av); return (error); } MPS_COMMAND(show, all, show_all, "", "Show all devices"); static int show_devices(int ac, char **av) { MPI2_CONFIG_PAGE_SASIOUNIT_0 *sas0; MPI2_SAS_IO_UNIT0_PHY_DATA *phydata; MPI2_CONFIG_PAGE_SAS_DEV_0 *device; MPI2_CONFIG_PAGE_EXPANDER_1 *exp1; uint16_t IOCStatus, handle, bus, target; char *type, *speed, enchandle[5], slot[3], bt[8]; char buf[256]; int fd, error, nphys; fd = mps_open(mps_unit); if (fd < 0) { error = errno; warn("mps_open"); return (error); } sas0 = mps_read_extended_config_page(fd, MPI2_CONFIG_EXTPAGETYPE_SAS_IO_UNIT, MPI2_SASIOUNITPAGE0_PAGEVERSION, 0, 0, &IOCStatus); if (sas0 == NULL) { error = errno; warn("Error retrieving SAS IO Unit page %d", IOCStatus); return (error); } nphys = sas0->NumPhys; printf("B____%-5s%-17s%-8s%-10s%-14s%-6s%-5s%-6s%s\n", "T", "SAS Address", "Handle", "Parent", "Device", "Speed", "Enc", "Slot", "Wdt"); handle = 0xffff; while (1) { device = mps_read_extended_config_page(fd, MPI2_CONFIG_EXTPAGETYPE_SAS_DEVICE, MPI2_SASDEVICE0_PAGEVERSION, 0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE | handle, &IOCStatus); if (device == NULL) { if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) break; error = errno; warn("Error retrieving device page"); close(fd); return (error); } - handle = device->DevHandle; + handle = le16toh(device->DevHandle); if (device->ParentDevHandle == 0x0) { free(device); continue; } bus = 0xffff; target = 0xffff; error = mps_map_btdh(fd, &handle, &bus, &target); if (error) { free(device); continue; } if ((bus == 0xffff) || (target == 0xffff)) snprintf(bt, sizeof(bt), " "); else snprintf(bt, sizeof(bt), "%02d %02d", bus, target); - type = get_device_type(device->DeviceInfo); + type = get_device_type(le32toh(device->DeviceInfo)); if (device->PhyNum < nphys) { phydata = &sas0->PhyData[device->PhyNum]; speed = get_device_speed(phydata->NegotiatedLinkRate); } else if (device->ParentDevHandle > 0) { exp1 = mps_read_extended_config_page(fd, MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER, MPI2_SASEXPANDER1_PAGEVERSION, 1, MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM | (device->PhyNum << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) | - device->ParentDevHandle, &IOCStatus); + le16toh(device->ParentDevHandle), &IOCStatus); if (exp1 == NULL) { if (IOCStatus != MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) { error = errno; warn("Error retrieving expander page 1: 0x%x", IOCStatus); close(fd); free(device); return (error); } speed = " "; } else { speed = get_device_speed(exp1->NegotiatedLinkRate); free(exp1); } } else speed = " "; if (device->EnclosureHandle != 0) { - snprintf(enchandle, 5, "%04x", device->EnclosureHandle); - snprintf(slot, 3, "%02d", device->Slot); + snprintf(enchandle, 5, "%04x", le16toh(device->EnclosureHandle)); + snprintf(slot, 3, "%02d", le16toh(device->Slot)); } else { snprintf(enchandle, 5, " "); snprintf(slot, 3, " "); } printf("%-10s", bt); - snprintf(buf, sizeof(buf), "%08x%08x", device->SASAddress.High, - device->SASAddress.Low); + snprintf(buf, sizeof(buf), "%08x%08x", le32toh(device->SASAddress.High), + le32toh(device->SASAddress.Low)); printf("%-17s", buf); - snprintf(buf, sizeof(buf), "%04x", device->DevHandle); + snprintf(buf, sizeof(buf), "%04x", le16toh(device->DevHandle)); printf("%-8s", buf); - snprintf(buf, sizeof(buf), "%04x", device->ParentDevHandle); + snprintf(buf, sizeof(buf), "%04x", le16toh(device->ParentDevHandle)); printf("%-10s", buf); printf("%-14s%-6s%-5s%-6s%d\n", type, speed, enchandle, slot, device->MaxPortConnections); free(device); } printf("\n"); free(sas0); close(fd); return (0); } MPS_COMMAND(show, devices, show_devices, "", "Show attached devices"); static int show_enclosures(int ac, char **av) { MPI2_CONFIG_PAGE_SAS_ENCLOSURE_0 *enc; char *type, sepstr[5]; uint16_t IOCStatus, handle; int fd, error, issep; fd = mps_open(mps_unit); if (fd < 0) { error = errno; warn("mps_open"); return (error); } printf("Slots Logical ID SEPHandle EncHandle Type\n"); handle = 0xffff; while (1) { enc = mps_read_extended_config_page(fd, MPI2_CONFIG_EXTPAGETYPE_ENCLOSURE, MPI2_SASENCLOSURE0_PAGEVERSION, 0, MPI2_SAS_ENCLOS_PGAD_FORM_GET_NEXT_HANDLE | handle, &IOCStatus); if (enc == NULL) { if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) break; error = errno; warn("Error retrieving enclosure page"); close(fd); return (error); } - type = get_enc_type(enc->Flags, &issep); + type = get_enc_type(le16toh(enc->Flags), &issep); if (issep == 0) snprintf(sepstr, 5, " "); else - snprintf(sepstr, 5, "%04x", enc->SEPDevHandle); + snprintf(sepstr, 5, "%04x", le16toh(enc->SEPDevHandle)); printf(" %.2d %08x%08x %s %04x %s\n", - enc->NumSlots, enc->EnclosureLogicalID.High, - enc->EnclosureLogicalID.Low, sepstr, enc->EnclosureHandle, + le16toh(enc->NumSlots), le32toh(enc->EnclosureLogicalID.High), + le32toh(enc->EnclosureLogicalID.Low), sepstr, le16toh(enc->EnclosureHandle), type); - handle = enc->EnclosureHandle; + handle = le16toh(enc->EnclosureHandle); free(enc); } printf("\n"); close(fd); return (0); } MPS_COMMAND(show, enclosures, show_enclosures, "", "Show attached enclosures"); static int show_expanders(int ac, char **av) { MPI2_CONFIG_PAGE_EXPANDER_0 *exp0; MPI2_CONFIG_PAGE_EXPANDER_1 *exp1; uint16_t IOCStatus, handle; char enchandle[5], parent[5], rphy[3], rhandle[5]; char *speed, *min, *max, *type; int fd, error, nphys, i; fd = mps_open(mps_unit); if (fd < 0) { error = errno; warn("mps_open"); return (error); } printf("NumPhys SAS Address DevHandle Parent EncHandle SAS Level\n"); handle = 0xffff; while (1) { exp0 = mps_read_extended_config_page(fd, MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER, MPI2_SASEXPANDER0_PAGEVERSION, 0, MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL | handle, &IOCStatus); if (exp0 == NULL) { if (IOCStatus == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) break; error = errno; warn("Error retrieving expander page 0"); close(fd); return (error); } nphys = exp0->NumPhys; - handle = exp0->DevHandle; + handle = le16toh(exp0->DevHandle); if (exp0->EnclosureHandle == 0x00) snprintf(enchandle, 5, " "); else - snprintf(enchandle, 5, "%04d", exp0->EnclosureHandle); + snprintf(enchandle, 5, "%04d", le16toh(exp0->EnclosureHandle)); if (exp0->ParentDevHandle == 0x0) snprintf(parent, 5, " "); else - snprintf(parent, 5, "%04x", exp0->ParentDevHandle); + snprintf(parent, 5, "%04x", le16toh(exp0->ParentDevHandle)); printf(" %02d %08x%08x %04x %s %s %d\n", - exp0->NumPhys, exp0->SASAddress.High, exp0->SASAddress.Low, - exp0->DevHandle, parent, enchandle, exp0->SASLevel); + exp0->NumPhys, le32toh(exp0->SASAddress.High), le32toh(exp0->SASAddress.Low), + le16toh(exp0->DevHandle), parent, enchandle, exp0->SASLevel); printf("\n"); printf(" Phy RemotePhy DevHandle Speed Min Max Device\n"); for (i = 0; i < nphys; i++) { exp1 = mps_read_extended_config_page(fd, MPI2_CONFIG_EXTPAGETYPE_SAS_EXPANDER, MPI2_SASEXPANDER1_PAGEVERSION, 1, MPI2_SAS_EXPAND_PGAD_FORM_HNDL_PHY_NUM | (i << MPI2_SAS_EXPAND_PGAD_PHYNUM_SHIFT) | exp0->DevHandle, &IOCStatus); if (exp1 == NULL) { if (IOCStatus != MPI2_IOCSTATUS_CONFIG_INVALID_PAGE) warn("Error retrieving expander pg 1"); continue; } - type = get_device_type(exp1->AttachedDeviceInfo); - if ((exp1->AttachedDeviceInfo &0x7) == 0) { + type = get_device_type(le32toh(exp1->AttachedDeviceInfo)); + if ((le32toh(exp1->AttachedDeviceInfo) &0x7) == 0) { speed = " "; snprintf(rphy, 3, " "); snprintf(rhandle, 5, " "); } else { speed = get_device_speed( exp1->NegotiatedLinkRate); snprintf(rphy, 3, "%02d", exp1->AttachedPhyIdentifier); snprintf(rhandle, 5, "%04x", - exp1->AttachedDevHandle); + le16toh(exp1->AttachedDevHandle)); } min = get_device_speed(exp1->HwLinkRate); max = get_device_speed(exp1->HwLinkRate >> 4); printf(" %02d %s %s %s %s %s %s\n", exp1->Phy, rphy, rhandle, speed, min, max, type); free(exp1); } free(exp0); } printf("\n"); close(fd); return (0); } MPS_COMMAND(show, expanders, show_expanders, "", "Show attached expanders"); static int show_cfgpage(int ac, char **av) { MPI2_CONFIG_PAGE_HEADER *hdr; MPI2_CONFIG_EXTENDED_PAGE_HEADER *ehdr; void *data; uint32_t addr; uint16_t IOCStatus; uint8_t page, num; int fd, error, len, attrs; char *pgname, *pgattr; fd = mps_open(mps_unit); if (fd < 0) { error = errno; warn("mps_open"); return (error); } addr = 0; num = 0; page = 0; switch (ac) { case 4: - addr = (uint32_t)strtoul(av[3], NULL, 0); + addr = htole32((uint32_t)strtoul(av[3], NULL, 0)); case 3: num = (uint8_t)strtoul(av[2], NULL, 0); case 2: page = (uint8_t)strtoul(av[1], NULL, 0); break; default: errno = EINVAL; warn("cfgpage: not enough arguments"); return (EINVAL); } if (page >= 0x10) data = mps_read_extended_config_page(fd, page, 0, num, addr, &IOCStatus); else data = mps_read_config_page(fd, page, num, addr, &IOCStatus); if (data == NULL) { error = errno; warn("Error retrieving cfg page: %s\n", mps_ioc_status(IOCStatus)); return (error); } if (page >= 0x10) { ehdr = data; - len = ehdr->ExtPageLength * 4; + len = le16toh(ehdr->ExtPageLength) * 4; page = ehdr->ExtPageType; attrs = ehdr->PageType >> 4; } else { hdr = data; len = hdr->PageLength * 4; page = hdr->PageType & 0xf; attrs = hdr->PageType >> 4; } pgname = get_page_name(page); if (attrs == 0) pgattr = "Read-only"; else if (attrs == 1) pgattr = "Read-Write"; else if (attrs == 2) pgattr = "Read-Write Persistent"; else pgattr = "Unknown Page Attribute"; printf("Page 0x%x: %s %d, %s\n", page, pgname, num, pgattr); hexdump(data, len, NULL, HD_REVERSED | 4); free(data); close(fd); return (0); } MPS_COMMAND(show, cfgpage, show_cfgpage, "page [num] [addr]", "Display config page"); diff --git a/usr.sbin/mpsutil/mps_slot.c b/usr.sbin/mpsutil/mps_slot.c index 1879d699067a..bb4a7324c461 100644 --- a/usr.sbin/mpsutil/mps_slot.c +++ b/usr.sbin/mpsutil/mps_slot.c @@ -1,114 +1,116 @@ /*- * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2019 Andriy Gapon * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __RCSID("$FreeBSD$"); #include #include #include +#include #include #include #include #include #include #include #include #include #include "mpsutil.h" MPS_TABLE(top, slot); static int slot_set(int argc, char **argv) { char *endptr; unsigned long ux; long x; int error; int fd; U32 status; U16 handle; U16 slot; if (argc != 5) { warnx("Incorrect number of arguments"); return (EINVAL); } if (strcmp(argv[1], "status") != 0) { warnx("Invalid argument '%s', expecting 'status'", argv[1]); return (EINVAL); } errno = 0; x = strtol(argv[2], &endptr, 0); if (*endptr != '\0' || errno != 0 || x < 0 || x > UINT16_MAX) { warnx("Invalid enclosure handle argument '%s'", argv[2]); return (EINVAL); } handle = x; errno = 0; x = strtol(argv[3], &endptr, 0); if (*endptr != '\0' || errno != 0 || x < 0 || x > UINT16_MAX) { warnx("Invalid slot argument '%s'", argv[3]); return (EINVAL); } slot = x; errno = 0; ux = strtoul(argv[4], &endptr, 0); if (*endptr != '\0' || errno != 0 || ux > UINT32_MAX) { warnx("Invalid status argument '%s'", argv[4]); return (EINVAL); } status = ux; fd = mps_open(mps_unit); if (fd < 0) { error = errno; warn("mps_open"); return (error); } - if (mps_set_slot_status(fd, handle, slot, status) != 0) { + if (mps_set_slot_status(fd, htole16(handle), htole16(slot), + htole32(status)) != 0) { warnx("Failed to set status"); close(fd); return (1); } close(fd); printf("Successfully set slot status\n"); return (0); } MPS_COMMAND(slot, set, slot_set, "status " "", "Set status of the slot in the directly attached enclosure"); diff --git a/usr.sbin/mpsutil/mpsutil.8 b/usr.sbin/mpsutil/mpsutil.8 index 1dd4f0509174..1bb7c4d5eaec 100644 --- a/usr.sbin/mpsutil/mpsutil.8 +++ b/usr.sbin/mpsutil/mpsutil.8 @@ -1,165 +1,168 @@ .\" .\" Copyright (c) Baptiste Daroussin .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" .Dd March 25, 2021 .Dt MPSUTIL 8 .Os .Sh NAME .Nm mpsutil , .Nm mprutil .Nd Utility for managing LSI Fusion-MPT 2/3 controllers .Sh SYNOPSIS .Nm .Cm version .Nm .Op Fl u Ar unit .Cm show adapter .Nm .Op Fl u Ar unit .Cm show adapters .Nm .Op Fl u Ar unit .Cm show all .Nm .Op Fl u Ar unit .Cm show cfgpage page .Op Ar num .Op Ar addr .Nm .Op Fl u Ar unit .Cm show devices .Nm .Op Fl u Ar unit .Cm show enclosures .Nm .Op Fl u Ar unit .Cm show expanders .Nm .Op Fl u Ar unit .Cm show iocfacts .Nm .Op Fl u Ar unit .Cm flash save .Op Ar firmware Ns | Ns Ar bios .Op Ar file .Nm .Op Fl u Ar unit .Cm flash update .Op Ar firmware Ns | Ns Ar bios .Ar file .Sh DESCRIPTION The .Nm utility can be used to display or modify various parameters on LSI Fusion-MPS 2 controllers. .Pp The .Nm mprutil utility can be used to display or modify various parameters on LSI Fusion-MPS 3 controllers. .Pp The .Nm mprutil utility behave identically to .Nm . (same program) .Pp Each invocation of .Nm consists of zero or more global options followed by a command. Commands may support additional optional or required arguments after the command. .Pp Currently one global option is supported: .Bl -tag -width indent .It Fl u Ar unit .Ar unit specifies the unit of the controller to work with. If no unit is specified, then unit 0 is used. .El .Pp The .Nm utility supports several different groups of commands. The first group of commands provide information about the controller. The second group of commands are used to manager controller-wide operations. .Pp The informational commands include: .Bl -tag -width indent .It Cm version Displays the version of .Nm . .It Cm show adapter Displays information about the controller such as the model number or firmware version. .It Cm show adapters Displays a summary of all adapters. .It Cm show all Displays all devices, expanders and enclosures. .It Cm show devices Displays all devices. .It Cm show expanders Displays all expanders. .It Cm show enclosures Displays all enclosures. .It Cm show iocfacts Displays IOC Facts messages. .It Cm show cfgpage page Oo Ar num Oc Op Ar addr Dump raw config page in hex. .El .Pp Controller management commands include: .Bl -tag -width indent .It Cm flash save Oo Ar firmware Ns | Ns Ar bios Oc Op Ar file Save the .Ar firmware or .Ar bios from the controller into a local .Ar file . If no .Ar file is specified then the file will be named .Pa firmware or .Pa bios . .It Cm flash update Oo Ar firmware Ns | Ns Ar bios Oc Ar file Replace the .Ar firmware or .Ar bios from the controller with the one specified via .Ar file . .El .Sh SEE ALSO .Xr mpr 4 , .Xr mps 4 .Sh HISTORY The .Nm utility first appeared in .Fx 11.0 . +.Sh TODO +Flash operations (save/update) are not supported on big-endian architectures. +.Pp