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
This commit is contained in:
Daniel Austin 2021-05-07 14:41:53 +03:00 committed by Andriy Gapon
parent 95a74ab4fb
commit e2ea6942ab
4 changed files with 171 additions and 2 deletions

View File

@ -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

129
usr.sbin/mpsutil/mps_set.c Normal file
View File

@ -0,0 +1,129 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2021 Daniel Austin <freebsd-ports@dan.me.uk>
*
* 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 <sys/cdefs.h>
__RCSID("$FreeBSD$");
#include <sys/param.h>
#include <sys/errno.h>
#include <err.h>
#include <libutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#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")

View File

@ -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;

View File

@ -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