From owner-dev-commits-src-branches@freebsd.org Fri May 21 10:30:02 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 040EE656C19; Fri, 21 May 2021 10:30:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FmjXn6m8hz3tVc; Fri, 21 May 2021 10:30:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C653D77D8; Fri, 21 May 2021 10:30:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 14LAU1H3053150; Fri, 21 May 2021 10:30:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 14LAU1Id053148; Fri, 21 May 2021 10:30:01 GMT (envelope-from git) Date: Fri, 21 May 2021 10:30:01 GMT Message-Id: <202105211030.14LAU1Id053148@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andriy Gapon Subject: git: 395bc3598b47 - stable/13 - mpsutil: extend show adapter information, add NCQ control MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: avg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 395bc3598b47ef270d17beae778830e134814fbe Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 May 2021 10:30:02 -0000 The branch stable/13 has been updated by avg: URL: https://cgit.FreeBSD.org/src/commit/?id=395bc3598b47ef270d17beae778830e134814fbe commit 395bc3598b47ef270d17beae778830e134814fbe Author: Daniel Austin AuthorDate: 2021-05-07 11:41:53 +0000 Commit: Andriy Gapon CommitDate: 2021-05-21 10:29:17 +0000 mpsutil: extend show adapter information, add NCQ control 'show adapter' now shows PCIe width and speed, IOC Speed, and the temperature of the controller. A new command, 'set ncq', is added. It enables or disables SATA NCQ in the NVRAM of the card. Its current setting is added to 'show adapter' as well. PR: 254841 MFC after: 2 weeks Relnotes: perhaps (cherry picked from commit e2ea6942ab316d4cd5c2fef73ab28dc974b8dc51) --- usr.sbin/mpsutil/Makefile | 2 +- usr.sbin/mpsutil/mps_set.c | 129 ++++++++++++++++++++++++++++++++++++++++++++ usr.sbin/mpsutil/mps_show.c | 34 ++++++++++++ usr.sbin/mpsutil/mpsutil.8 | 8 ++- 4 files changed, 171 insertions(+), 2 deletions(-) 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..91e4d23ab78d --- /dev/null +++ b/usr.sbin/mpsutil/mps_set.c @@ -0,0 +1,129 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2021 Daniel Austin + * + * 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 "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, "[enable|disable]", "set SATA NCQ function") + diff --git a/usr.sbin/mpsutil/mps_show.c b/usr.sbin/mpsutil/mps_show.c index 620bb5e27f89..7c2596497818 100644 --- a/usr.sbin/mpsutil/mps_show.c +++ b/usr.sbin/mpsutil/mps_show.c @@ -59,12 +59,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; @@ -126,6 +132,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; diff --git a/usr.sbin/mpsutil/mpsutil.8 b/usr.sbin/mpsutil/mpsutil.8 index 1bb7c4d5eaec..e7c2fda8f84e 100644 --- a/usr.sbin/mpsutil/mpsutil.8 +++ b/usr.sbin/mpsutil/mpsutil.8 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd March 25, 2021 +.Dd May 7, 2021 .Dt MPSUTIL 8 .Os .Sh NAME @@ -62,6 +62,10 @@ .Cm show iocfacts .Nm .Op Fl u Ar unit +.Cm set ncq +.Op Ar enable Ns | Ns Ar disable +.Nm +.Op Fl u Ar unit .Cm flash save .Op Ar firmware Ns | Ns Ar bios .Op Ar file @@ -134,6 +138,8 @@ Dump raw config page in hex. .Pp Controller management commands include: .Bl -tag -width indent +.It Cm set ncq Oo Ar enable Ns | Ns Ar disable Oc +Enables or disables NCQ in the NVRAM of the card. .It Cm flash save Oo Ar firmware Ns | Ns Ar bios Oc Op Ar file Save the .Ar firmware