diff --git a/usr.sbin/mpsutil/Makefile b/usr.sbin/mpsutil/Makefile index dd99f5814565..0bc981366650 100644 --- a/usr.sbin/mpsutil/Makefile +++ b/usr.sbin/mpsutil/Makefile @@ -1,7 +1,7 @@ # $FreeBSD$ PROG= mpsutil -SRCS= mps_cmd.c mps_debug.c mps_flash.c mps_show.c mps_slot.c mpsutil.c +SRCS= mps_cmd.c mps_debug.c mps_flash.c mps_set.c mps_show.c mps_slot.c mpsutil.c MAN= mpsutil.8 WARNS?= 3 diff --git a/usr.sbin/mpsutil/mps_set.c b/usr.sbin/mpsutil/mps_set.c new file mode 100644 index 000000000000..2ce620331a06 --- /dev/null +++ b/usr.sbin/mpsutil/mps_set.c @@ -0,0 +1,135 @@ +/*- + * 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 "mpsutil.h" + +static int set_ncq(int ac, char **av); + +MPS_TABLE(top, set); + +static int +set_ncq(int ac, char **av) +{ + MPI2_CONFIG_PAGE_HEADER header; + MPI2_CONFIG_PAGE_IO_UNIT_1 *iounit1; + MPI2_CONFIG_REQUEST req; + MPI2_CONFIG_REPLY reply; + int error, fd; + + bzero(&req, sizeof(req)); + bzero(&header, sizeof(header)); + bzero(&reply, sizeof(reply)); + + fd = mps_open(mps_unit); + if (fd < 0) { + error = errno; + warn("mps_open"); + return (error); + } + + error = mps_read_config_page_header(fd, MPI2_CONFIG_PAGETYPE_IO_UNIT, 1, 0, + &header, NULL); + if (error) { + error = errno; + warn("Failed to get IOUNIT page 1 header"); + return (error); + } + + iounit1 = mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_IO_UNIT, 1, 0, NULL); + if (iounit1 == NULL) { + error = errno; + warn("Failed to get IOUNIT page 1 info"); + return (error); + } + + if (ac == 1) { + /* just show current setting */ + printf("SATA Native Command Queueing is currently: %s\n", + ((iounit1->Flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE) == 0) ? + "ENABLED" : "DISABLED"); + } else if (ac == 2) { + if (!strcasecmp(av[1], "enable") || !strcmp(av[1], "1")) { + iounit1->Flags &= ~MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE; + } else if (!strcasecmp(av[1], "disable") || !strcmp(av[1], "0")) { + iounit1->Flags |= MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE; + } else { + free(iounit1); + error = EINVAL; + warn("set ncq: Only 'enable' and 'disable' allowed."); + return (EINVAL); + } + req.Function = MPI2_FUNCTION_CONFIG; + req.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT; + req.ExtPageLength = 0; + req.ExtPageType = 0; + req.Header = header; + req.PageAddress = 0; + if (mps_pass_command(fd, &req, sizeof(req) - sizeof(req.PageBufferSGE), &reply, sizeof(reply), + NULL, 0, iounit1, sizeof(iounit1), 30) != 0) { + free(iounit1); + error = errno; + warn("Failed to update config page"); + return (error); + } + if (!IOC_STATUS_SUCCESS(reply.IOCStatus)) { + free(iounit1); + error = errno; + warn("%s", mps_ioc_status(reply.IOCStatus)); + return (error); + } + printf("NCQ setting accepted. It may not take effect until the controller is reset.\n"); + } else { + free(iounit1); + errno = EINVAL; + warn("set ncq: too many arguments"); + return (EINVAL); + } + free(iounit1); + + close(fd); + return (0); +} + +MPS_COMMAND(set, ncq, set_ncq, "", "set SATA NCQ function") + diff --git a/usr.sbin/mpsutil/mps_show.c b/usr.sbin/mpsutil/mps_show.c index bb790fe21229..d188c3dda550 100644 --- a/usr.sbin/mpsutil/mps_show.c +++ b/usr.sbin/mpsutil/mps_show.c @@ -58,12 +58,18 @@ MPS_TABLE(top, show); static int show_adapter(int ac, char **av) { + const char* pcie_speed[] = { "2.5", "5.0", "8.0" }; + const char* temp_units[] = { "", "F", "C" }; + const char* ioc_speeds[] = { "", "Full", "Half", "Quarter", "Eighth" }; + 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_CONFIG_PAGE_IO_UNIT_1 *iounit1; + MPI2_CONFIG_PAGE_IO_UNIT_7 *iounit7; MPI2_IOC_FACTS_REPLY *facts; U16 IOCStatus; char *speed, *minspeed, *maxspeed, *isdisabled, *type; @@ -125,6 +131,34 @@ show_adapter(int ac, char **av) ? "yes" : "no"); free(facts); + iounit1 = mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_IO_UNIT, 1, 0, NULL); + if (iounit1 == NULL) { + error = errno; + warn("Failed to get IOUNIT page 1 info"); + return (error); + } + printf(" SATA NCQ: %s\n", + ((iounit1->Flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE) == 0) ? + "ENABLED" : "DISABLED"); + free(iounit1); + + iounit7 = mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_IO_UNIT, 7, 0, NULL); + if (iounit7 == NULL) { + error = errno; + warn("Failed to get IOUNIT page 7 info"); + return (error); + } + printf(" PCIe Width/Speed: x%d (%s GB/sec)\n", iounit7->PCIeWidth, + pcie_speed[iounit7->PCIeSpeed]); + printf(" IOC Speed: %s\n", ioc_speeds[iounit7->IOCSpeed]); + printf(" Temperature: "); + if (iounit7->IOCTemperatureUnits == MPI2_IOUNITPAGE7_IOC_TEMP_NOT_PRESENT) + printf("Unknown/Unsupported\n"); + else + printf("%d %s\n", iounit7->IOCTemperature, + temp_units[iounit7->IOCTemperatureUnits]); + free(iounit7); + fd = mps_open(mps_unit); if (fd < 0) { error = errno;