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