1/* $NetBSD: envsys.h,v 1.38 2018/05/27 06:40:31 wiz Exp $ */
2
3/*-
4 * Copyright (c) 1999, 2007, 2014 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tim Rightnour, Juan Romero Pardines and Bill Squier.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef _SYS_ENVSYS_H_
33#define _SYS_ENVSYS_H_
34
35#ifndef _KERNEL
36#include <stdbool.h>
37#endif
38
39#include <sys/ioccom.h>
40#include <sys/power.h>
41#include <sys/queue.h>
42
43/*
44 * ENVironmental SYStem version 2 (aka ENVSYS 2)
45 */
46
47#define ENVSYS_MAXSENSORS 512
48#define ENVSYS_DESCLEN 32
49
50/* sensor units */
51enum envsys_units {
52 ENVSYS_STEMP = 0, /* Temperature (microkelvins) */
53 ENVSYS_SFANRPM, /* Fan RPM */
54 ENVSYS_SVOLTS_AC, /* AC Volts */
55 ENVSYS_SVOLTS_DC, /* DC Volts */
56 ENVSYS_SOHMS, /* Ohms */
57 ENVSYS_SWATTS, /* Watts */
58 ENVSYS_SAMPS, /* Ampere */
59 ENVSYS_SWATTHOUR, /* Watt hour */
60 ENVSYS_SAMPHOUR, /* Ampere hour */
61 ENVSYS_INDICATOR, /* Indicator */
62 ENVSYS_INTEGER, /* Integer */
63 ENVSYS_DRIVE, /* Drive */
64 ENVSYS_BATTERY_CAPACITY, /* Battery capacity */
65 ENVSYS_BATTERY_CHARGE, /* Battery charging/discharging */
66 ENVSYS_SRELHUMIDITY, /* relative humidity */
67 ENVSYS_LUX, /* illuminance in lux */
68 ENVSYS_NSENSORS
69};
70
71/* sensor states */
72enum envsys_states {
73 ENVSYS_SVALID = 10, /* sensor state is valid */
74 ENVSYS_SINVALID, /* sensor state is invalid */
75 ENVSYS_SCRITICAL, /* sensor state is critical */
76 ENVSYS_SCRITUNDER, /* sensor state is critical under */
77 ENVSYS_SCRITOVER, /* sensor state is critical over */
78 ENVSYS_SWARNUNDER, /* sensor state is warn under */
79 ENVSYS_SWARNOVER /* sensor state is warn over */
80};
81
82/* sensor drive states */
83enum envsys_drive_states {
84 ENVSYS_DRIVE_EMPTY = 1, /* drive is empty */
85 ENVSYS_DRIVE_READY, /* drive is ready */
86 ENVSYS_DRIVE_POWERUP, /* drive is powered up */
87 ENVSYS_DRIVE_ONLINE, /* drive is online */
88 ENVSYS_DRIVE_IDLE, /* drive is idle */
89 ENVSYS_DRIVE_ACTIVE, /* drive is active */
90 ENVSYS_DRIVE_REBUILD, /* drive is rebuilding */
91 ENVSYS_DRIVE_POWERDOWN, /* drive is powered down */
92 ENVSYS_DRIVE_FAIL, /* drive failed */
93 ENVSYS_DRIVE_PFAIL, /* drive is degraded */
94 ENVSYS_DRIVE_MIGRATING, /* drive is migrating */
95 ENVSYS_DRIVE_OFFLINE, /* drive is offline */
96 ENVSYS_DRIVE_BUILD, /* drive is building */
97 ENVSYS_DRIVE_CHECK /* drive is checking its state */
98};
99
100/* sensor battery capacity states */
101enum envsys_battery_capacity_states {
102 ENVSYS_BATTERY_CAPACITY_NORMAL = 1, /* normal cap in battery */
103 ENVSYS_BATTERY_CAPACITY_WARNING, /* warning cap in battery */
104 ENVSYS_BATTERY_CAPACITY_CRITICAL, /* critical cap in battery */
105 ENVSYS_BATTERY_CAPACITY_HIGH, /* high cap in battery */
106 ENVSYS_BATTERY_CAPACITY_MAX, /* maximum cap in battery */
107 ENVSYS_BATTERY_CAPACITY_LOW /* low cap in battery */
108};
109
110/* sensor indicator states */
111enum envsys_indicator_states {
112 ENVSYS_INDICATOR_FALSE = 0,
113 ENVSYS_INDICATOR_TRUE = 1
114};
115
116/*
117 * IOCTLs
118 */
119#define ENVSYS_GETDICTIONARY _IOWR('E', 0, struct plistref)
120#define ENVSYS_SETDICTIONARY _IOWR('E', 1, struct plistref)
121#define ENVSYS_REMOVEPROPS _IOWR('E', 2, struct plistref)
122
123/*
124 * Compatibility with old interface. Only ENVSYS_GTREDATA
125 * and ENVSYS_GTREINFO ioctls are supported.
126 */
127
128/* get sensor data */
129
130struct envsys_tre_data {
131 unsigned int sensor;
132 union { /* all data is given */
133 uint32_t data_us; /* in microKelvins, */
134 int32_t data_s; /* rpms, volts, amps, */
135 } cur, min, max, avg; /* ohms, watts, etc */
136 /* see units below */
137
138 uint32_t warnflags; /* warning flags */
139 uint32_t validflags; /* sensor valid flags */
140 unsigned int units; /* type of sensor */
141};
142typedef struct envsys_tre_data envsys_tre_data_t;
143
144/* flags for warnflags */
145#define ENVSYS_WARN_OK 0x00000000 /* All is well */
146#define ENVSYS_WARN_UNDER 0x00000001 /* an under condition */
147#define ENVSYS_WARN_CRITUNDER 0x00000002 /* a critical under condition */
148#define ENVSYS_WARN_OVER 0x00000004 /* an over condition */
149#define ENVSYS_WARN_CRITOVER 0x00000008 /* a critical over condition */
150
151/* drive status */
152#define ENVSYS_DRIVE_EMPTY 1
153#define ENVSYS_DRIVE_READY 2
154#define ENVSYS_DRIVE_POWERUP 3
155#define ENVSYS_DRIVE_ONLINE 4
156#define ENVSYS_DRIVE_IDLE 5
157#define ENVSYS_DRIVE_ACTIVE 6
158#define ENVSYS_DRIVE_REBUILD 7
159#define ENVSYS_DRIVE_POWERDOWN 8
160#define ENVSYS_DRIVE_FAIL 9
161#define ENVSYS_DRIVE_PFAIL 10
162
163#ifdef ENVSYSUNITNAMES
164static const char * const envsysunitnames[] = {
165 "degC", "RPM", "VAC", "V", "Ohms", "W",
166 "A", "Wh", "Ah", "bool", "integer", "drive", "%rH", "lux", "Unk"
167};
168static const char * const envsysdrivestatus[] = {
169 "unknown", "empty", "ready", "powering up", "online", "idle", "active",
170 "rebuilding", "powering down", "failed", "degraded"
171};
172#endif
173
174
175/* flags for validflags */
176#define ENVSYS_FVALID 0x00000001 /* sensor is valid */
177#define ENVSYS_FCURVALID 0x00000002 /* cur for this sens is valid */
178#define ENVSYS_FMINVALID 0x00000004 /* min for this sens is valid */
179#define ENVSYS_FMAXVALID 0x00000008 /* max for this sens is valid */
180#define ENVSYS_FAVGVALID 0x00000010 /* avg for this sens is valid */
181#define ENVSYS_FFRACVALID 0x00000020 /* display fraction of max */
182
183#define ENVSYS_GTREDATA _IOWR('E', 2, envsys_tre_data_t)
184
185/* set and check sensor info */
186
187struct envsys_basic_info {
188 unsigned int sensor; /* sensor number */
189 unsigned int units; /* type of sensor */
190 char desc[33]; /* sensor description */
191 unsigned int rfact; /* for volts, (int)(factor x 10^4) */
192 unsigned int rpms; /* for fans, set nominal RPMs */
193 uint32_t validflags; /* sensor valid flags */
194};
195typedef struct envsys_basic_info envsys_basic_info_t;
196
197#define ENVSYS_GTREINFO _IOWR('E', 4, envsys_basic_info_t)
198
199#endif /* _SYS_ENVSYS_H_ */
200