xref: /titanic_41/usr/src/uts/common/sys/hotplug/hpctrl.h (revision e71ca95ca6de23d33b54cb55cefdef30bc7c969b)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_HOTPLUG_HPCTRL_H
28 #define	_SYS_HOTPLUG_HPCTRL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * ****************************************************************
34  * Hot Plug Controller interfaces for PCI and CompactPCI platforms.
35  * ****************************************************************
36  */
37 #include <sys/types.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * Type definition for slot handle. This is an opaque pointer
45  * created by the HPS framework.
46  */
47 typedef void *hpc_slot_t;
48 
49 #define	HPC_SLOT_OPS_VERSION	0
50 
51 /*
52  * slot operations structure definition.
53  *
54  *	Function		Description
55  *	--------		-----------
56  *	xxx_op_connect		CONNECT the slot to the bus to enable
57  *				access to the adapter.
58  *	xxx_op_disconnect	DISCONNECT the slot from the bus. For PCI,
59  *				this disables the power to the slot.
60  *	xxx_op_insert		Prepare the slot for card insertion. This
61  *				may not be applicable for all bus types.
62  *	xxx_op_remove		Prepare the slot for card removal. This
63  *				may not be applicable for all bus types.
64  *	xxx_op_control		Perform misc. commands to control the
65  *				LEDs, get status information, etc.
66  */
67 typedef struct hpc_slot_ops {
68 	int	hpc_version;			/* HPC_SLOT_OPS_VERSION */
69 	int	(*hpc_op_connect)(caddr_t ops_arg, hpc_slot_t slot_hdl,
70 			void *data, uint_t flags);
71 	int	(*hpc_op_disconnect)(caddr_t ops_arg, hpc_slot_t slot_hdl,
72 			void *data, uint_t flags);
73 	int	(*hpc_op_insert)(caddr_t ops_arg, hpc_slot_t slot_hdl,
74 			void *data, uint_t flags);
75 	int	(*hpc_op_remove)(caddr_t ops_arg, hpc_slot_t slot_hdl,
76 			void *data, uint_t flags);
77 	int	(*hpc_op_control)(caddr_t ops_arg, hpc_slot_t slot_hdl,
78 			int request, caddr_t arg);
79 } hpc_slot_ops_t;
80 
81 #define	HPC_SLOT_INFO_VERSION	1
82 #define	PCI_SLOT_NAME_LEN	256
83 /*
84  * Slot information structure.
85  */
86 typedef struct hpc_slot_info {
87 	uint16_t	version;		/* HPC_SLOT_INFO_VERSION */
88 	uint16_t	slot_type;		/* slot type: PCI, ... */
89 	uint16_t	slot_flags;
90 	union {
91 	    /* pci bus slot */
92 	    struct pci_slot_info {
93 		uint16_t	device_number;		/* PCI device number */
94 		uint16_t	slot_capabilities;	/* 64bit, etc. */
95 		char		slot_logical_name[PCI_SLOT_NAME_LEN];
96 	    } pci;
97 	    struct sbd_slot_info {
98 		int		slot_num;
99 	    } sbd;
100 	    /* other bus types go here... */
101 	} slot;
102 } hpc_slot_info_t;
103 
104 /* short names for bus specific fields in hpc_slot_info structure */
105 #define	pci_dev_num		slot.pci.device_number
106 #define	pci_slot_name		slot.pci.slot_logical_name
107 #define	pci_slot_capabilities	slot.pci.slot_capabilities
108 
109 #define	sbd_slot_num		slot.sbd.slot_num
110 
111 /* slot_type definitions */
112 #define	HPC_SLOT_TYPE_PCI	0x1		/* PCI bus slot */
113 #define	HPC_SLOT_TYPE_CPCI	0x2		/* Compact PCI bus slot */
114 #define	HPC_SLOT_TYPE_SBD	0x3		/* System bus slot */
115 #define	HPC_SLOT_TYPE_PCIE	0x4		/* PCI Express slot */
116 
117 /* bit definitions in slot_capabilities field for PCI or cPCI bus slots */
118 #define	HPC_SLOT_64BITS		0x0001	/* slot is a 64bit slot */
119 #define	HPC_SLOT_TEST		0x0002	/* testing capability on the slot */
120 
121 /* slot_flags definitions */
122 #define	HPC_SLOT_NO_AUTO_ENABLE	0x1	/* No auto-enable on registration */
123 #define	HPC_SLOT_CREATE_DEVLINK	0x2	/* create device link under /dev/cfg */
124 
125 /*
126  * xxx_op_control command definitions.
127  *
128  * 	Command (request)	   arg			Descritpion
129  *	-----------------	   ---			-----------
130  *	HPC_CTRL_GET_LED_STATE	   hpc_led_info *	Get state of an LED.
131  *	HPC_CTRL_SET_LED_STATE	   hpc_led_info *	Set state of an LED.
132  *	HPC_CTRL_GET_SLOT_STATE	   hpc_slot_state_t *	Get the slot state.
133  *	HPC_CTRL_DEV_CONFIGURED	   NULL 		Board is configured.
134  *	HPC_CTRL_DEV_UNCONFIGURED  NULL 		Board is unconfigured.
135  *	HPC_CTRL_DEV_CONFIG_FAILURE NULL	Board Configuration Failed
136  *	HPC_CTRL_DEV_UNCONFIG_FAILURE NULL	Board Unconfiguration Failed
137  *	HPC_CTRL_GET_BOARD_TYPE    hpc_board_type_t *	Get board type info.
138  *	HPC_CTRL_DISABLE_AUTOCFG   NULL			Disable auto config-
139  *							uration for this slot.
140  *	HPC_CTRL_ENABLE_AUTOCFG    NULL			Enable auto config-
141  *							uration for this slot.
142  *	HPC_CTRL_DISABLE_SLOT	   NULL			Disable the slot for
143  *							hot plug operations.
144  *	HPC_CTRL_ENABLE_SLOT	   NULL			ReEnable the slot for
145  *							hot plug operations.
146  */
147 #define	HPC_CTRL_GET_LED_STATE		0x1
148 #define	HPC_CTRL_SET_LED_STATE		0x2
149 #define	HPC_CTRL_GET_SLOT_STATE		0x3
150 #define	HPC_CTRL_DEV_CONFIGURED		0x4
151 #define	HPC_CTRL_DEV_UNCONFIGURED	0x5
152 #define	HPC_CTRL_GET_BOARD_TYPE		0x6
153 #define	HPC_CTRL_DISABLE_AUTOCFG	0x7
154 #define	HPC_CTRL_ENABLE_AUTOCFG		0x8
155 #define	HPC_CTRL_DISABLE_SLOT		0x9
156 #define	HPC_CTRL_ENABLE_SLOT		0xa
157 #define	HPC_CTRL_DISABLE_ENUM		0xb
158 #define	HPC_CTRL_ENABLE_ENUM		0xc
159 #define	HPC_CTRL_DEV_CONFIG_FAILURE	0xd
160 #define	HPC_CTRL_DEV_UNCONFIG_FAILURE	0xe
161 #define	HPC_CTRL_DEV_CONFIG_START	0xf
162 #define	HPC_CTRL_DEV_UNCONFIG_START	0x10
163 
164 /*
165  * type definitions for led information.
166  *
167  * Note: ATTN/ACTIVE leds are platform specific and they may not be
168  *	 available on all platforms.
169  */
170 typedef enum { HPC_FAULT_LED, HPC_POWER_LED, HPC_ATTN_LED,
171 	HPC_ACTIVE_LED} hpc_led_t;
172 
173 typedef enum { HPC_LED_OFF, HPC_LED_ON, HPC_LED_BLINK } hpc_led_state_t;
174 
175 typedef struct hpc_led_info {
176 	hpc_led_t	led;	/* led id: HPC_POWER_LED, HPC_FAULT_LED, ... */
177 	hpc_led_state_t	state;	/* led state: HPC_LED_ON, HPC_LED_OFF, ... */
178 } hpc_led_info_t;
179 
180 /*
181  * type definition for slot state.
182  *
183  *	HPC_SLOT_EMPTY		Slot has no card present.
184  *	HPC_SLOT_CONNECTED	Card is present in the slot and it is
185  *				connected to the bus.
186  *	HPC_SLOT_DISCONNECTED	Card is present in the slot and it is
187  *				disconnected from the bus.
188  *	HPC_SLOT_UNKNOWN	If the HPC driver can not figure out
189  *				the receptacle state. This is possible
190  *				on Compact PCI Hot Swap platform.
191  */
192 typedef enum { HPC_SLOT_EMPTY, HPC_SLOT_DISCONNECTED,
193 	HPC_SLOT_CONNECTED, HPC_SLOT_UNKNOWN } hpc_slot_state_t;
194 
195 /*
196  * type definition for board type.
197  *
198  *	HPC_BOARD_UNKNOWN	Board is either not present or unknown.
199  *	HPC_BOARD_PCI_HOTPLUG	PCI or PCIe adapter.
200  *	HPC_BOARD_CPCI_NON_HS	Non Hot Swap cPCI board.
201  *	HPC_BOARD_CPCI_BASIC_HS	Basic Hot Swap cPCI board.
202  *	HPC_BOARD_CPCI_FULL_HS	Full Hot Swap cPCI board.
203  *	HPC_BOARD_CPCI_HS	Indicates if HSC driver can not determine
204  *				the type of Hot Swap board.
205  */
206 typedef enum { HPC_BOARD_UNKNOWN, HPC_BOARD_PCI_HOTPLUG,
207 	HPC_BOARD_CPCI_NON_HS, HPC_BOARD_CPCI_BASIC_HS,
208 	HPC_BOARD_CPCI_FULL_HS, HPC_BOARD_CPCI_HS } hpc_board_type_t;
209 
210 /*
211  * Event type definitions (for hpc_event_notify() interface).
212  *
213  *	Event			   Descritpion
214  *	-----			   -----------
215  *	HPC_EVENT_SLOT_INSERTION   Card is inserted in the slot.
216  *	HPC_EVENT_SLOT_REMOVAL	   Card is removed from the slot.
217  *	HPC_EVENT_SLOT_POWER_ON	   Slot is powered ON.
218  *	HPC_EVENT_SLOT_POWER_OFF   Slot is powered OFF.
219  *	HPC_EVENT_SLOT_LATCH_OPEN  LATCH on the slot is open.
220  *	HPC_EVENT_SLOT_LATCH_SHUT  LATCH on the slot is shut.
221  *	HPC_EVENT_SLOT_ENUM	   ENUM# signal is generated on the bus
222  *				   and it may be generated from this slot.
223  *	HPC_EVENT_SLOT_NOT_HEALTHY HEALTHY# signal is lost on this slot.
224  *	HPC_EVENT_SLOT_HEALTHY_OK  HEALTHY# signal on this slot is OK now.
225  *	HPC_EVENT_SLOT_CONFIGURE   Configure the occupant in the slot.
226  *	HPC_EVENT_SLOT_UNCONFIGURE Unconfigure the occupant in the slot.
227  */
228 #define	HPC_EVENT_SLOT_INSERTION	0x00000001
229 #define	HPC_EVENT_SLOT_REMOVAL		0x00000002
230 #define	HPC_EVENT_SLOT_POWER_ON		0x00000004
231 #define	HPC_EVENT_SLOT_POWER_OFF	0x00000008
232 #define	HPC_EVENT_SLOT_LATCH_OPEN	0x00000010
233 #define	HPC_EVENT_SLOT_LATCH_SHUT	0x00000020
234 #define	HPC_EVENT_SLOT_ENUM		0x00000040
235 #define	HPC_EVENT_SLOT_NOT_HEALTHY	0x00000080
236 #define	HPC_EVENT_SLOT_HEALTHY_OK	0x00000100
237 #define	HPC_EVENT_SLOT_CONFIGURE	0x00000200
238 #define	HPC_EVENT_SLOT_UNCONFIGURE	0x00000400
239 #define	HPC_EVENT_SLOT_BLUE_LED_ON	0x00000800
240 #define	HPC_EVENT_SLOT_BLUE_LED_OFF	0x00001000
241 #define	HPC_EVENT_CLEAR_ENUM		0x00002000
242 #define	HPC_EVENT_PROCESS_ENUM		0x00004000
243 #define	HPC_EVENT_ENABLE_ENUM		0x00008000
244 #define	HPC_EVENT_DISABLE_ENUM		0x00010000
245 #define	HPC_EVENT_BUS_ENUM		HPC_EVENT_SLOT_ENUM
246 #define	HPC_EVENT_SLOT_ATTN		0x00020000
247 #define	HPC_EVENT_SLOT_POWER_FAULT  	0x00040000
248 
249 /*
250  * return values for errors from HPS framework interfaces.
251  */
252 #define	HPC_SUCCESS			0x0
253 #define	HPC_ERR_INVALID			0x1	/* invalid arguments */
254 #define	HPC_ERR_SLOT_NOTREGISTERED	0x2	/* slot is not registered */
255 #define	HPC_ERR_SLOT_DUPLICATE		0x3	/* slot is already registered */
256 #define	HPC_ERR_BUS_NOTREGISTERED	0x4	/* slot is not registered */
257 #define	HPC_ERR_BUS_DUPLICATE		0x5	/* slot is already registered */
258 #define	HPC_ERR_NOTSUPPORTED		0x6	/* operation not supported */
259 #define	HPC_ERR_FAILED			0x7	/* operation failed */
260 
261 /* return values for event notifications */
262 #define	HPC_EVENT_CLAIMED		0x10	/* HPC event is claimed */
263 #define	HPC_EVENT_UNCLAIMED		-1	/* HPC event is not claimed */
264 
265 /* definitions for slot (un)registration events */
266 #define	HPC_SLOT_ONLINE		1	/* slot is registered */
267 #define	HPC_SLOT_OFFLINE	2	/* slot is unregistered */
268 
269 /*
270  * function prototype definitions for interfaces between HPC driver
271  * and Hot Plug Services framework.
272  */
273 #ifdef	__STDC__
274 extern int hpc_slot_register(dev_info_t *dip, char *bus_path,
275 	hpc_slot_info_t *slot_info, hpc_slot_t *slot_hdl,
276 	hpc_slot_ops_t *slot_ops, caddr_t ops_arg, uint_t flags);
277 extern int hpc_slot_unregister(hpc_slot_t *slot_hdl);
278 extern struct hpc_slot_ops *hpc_alloc_slot_ops(int sleepflag);
279 extern void hpc_free_slot_ops(hpc_slot_ops_t *ops);
280 extern int hpc_slot_event_notify(hpc_slot_t slot_hdl, uint_t event,
281 	uint_t flags);
282 extern boolean_t hpc_bus_registered(hpc_slot_t slot_hdl);
283 #else
284 extern int hpc_slot_register();
285 extern int hpc_slot_unregister();
286 extern struct hpc_slot_ops *hpc_alloc_slot_ops();
287 extern void hpc_free_slot_ops();
288 extern int hpc_slot_event_notify();
289 extern boolean_t hpc_bus_registered();
290 #endif	/* __STDC__ */
291 
292 /*
293  * *****************************************************************
294  * Implementation specific data structures and definitons. These are
295  * the private interfaces between cfgadm plug-in and the PCI nexus
296  * driver.
297  * *****************************************************************
298  */
299 
300 /*
301  * Data structure used for DEVCTL_AP_CONTROL ioctl on the AP.
302  */
303 struct hpc_control_data {
304 	uint_t	cmd;		/* HPC_CTRL_* command */
305 	void	*data;		/* pointer to data that is exchanged */
306 };
307 
308 struct hpc_control32_data {
309 	uint_t	  cmd;		/* HPC_CTRL_* command */
310 	caddr32_t data;		/* pointer to data that is exchanged */
311 };
312 
313 /* misc. control commands for DEVCTL_AP_CONTROL ioctl interface */
314 #define	HPC_CTRL_GET_SLOT_INFO	0x100
315 #define	HPC_CTRL_GET_CARD_INFO	0x101
316 
317 /* card information structure to get data from the PCI config header */
318 typedef struct hpc_card_info {
319 	uint8_t	prog_class;	/* PCI_CONF_PROGCLASS byte */
320 	uint8_t	base_class;	/* PCI_CONF_BASCLASS byte */
321 	uint8_t	sub_class;	/* PCI_CONF_SUBCLASS byte */
322 	uint8_t	header_type;	/* PCI_CONF_HEADER byte */
323 } hpc_card_info_t;
324 
325 /* Slot occupant information structure */
326 #define	HPC_MAX_OCCUPANTS	128
327 typedef struct hpc_occupant_info {
328 	int	i;
329 	char	*id[HPC_MAX_OCCUPANTS];
330 } hpc_occupant_info_t;
331 
332 #ifdef	__cplusplus
333 }
334 #endif
335 
336 #endif	/* _SYS_HOTPLUG_HPCTRL_H */
337