xref: /titanic_50/usr/src/uts/common/sys/devctl.h (revision 71269a2275bf5a143dad6461eee2710a344e7261)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_DEVCTL_H
27 #define	_SYS_DEVCTL_H
28 
29 /*
30  * Device control interfaces
31  */
32 #include <sys/types.h>
33 #include <sys/nvpair.h>
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40  * structure used to pass IOCTL data between the libdevice interfaces
41  * and nexus driver devctl IOCTL interface.
42  *
43  * Applications and nexus drivers may not access the contents of this
44  * structure directly.  Instead, drivers must use the ndi_dc_XXX(9n)
45  * interfaces, while applications must use the interfaces provided by
46  * libdevice.so.1.
47  */
48 struct devctl_iocdata {
49 	uint_t	cmd;			/* ioctl cmd */
50 	uint_t	flags;			/* command-specific flags */
51 	void	*cpyout_buf;		/* copyout vector */
52 	nvlist_t *nvl_user;		/* application defined attributes */
53 	size_t  nvl_usersz;
54 	char	*c_nodename;		/* child device nodename */
55 	char	*c_unitaddr;		/* child device unit address */
56 };
57 
58 #if defined(_SYSCALL32)
59 /*
60  * Structure to pass/return data from 32-bit program's.
61  */
62 struct devctl_iocdata32 {
63 	uint32_t  cmd;
64 	uint32_t  flags;
65 	caddr32_t cpyout_buf;
66 	caddr32_t nvl_user;
67 	uint32_t  nvl_usersz;
68 	caddr32_t c_nodename;
69 	caddr32_t c_unitaddr;
70 };
71 #endif
72 
73 /*
74  * Limit size of packed application defined attributes (nvl_user) to prevent
75  * user application from requesting excessive kernel memory allocation.
76  */
77 #define	DEVCTL_MAX_NVL_USERSZ	0x10000
78 
79 /*
80  * State of receptacle for an Attachment Point.
81  */
82 typedef enum {
83 	AP_RSTATE_EMPTY,
84 	AP_RSTATE_DISCONNECTED,
85 	AP_RSTATE_CONNECTED
86 } ap_rstate_t;
87 
88 /*
89  * State of occupant for an Attachment Point.
90  */
91 typedef enum {
92 	AP_OSTATE_UNCONFIGURED,
93 	AP_OSTATE_CONFIGURED
94 } ap_ostate_t;
95 
96 /*
97  * condition of an Attachment Point.
98  */
99 typedef enum {
100 	AP_COND_UNKNOWN,
101 	AP_COND_OK,
102 	AP_COND_FAILING,
103 	AP_COND_FAILED,
104 	AP_COND_UNUSABLE
105 } ap_condition_t;
106 
107 /*
108  * structure used to return the state of Attachment Point (AP) thru
109  * devctl_ap_getstate() interface.
110  */
111 
112 typedef struct devctl_ap_state {
113 	ap_rstate_t	ap_rstate; 	/* receptacle state */
114 	ap_ostate_t	ap_ostate;	/* occupant state */
115 	ap_condition_t	ap_condition;	/* condition of AP */
116 	time_t		ap_last_change;
117 	uint32_t	ap_error_code;	/* error code */
118 	uint8_t		ap_in_transition;
119 } devctl_ap_state_t;
120 
121 #if defined(_SYSCALL32)
122 /*
123  * Structure to pass/return data from 32-bit program's.
124  */
125 typedef struct devctl_ap_state32 {
126 	ap_rstate_t	ap_rstate; 	/* receptacle state */
127 	ap_ostate_t	ap_ostate;	/* occupant state */
128 	ap_condition_t	ap_condition;	/* condition of AP */
129 	time32_t	ap_last_change;
130 	uint32_t	ap_error_code;	/* error code */
131 	uint8_t		ap_in_transition;
132 } devctl_ap_state32_t;
133 #endif
134 
135 #define	DEVCTL_IOC		(0xDC << 16)
136 #define	DEVCTL_IOC_MAX		(DEVCTL_IOC | 0xFFFF)
137 #define	DEVCTL_BUS_QUIESCE	(DEVCTL_IOC | 1)
138 #define	DEVCTL_BUS_UNQUIESCE	(DEVCTL_IOC | 2)
139 #define	DEVCTL_BUS_RESETALL	(DEVCTL_IOC | 3)
140 #define	DEVCTL_BUS_RESET	(DEVCTL_IOC | 4)
141 #define	DEVCTL_BUS_GETSTATE	(DEVCTL_IOC | 5)
142 #define	DEVCTL_DEVICE_ONLINE	(DEVCTL_IOC | 6)
143 #define	DEVCTL_DEVICE_OFFLINE	(DEVCTL_IOC | 7)
144 #define	DEVCTL_DEVICE_GETSTATE	(DEVCTL_IOC | 9)
145 #define	DEVCTL_DEVICE_RESET	(DEVCTL_IOC | 10)
146 #define	DEVCTL_BUS_CONFIGURE	(DEVCTL_IOC | 11)
147 #define	DEVCTL_BUS_UNCONFIGURE	(DEVCTL_IOC | 12)
148 #define	DEVCTL_DEVICE_REMOVE	(DEVCTL_IOC | 13)
149 #define	DEVCTL_AP_CONNECT	(DEVCTL_IOC | 14)
150 #define	DEVCTL_AP_DISCONNECT	(DEVCTL_IOC | 15)
151 #define	DEVCTL_AP_INSERT	(DEVCTL_IOC | 16)
152 #define	DEVCTL_AP_REMOVE	(DEVCTL_IOC | 17)
153 #define	DEVCTL_AP_CONFIGURE	(DEVCTL_IOC | 18)
154 #define	DEVCTL_AP_UNCONFIGURE	(DEVCTL_IOC | 19)
155 #define	DEVCTL_AP_GETSTATE	(DEVCTL_IOC | 20)
156 #define	DEVCTL_AP_CONTROL	(DEVCTL_IOC | 21)
157 #define	DEVCTL_BUS_DEV_CREATE	(DEVCTL_IOC | 22)
158 #define	DEVCTL_PM_BUSY_COMP	(DEVCTL_IOC | 23)
159 #define	DEVCTL_PM_IDLE_COMP	(DEVCTL_IOC | 24)
160 #define	DEVCTL_PM_RAISE_PWR	(DEVCTL_IOC | 25)
161 #define	DEVCTL_PM_LOWER_PWR	(DEVCTL_IOC | 26)
162 #define	DEVCTL_PM_CHANGE_PWR_LOW	(DEVCTL_IOC | 27)
163 #define	DEVCTL_PM_CHANGE_PWR_HIGH	(DEVCTL_IOC | 28)
164 #define	DEVCTL_PM_POWER		(DEVCTL_IOC | 29)
165 #define	DEVCTL_PM_PROM_PRINTF	(DEVCTL_IOC | 30)
166 #define	DEVCTL_PM_FAIL_SUSPEND	(DEVCTL_IOC | 31)
167 #define	DEVCTL_PM_PWR_HAS_CHANGED_ON_RESUME	(DEVCTL_IOC | 32)
168 #define	DEVCTL_PM_PUP_WITH_PWR_HAS_CHANGED	(DEVCTL_IOC | 34)
169 #define	DEVCTL_PM_BUSY_COMP_TEST	(DEVCTL_IOC | 35)
170 #define	DEVCTL_PM_BUS_STRICT_TEST	(DEVCTL_IOC | 36)
171 #define	DEVCTL_PM_NO_LOWER_POWER	(DEVCTL_IOC | 37)
172 #define	DEVCTL_PM_BUS_NO_INVOL		(DEVCTL_IOC | 38)
173 #define	DEVCTL_SET_LED		(DEVCTL_IOC | 39)
174 #define	DEVCTL_GET_LED		(DEVCTL_IOC | 40)
175 #define	DEVCTL_NUM_LEDS		(DEVCTL_IOC | 41)
176 
177 
178 /*
179  * is (c) in the range of possible devctl IOCTL commands?
180  */
181 #define	IS_DEVCTL(c) (((c) >= DEVCTL_IOC) && ((c) <= DEVCTL_IOC_MAX))
182 
183 /*
184  * Device and Bus State definitions
185  *
186  * Device state is returned as a set of bit-flags that indicate the current
187  * operational state of a device node.
188  *
189  * Device nodes for leaf devices only contain state information for the
190  * device itself.  Nexus device nodes contain both Bus and Device state
191  * information.
192  *
193  * 	DEVICE_ONLINE  - Device is available for use by the system.  Mutually
194  *                       exclusive with DEVICE_OFFLINE.
195  *
196  *	DEVICE_OFFLINE - Device is unavailable for use by the system.
197  *			 Mutually exclusive with DEVICE_ONLINE and DEVICE_BUSY.
198  *
199  *	DEVICE_DOWN    - Device has been placed in the "DOWN" state by
200  *			 its controlling driver.
201  *
202  *	DEVICE_BUSY    - Device has open instances or nexus has INITALIZED
203  *                       children (nexi).  A device in this state is by
204  *			 definition Online.
205  *
206  * Bus state is returned as a set of bit-flags which indicates the
207  * operational state of a bus associated with the nexus dev_info node.
208  *
209  * 	BUS_ACTIVE     - The bus associated with the device node is Active.
210  *                       I/O requests from child devices attached to the
211  *			 are initiated (or queued for initiation) as they
212  *			 are received.
213  *
214  *	BUS_QUIESCED   - The bus associated with the device node has been
215  *			 Quieced. I/O requests from child devices attached
216  *			 to the bus are held pending until the bus nexus is
217  *			 Unquiesced.
218  *
219  *	BUS_SHUTDOWN   - The bus associated with the device node has been
220  *			 shutdown by the nexus driver.  I/O requests from
221  *			 child devices are returned with an error indicating
222  *			 the requested operation failed.
223  */
224 #define	DEVICE_ONLINE	0x1
225 #define	DEVICE_BUSY	0x2
226 #define	DEVICE_OFFLINE  0x4
227 #define	DEVICE_DOWN	0x8
228 
229 #define	BUS_ACTIVE	0x10
230 #define	BUS_QUIESCED	0x20
231 #define	BUS_SHUTDOWN	0x40
232 
233 #define	DC_DEVI_NODENAME	"ndi_dc.devi_nodename"
234 
235 #define	DEVCTL_CONSTRUCT	0x1
236 #define	DEVCTL_OFFLINE		0x2
237 
238 /*
239  * Drive status LED control
240  */
241 struct dc_led_ctl {
242 	uint32_t	led_number : 16;	/* LED/device number */
243 	uint32_t	led_ctl_active : 1;	/* Control active */
244 	uint32_t	led_type : 9;		/* LED type */
245 	uint32_t	led_state : 6;		/* LED ON/OFF/Blink state */
246 };
247 
248 /* Control active field */
249 #define	DCL_CNTRL_OFF		0	/* Control inactive */
250 #define	DCL_CNTRL_ON		1	/* Control active */
251 
252 /* LED type field */
253 #define	DCL_TYPE_DEVICE_FAIL	1	/* Device FAIL LED type */
254 #define	DCL_TYPE_DEVICE_OK2RM	2	/* Device OK2RM LED type */
255 
256 /* LED state field */
257 #define	DCL_STATE_OFF		0	/* LED state OFF */
258 #define	DCL_STATE_ON		1	/* LED state ON */
259 #define	DCL_STATE_SLOW_BLNK	2	/* LED slow blink */
260 #define	DCL_STATE_FAST_BLNK	3	/* LED fast blink */
261 
262 #ifdef	__cplusplus
263 }
264 #endif
265 
266 #endif	/* _SYS_DEVCTL_H */
267