mfi_properties.c revision 257820
1257820Ssbruno/*-
2257820Ssbruno * Copyright (c) 2013 Yahoo!, Inc.
3257820Ssbruno * All rights reserved.
4257820Ssbruno *
5257820Ssbruno * Redistribution and use in source and binary forms, with or without
6257820Ssbruno * modification, are permitted provided that the following conditions
7257820Ssbruno * are met:
8257820Ssbruno * 1. Redistributions of source code must retain the above copyright
9257820Ssbruno *    notice, this list of conditions and the following disclaimer.
10257820Ssbruno * 2. Redistributions in binary form must reproduce the above copyright
11257820Ssbruno *    notice, this list of conditions and the following disclaimer in the
12257820Ssbruno *    documentation and/or other materials provided with the distribution.
13257820Ssbruno *
14257820Ssbruno * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15257820Ssbruno * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16257820Ssbruno * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17257820Ssbruno * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18257820Ssbruno * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19257820Ssbruno * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20257820Ssbruno * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21257820Ssbruno * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22257820Ssbruno * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23257820Ssbruno * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24257820Ssbruno * SUCH DAMAGE.
25257820Ssbruno *
26257820Ssbruno *
27257820Ssbruno * $FreeBSD: head/usr.sbin/mfiutil/mfi_properties.c 257820 2013-11-07 21:47:59Z sbruno $
28257820Ssbruno */
29257820Ssbruno
30257820Ssbruno#include <sys/errno.h>
31257820Ssbruno#include <sys/ioctl.h>
32257820Ssbruno#include <sys/param.h>
33257820Ssbruno#include <sys/sysctl.h>
34257820Ssbruno#include <sys/uio.h>
35257820Ssbruno
36257820Ssbruno#include <err.h>
37257820Ssbruno#include <fcntl.h>
38257820Ssbruno#include <stdio.h>
39257820Ssbruno#include <stdlib.h>
40257820Ssbruno#include <string.h>
41257820Ssbruno#include <unistd.h>
42257820Ssbruno
43257820Ssbruno#include "mfiutil.h"
44257820Ssbruno#include <dev/mfi/mfi_ioctl.h>
45257820Ssbruno
46257820SsbrunoMFI_TABLE(top, ctrlprop);
47257820Ssbruno
48257820Ssbrunostatic int
49257820Ssbrunomfi_ctrl_get_properties(int fd, struct mfi_ctrl_props *info)
50257820Ssbruno{
51257820Ssbruno
52257820Ssbruno	return (mfi_dcmd_command(fd, MFI_DCMD_CTRL_GET_PROPS, info,
53257820Ssbruno	    sizeof(struct mfi_ctrl_props), NULL, 0, NULL));
54257820Ssbruno}
55257820Ssbruno
56257820Ssbrunostatic int
57257820Ssbrunomfi_ctrl_set_properties(int fd, struct mfi_ctrl_props *info)
58257820Ssbruno{
59257820Ssbruno
60257820Ssbruno	return (mfi_dcmd_command(fd, MFI_DCMD_CTRL_SET_PROPS, info,
61257820Ssbruno	    sizeof(struct mfi_ctrl_props), NULL, 0, NULL));
62257820Ssbruno}
63257820Ssbruno
64257820Ssbruno/*
65257820Ssbruno * aquite the controller properties data structure modify the
66257820Ssbruno * rebuild rate if requested and then retun
67257820Ssbruno */
68257820Ssbrunostatic int
69257820Ssbrunomfi_ctrl_rebuild_rate(int ac, char **av)
70257820Ssbruno{
71257820Ssbruno        int error, fd;
72257820Ssbruno	struct mfi_ctrl_props ctrl_props;
73257820Ssbruno
74257820Ssbruno	if (ac > 2) {
75257820Ssbruno		warn("mfi_ctrl_set_rebuild_rate");
76257820Ssbruno		return(-1);
77257820Ssbruno	}
78257820Ssbruno
79257820Ssbruno        fd = mfi_open(mfi_unit, O_RDWR);
80257820Ssbruno        if (fd < 0) {
81257820Ssbruno                error = errno;
82257820Ssbruno                warn("mfi_open");
83257820Ssbruno                return (error);
84257820Ssbruno        }
85257820Ssbruno
86257820Ssbruno	error = mfi_ctrl_get_properties(fd, &ctrl_props);
87257820Ssbruno        if ( error < 0) {
88257820Ssbruno                error = errno;
89257820Ssbruno                warn("Failed to get controller properties");
90257820Ssbruno                close(fd);
91257820Ssbruno                return (error);
92257820Ssbruno        }
93257820Ssbruno	/*
94257820Ssbruno	 * User requested a change to the rebuild rate
95257820Ssbruno	 */
96257820Ssbruno	if (ac > 1) {
97257820Ssbruno		ctrl_props.rebuild_rate = atoi(av[ac - 1]);
98257820Ssbruno		error = mfi_ctrl_set_properties(fd, &ctrl_props);
99257820Ssbruno        	if ( error < 0) {
100257820Ssbruno                	error = errno;
101257820Ssbruno                	warn("Failed to set controller properties");
102257820Ssbruno                	close(fd);
103257820Ssbruno                	return (error);
104257820Ssbruno        	}
105257820Ssbruno
106257820Ssbruno		error = mfi_ctrl_get_properties(fd, &ctrl_props);
107257820Ssbruno        	if ( error < 0) {
108257820Ssbruno                	error = errno;
109257820Ssbruno                	warn("Failed to get controller properties");
110257820Ssbruno                	close(fd);
111257820Ssbruno                	return (error);
112257820Ssbruno        	}
113257820Ssbruno	}
114257820Ssbruno	printf ("controller rebuild rate: %%%u \n",
115257820Ssbruno		ctrl_props.rebuild_rate);
116257820Ssbruno	return (0);
117257820Ssbruno}
118257820SsbrunoMFI_COMMAND(ctrlprop, rebuild, mfi_ctrl_rebuild_rate);
119257820Ssbruno
120257820Ssbrunostatic int
121257820Ssbrunomfi_ctrl_alarm_enable(int ac, char **av)
122257820Ssbruno{
123257820Ssbruno        int error, fd;
124257820Ssbruno	struct mfi_ctrl_props ctrl_props;
125257820Ssbruno
126257820Ssbruno	if (ac > 2) {
127257820Ssbruno		warn("mfi_ctrl_alarm_enable");
128257820Ssbruno		return(-1);
129257820Ssbruno	}
130257820Ssbruno
131257820Ssbruno        fd = mfi_open(mfi_unit, O_RDWR);
132257820Ssbruno        if (fd < 0) {
133257820Ssbruno                error = errno;
134257820Ssbruno                warn("mfi_open");
135257820Ssbruno                return (error);
136257820Ssbruno        }
137257820Ssbruno
138257820Ssbruno	error = mfi_ctrl_get_properties(fd, &ctrl_props);
139257820Ssbruno        if ( error < 0) {
140257820Ssbruno                error = errno;
141257820Ssbruno                warn("Failed to get controller properties");
142257820Ssbruno                close(fd);
143257820Ssbruno                return (error);
144257820Ssbruno        }
145257820Ssbruno	printf ("controller alarm was : %s\n",
146257820Ssbruno		(ctrl_props.alarm_enable ? "enabled" : "disabled"));
147257820Ssbruno
148257820Ssbruno	if (ac > 1) {
149257820Ssbruno		ctrl_props.alarm_enable = atoi(av[ac - 1]);
150257820Ssbruno		error = mfi_ctrl_set_properties(fd, &ctrl_props);
151257820Ssbruno        	if ( error < 0) {
152257820Ssbruno                	error = errno;
153257820Ssbruno                	warn("Failed to set controller properties");
154257820Ssbruno                	close(fd);
155257820Ssbruno                	return (error);
156257820Ssbruno        	}
157257820Ssbruno
158257820Ssbruno		error = mfi_ctrl_get_properties(fd, &ctrl_props);
159257820Ssbruno        	if ( error < 0) {
160257820Ssbruno                	error = errno;
161257820Ssbruno                	warn("Failed to get controller properties");
162257820Ssbruno                	close(fd);
163257820Ssbruno                	return (error);
164257820Ssbruno        	}
165257820Ssbruno	}
166257820Ssbruno	printf ("controller alarm was : %s\n",
167257820Ssbruno		(ctrl_props.alarm_enable ? "enabled" : "disabled"));
168257820Ssbruno	return (0);
169257820Ssbruno}
170257820Ssbruno
171257820SsbrunoMFI_COMMAND(ctrlprop, alarm, mfi_ctrl_alarm_enable);
172