1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause 3 * 4 * Copyright (c) 2013 Yahoo!, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 */ 29 30 #include <sys/errno.h> 31 #include <sys/ioctl.h> 32 #include <sys/param.h> 33 #include <sys/sysctl.h> 34 #include <sys/uio.h> 35 36 #include <err.h> 37 #include <fcntl.h> 38 #include <stdio.h> 39 #include <stdlib.h> 40 #include <string.h> 41 #include <unistd.h> 42 43 #include "mfiutil.h" 44 #include <dev/mfi/mfi_ioctl.h> 45 46 MFI_TABLE(top, ctrlprop); 47 48 static int 49 mfi_ctrl_get_properties(int fd, struct mfi_ctrl_props *info) 50 { 51 52 return (mfi_dcmd_command(fd, MFI_DCMD_CTRL_GET_PROPS, info, 53 sizeof(struct mfi_ctrl_props), NULL, 0, NULL)); 54 } 55 56 static int 57 mfi_ctrl_set_properties(int fd, struct mfi_ctrl_props *info) 58 { 59 60 return (mfi_dcmd_command(fd, MFI_DCMD_CTRL_SET_PROPS, info, 61 sizeof(struct mfi_ctrl_props), NULL, 0, NULL)); 62 } 63 64 /* 65 * Acquire the controller properties data structure, modify the 66 * rebuild rate if requested and then return 67 */ 68 static int 69 mfi_ctrl_rebuild_rate(int ac, char **av) 70 { 71 int error, fd; 72 struct mfi_ctrl_props ctrl_props; 73 74 if (ac > 2) { 75 warn("mfi_ctrl_set_rebuild_rate"); 76 return(-1); 77 } 78 79 fd = mfi_open(mfi_device, O_RDWR); 80 if (fd < 0) { 81 error = errno; 82 warn("mfi_open"); 83 return (error); 84 } 85 86 error = mfi_ctrl_get_properties(fd, &ctrl_props); 87 if ( error < 0) { 88 error = errno; 89 warn("Failed to get controller properties"); 90 close(fd); 91 return (error); 92 } 93 /* 94 * User requested a change to the rebuild rate 95 */ 96 if (ac > 1) { 97 ctrl_props.rebuild_rate = atoi(av[ac - 1]); 98 error = mfi_ctrl_set_properties(fd, &ctrl_props); 99 if ( error < 0) { 100 error = errno; 101 warn("Failed to set controller properties"); 102 close(fd); 103 return (error); 104 } 105 106 error = mfi_ctrl_get_properties(fd, &ctrl_props); 107 if ( error < 0) { 108 error = errno; 109 warn("Failed to get controller properties"); 110 close(fd); 111 return (error); 112 } 113 } 114 printf ("controller rebuild rate: %%%u \n", 115 ctrl_props.rebuild_rate); 116 return (0); 117 } 118 MFI_COMMAND(ctrlprop, rebuild, mfi_ctrl_rebuild_rate); 119 120 static int 121 mfi_ctrl_alarm_enable(int ac, char **av) 122 { 123 int error, fd; 124 struct mfi_ctrl_props ctrl_props; 125 126 if (ac > 2) { 127 warn("mfi_ctrl_alarm_enable"); 128 return(-1); 129 } 130 131 fd = mfi_open(mfi_device, O_RDWR); 132 if (fd < 0) { 133 error = errno; 134 warn("mfi_open"); 135 return (error); 136 } 137 138 error = mfi_ctrl_get_properties(fd, &ctrl_props); 139 if ( error < 0) { 140 error = errno; 141 warn("Failed to get controller properties"); 142 close(fd); 143 return (error); 144 } 145 printf ("controller alarm was : %s\n", 146 (ctrl_props.alarm_enable ? "enabled" : "disabled")); 147 148 if (ac > 1) { 149 ctrl_props.alarm_enable = atoi(av[ac - 1]); 150 error = mfi_ctrl_set_properties(fd, &ctrl_props); 151 if ( error < 0) { 152 error = errno; 153 warn("Failed to set controller properties"); 154 close(fd); 155 return (error); 156 } 157 158 error = mfi_ctrl_get_properties(fd, &ctrl_props); 159 if ( error < 0) { 160 error = errno; 161 warn("Failed to get controller properties"); 162 close(fd); 163 return (error); 164 } 165 } 166 printf ("controller alarm was : %s\n", 167 (ctrl_props.alarm_enable ? "enabled" : "disabled")); 168 return (0); 169 } 170 171 MFI_COMMAND(ctrlprop, alarm, mfi_ctrl_alarm_enable); 172