View | Details | Raw Unified | Return to bug 254841 | Differences between
and this patch

Collapse All | Expand All

(-)b/usr.sbin/mpsutil/Makefile (-1 / +1 lines)
Lines 1-7 Link Here
1
# $FreeBSD$
1
# $FreeBSD$
2
2
3
PROG=	mpsutil
3
PROG=	mpsutil
4
SRCS=	mps_cmd.c mps_debug.c mps_flash.c mps_show.c mps_slot.c mpsutil.c
4
SRCS=	mps_cmd.c mps_debug.c mps_flash.c mps_set.c mps_show.c mps_slot.c mpsutil.c
5
MAN=	mpsutil.8
5
MAN=	mpsutil.8
6
6
7
WARNS?= 3
7
WARNS?= 3
(-)b/usr.sbin/mpsutil/mps_set.c (+135 lines)
Added Link Here
1
/*-
2
 * Copyright (c) 2015 Netflix, Inc.
3
 * Written by: Scott Long <scottl@freebsd.org>
4
 *
5
 * Copyright (c) 2008 Yahoo!, Inc.
6
 * All rights reserved.
7
 * Written by: John Baldwin <jhb@FreeBSD.org>
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions
11
 * are met:
12
 * 1. Redistributions of source code must retain the above copyright
13
 *    notice, this list of conditions and the following disclaimer.
14
 * 2. Redistributions in binary form must reproduce the above copyright
15
 *    notice, this list of conditions and the following disclaimer in the
16
 *    documentation and/or other materials provided with the distribution.
17
 * 3. Neither the name of the author nor the names of any co-contributors
18
 *    may be used to endorse or promote products derived from this software
19
 *    without specific prior written permission.
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31
 * SUCH DAMAGE.
32
 */
33
34
#include <sys/cdefs.h>
35
__RCSID("$FreeBSD$");
36
37
#include <sys/param.h>
38
#include <sys/errno.h>
39
#include <err.h>
40
#include <libutil.h>
41
#include <stdio.h>
42
#include <stdlib.h>
43
#include <string.h>
44
#include <unistd.h>
45
#include "mpsutil.h"
46
47
static int set_ncq(int ac, char **av);
48
49
MPS_TABLE(top, set);
50
51
static int
52
set_ncq(int ac, char **av)
53
{
54
	MPI2_CONFIG_PAGE_HEADER header;
55
	MPI2_CONFIG_PAGE_IO_UNIT_1 *iounit1;
56
	MPI2_CONFIG_REQUEST req;
57
	MPI2_CONFIG_REPLY reply;
58
	int error, fd;
59
60
	bzero(&req, sizeof(req));
61
	bzero(&header, sizeof(header));
62
	bzero(&reply, sizeof(reply));
63
64
	fd = mps_open(mps_unit);
65
	if (fd < 0) {
66
		error = errno;
67
		warn("mps_open");
68
		return (error);
69
	}
70
71
	error = mps_read_config_page_header(fd, MPI2_CONFIG_PAGETYPE_IO_UNIT, 1, 0,
72
		&header, NULL);
73
	if (error) {
74
			error = errno;
75
			warn("Failed to get IOUNIT page 1 header");
76
			return (error);
77
	}
78
79
	iounit1 = mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_IO_UNIT, 1, 0, NULL);
80
	if (iounit1 == NULL) {
81
		error = errno;
82
		warn("Failed to get IOUNIT page 1 info");
83
		return (error);
84
	}
85
86
	if (ac == 1) {
87
		/* just show current setting */
88
		printf("SATA Native Command Queueing is currently: %s\n",
89
			((iounit1->Flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE) == 0) ?
90
			"ENABLED" : "DISABLED");
91
	} else if (ac == 2) {
92
		if (!strcasecmp(av[1], "enable") || !strcmp(av[1], "1")) {
93
			iounit1->Flags &= ~MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE;
94
		} else if (!strcasecmp(av[1], "disable") || !strcmp(av[1], "0")) {
95
			iounit1->Flags |= MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE;
96
		} else {
97
			free(iounit1);
98
			error = EINVAL;
99
			warn("set ncq: Only 'enable' and 'disable' allowed.");
100
			return (EINVAL);
101
		}
102
		req.Function = MPI2_FUNCTION_CONFIG;
103
		req.Action = MPI2_CONFIG_ACTION_PAGE_WRITE_CURRENT;
104
		req.ExtPageLength = 0;
105
		req.ExtPageType = 0;
106
		req.Header = header;
107
		req.PageAddress = 0;
108
		if (mps_pass_command(fd, &req, sizeof(req) - sizeof(req.PageBufferSGE), &reply, sizeof(reply),
109
			NULL, 0, iounit1, sizeof(iounit1), 30) != 0) {
110
				free(iounit1);
111
				error = errno;
112
				warn("Failed to update config page");
113
		                return (error);
114
		}
115
		if (!IOC_STATUS_SUCCESS(reply.IOCStatus)) {
116
			free(iounit1);
117
			error = errno;
118
			warn("%s", mps_ioc_status(reply.IOCStatus));
119
			return (error);
120
		}
121
		printf("NCQ setting accepted.  It may not take effect until the controller is reset.\n");
122
	} else {
123
		free(iounit1);
124
		errno = EINVAL;
125
		warn("set ncq: too many arguments");
126
		return (EINVAL);
127
	}
