xref: /illumos-gate/usr/src/uts/common/sys/ddi_hp_impl.h (revision ffb6483089015eb90be1f5e7fc2a96c9929546a6)
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 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  * Copyright 2019 Joyent, Inc.
25  */
26 
27 /*
28  * See the big theory statement in uts/common/os/ddi_hp_impl.c for more
29  * information about the structures and functions defined here.
30  */
31 
32 #ifndef	_SYS_DDI_HP_IMPL_H
33 #define	_SYS_DDI_HP_IMPL_H
34 
35 /*
36  * Sun DDI hotplug implementation specific definitions
37  */
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #ifdef _KERNEL
44 
45 /* Flags for sync request and async hotplug request */
46 #define	DDI_HP_REQ_SYNC 0x0001
47 #define	DDI_HP_REQ_ASYNC 0x0002
48 
49 /* Check if a handle represents a port or a connector */
50 #define	DDI_HP_IS_VIRTUAL_PORT(hdlp)		\
51 	(hdlp->cn_info.cn_type == DDI_HP_CN_TYPE_VIRTUAL_PORT)
52 
53 /*
54  * ddi_hp_cn_handle_t
55  *
56  * DDI handle for a registered Hotplug Connection (CN)
57  */
58 typedef struct ddi_hp_cn_handle {
59 	dev_info_t		*cn_dip; /* The dip that the handle is linked */
60 	ddi_hp_cn_info_t	cn_info; /* Connection info */
61 	struct ddi_hp_cn_handle	*next;	 /* Next Connector/Port. */
62 } ddi_hp_cn_handle_t;
63 
64 typedef struct ddi_hp_cn_async_event_entry {
65 	dev_info_t			*dip;
66 	char				*cn_name;
67 	ddi_hp_cn_state_t		target_state;
68 } ddi_hp_cn_async_event_entry_t;
69 
70 /*
71  * ddi_hp_op_t
72  *
73  * Typedef for Hotplug OPS commands used with bus_hp_op()
74  */
75 typedef enum {
76 	DDI_HPOP_CN_GET_STATE = 1,	/* Get Connection state */
77 	DDI_HPOP_CN_CHANGE_STATE,	/* Change Connection state */
78 	DDI_HPOP_CN_PROBE,		/* Probe Connection */
79 	DDI_HPOP_CN_UNPROBE,		/* Unprobe Connection */
80 	DDI_HPOP_CN_GET_PROPERTY,	/* Get bus specific property */
81 	DDI_HPOP_CN_SET_PROPERTY,	/* Set bus specific property */
82 	DDI_HPOP_CN_CREATE_PORT,	/* Create a port for virtual hotplug */
83 	DDI_HPOP_CN_REMOVE_PORT		/* Remove an empty port */
84 } ddi_hp_op_t;
85 
86 #define	DDIHP_CN_OPS(hdlp, op, arg, result, ret)		\
87 	if (DDI_HP_IS_VIRTUAL_PORT(hdlp))			\
88 		ret = ddihp_port_ops(hdlp, op, arg, result);	\
89 	else							\
90 		ret = ddihp_connector_ops(hdlp, op, arg, result);
91 
92 #define	NEXUS_HAS_HP_OP(dip)						\
93 	((DEVI(dip)->devi_ops->devo_bus_ops) &&				\
94 	(DEVI(dip)->devi_ops->devo_bus_ops->busops_rev >= BUSO_REV_10) && \
95 	(DEVI(dip)->devi_ops->devo_bus_ops->bus_hp_op))
96 
97 /*
98  * ddi_hp_cn_sysevent_t
99  *
100  * The following correspond to sysevent defined subclasses
101  */
102 typedef enum {
103 	DDI_HP_CN_STATE_CHANGE,
104 	DDI_HP_CN_REQ
105 } ddi_hp_cn_sysevent_t;
106 
107 /*
108  * Misc
109  */
110 
111 /* Append a node to list */
112 #define	DDIHP_LIST_APPEND(type, head, node)				\
113 if (node) {								\
114 	type *curr, *prev = NULL;					\
115 	(node)->next = NULL;						\
116 	for (curr = (head); curr; prev = curr, curr = curr->next);	\
117 	if (prev == NULL)						\
118 		(head) = (node);					\
119 	else								\
120 		prev->next = (node);					\
121 }
122 
123 /* Remove a node from a list */
124 #define	DDIHP_LIST_REMOVE(type, head, node)				\
125 if (node) {								\
126 	type *curr, *prev = NULL;					\
127 	for (curr = (head); curr; prev = curr, curr = curr->next) {	\
128 		if (curr == (node))					\
129 			break;						\
130 	}								\
131     if (curr) {								\
132 	if (prev == NULL)						\
133 		(head) = (head)->next;					\
134 	else								\
135 		prev->next = curr->next;				\
136 	}								\
137 }
138 
139 int ddihp_modctl(int hp_op, char *path, char *cn_name, uintptr_t arg,
140     uintptr_t rval);
141 ddi_hp_cn_handle_t *ddihp_cn_name_to_handle(dev_info_t *dip, char *cn_name);
142 int ddihp_cn_getstate(ddi_hp_cn_handle_t *hdlp);
143 int ddihp_port_ops(ddi_hp_cn_handle_t *hdlp, ddi_hp_op_t op,
144     void *arg, void *result);
145 int ddihp_connector_ops(ddi_hp_cn_handle_t *hdlp,
146     ddi_hp_op_t op, void *arg, void *result);
147 void ddihp_cn_gen_sysevent(ddi_hp_cn_handle_t *hdlp,
148     ddi_hp_cn_sysevent_t event_sub_class, int hint, int kmflag);
149 int ddihp_cn_unregister(ddi_hp_cn_handle_t *hdlp);
150 
151 #endif /* _KERNEL */
152 
153 #ifdef	__cplusplus
154 }
155 #endif
156 
157 #endif	/* _SYS_DDI_HP_IMPL_H */
158