128
	free(iounit1);
129
130
	close(fd);
131
	return (0);
132
}
133
134
MPS_COMMAND(set, ncq, set_ncq, "", "set SATA NCQ function")
135
(-)b/usr.sbin/mpsutil/mps_show.c (+34 lines)
Lines 58-69 MPS_TABLE(top, show); Link Here
58
static int
58
static int
59
show_adapter(int ac, char **av)
59
show_adapter(int ac, char **av)
60
{
60
{
61
	const char* pcie_speed[] = { "2.5", "5.0", "8.0" };
62
	const char* temp_units[] = { "", "F", "C" };
63
	const char* ioc_speeds[] = { "", "Full", "Half", "Quarter", "Eighth" };
64
61
	MPI2_CONFIG_PAGE_SASIOUNIT_0	*sas0;
65
	MPI2_CONFIG_PAGE_SASIOUNIT_0	*sas0;
62
	MPI2_CONFIG_PAGE_SASIOUNIT_1	*sas1;
66
	MPI2_CONFIG_PAGE_SASIOUNIT_1	*sas1;
63
	MPI2_SAS_IO_UNIT0_PHY_DATA	*phy0;
67
	MPI2_SAS_IO_UNIT0_PHY_DATA	*phy0;
64
	MPI2_SAS_IO_UNIT1_PHY_DATA	*phy1;
68
	MPI2_SAS_IO_UNIT1_PHY_DATA	*phy1;
65
	MPI2_CONFIG_PAGE_MAN_0 *man0;
69
	MPI2_CONFIG_PAGE_MAN_0 *man0;
66
	MPI2_CONFIG_PAGE_BIOS_3 *bios3;
70
	MPI2_CONFIG_PAGE_BIOS_3 *bios3;
71
	MPI2_CONFIG_PAGE_IO_UNIT_1 *iounit1;
72
	MPI2_CONFIG_PAGE_IO_UNIT_7 *iounit7;
67
	MPI2_IOC_FACTS_REPLY *facts;
73
	MPI2_IOC_FACTS_REPLY *facts;
68
	U16 IOCStatus;
74
	U16 IOCStatus;
69
	char *speed, *minspeed, *maxspeed, *isdisabled, *type;
75
	char *speed, *minspeed, *maxspeed, *isdisabled, *type;
Lines 125-130 show_adapter(int ac, char **av) Link Here
125
	    ? "yes" : "no");
131
	    ? "yes" : "no");
126
	free(facts);
132
	free(facts);
127
133
134
	iounit1 = mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_IO_UNIT, 1, 0, NULL);
135
	if (iounit1 == NULL) {
136
		error = errno;
137
		warn("Failed to get IOUNIT page 1 info");
138
		return (error);
139
	}
140
	printf("         SATA NCQ: %s\n",
141
		((iounit1->Flags & MPI2_IOUNITPAGE1_NATIVE_COMMAND_Q_DISABLE) == 0) ?
142
		"ENABLED" : "DISABLED");
143
	free(iounit1);
144
145
	iounit7 = mps_read_config_page(fd, MPI2_CONFIG_PAGETYPE_IO_UNIT, 7, 0, NULL);
146
	if (iounit7 == NULL) {
147
		error = errno;
148
		warn("Failed to get IOUNIT page 7 info");
149
		return (error);
150
	}
151
	printf(" PCIe Width/Speed: x%d (%s GB/sec)\n", iounit7->PCIeWidth,
152
		pcie_speed[iounit7->PCIeSpeed]);
153
	printf("        IOC Speed: %s\n", ioc_speeds[iounit7->IOCSpeed]);
154
	printf("      Temperature: ");
155
	if (iounit7->IOCTemperatureUnits == MPI2_IOUNITPAGE7_IOC_TEMP_NOT_PRESENT)
156
		printf("Unknown/Unsupported\n");
157
	else
158
		printf("%d %s\n", iounit7->IOCTemperature,
159
			temp_units[iounit7->IOCTemperatureUnits]);
160
	free(iounit7);
161
128
	fd = mps_open(mps_unit);
162
	fd = mps_open(mps_unit);
129
	if (fd < 0) {
163
	if (fd < 0) {
130
		error = errno;
164
		error = errno;

Return to bug 254841