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 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_CFGA_SBD_H
28 #define	_CFGA_SBD_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #define	DEVDIR	"/devices"
35 
36 #ifdef	SBD_DEBUG
37 #define	DBG	dbg
38 void dbg(char *, ...);
39 #else
40 #define	DBG
41 #endif
42 
43 typedef struct {
44 	int flags;
45 	int code;
46 	char *mid;
47 	char *platform;
48 	int skip;
49 	int err;
50 } ap_opts_t;
51 
52 /*
53  * Command options.
54  *
55  * Some of the options are provided for testing purpose and
56  * will not published (e.g. err,code,mid).
57  */
58 #define	OPT_UNASSIGN		0
59 #define	OPT_SKIP		1
60 #define	OPT_PARSABLE		2
61 #define	OPT_NOPOWEROFF		3
62 #define	OPT_CODE		4
63 #define	OPT_MID			5
64 #define	OPT_ERR			6
65 #define	OPT_PLATFORM		7
66 #define	OPT_SIM			8
67 #define	OPT_SUSPEND_OK		9
68 #define	OPT_LIST_ALL		29
69 #define	OPT_FORCE		30
70 #define	OPT_VERBOSE		31
71 
72 #define	ap_getopt(a, o)	((a)->opts.flags &  ((uint_t)1 << (o)))
73 #define	ap_setopt(a, o)	((a)->opts.flags |= ((uint_t)1 << (o)))
74 
75 typedef enum {
76 	AP_NONE = 0,
77 	AP_BOARD,
78 	AP_CPU,
79 	AP_MEM,
80 	AP_IO,
81 	AP_CMP
82 } ap_target_t;
83 
84 #define	AP_NCLASS	6
85 
86 /*
87  * Attachment point descriptor.
88  *
89  * All commands are processed as follows:
90  *
91  * . allocate a command descriptor
92  * . parse the physical ap_id
93  * . parse the command and its options.
94  * . sequence if necessary (state change commands)
95  * . execute
96  *
97  */
98 typedef struct {
99 	int fd;
100 	int bnum;
101 	int cnum;
102 	int ncm;
103 	int inst;
104 	int norcm;
105 	int statonly;
106 	const char *class;
107 	const char *apid;
108 	char *drv;
109 	char *path;
110 	char *target;
111 	char *minor;
112 	char *cid;
113 	char *cname;
114 	char *options;
115 	char **errstring;
116 	ap_opts_t opts;
117 	ap_target_t tgt;
118 	struct cfga_msg *msgp;
119 	struct cfga_confirm *confp;
120 	void *ctl;
121 	void *stat;
122 	void *cmstat;
123 	void *rcm;
124 } apd_t;
125 
126 /*
127  * Command definitions.
128  *
129  * The command order is significant.  The sequenced (-c) commands
130  * are sorted in execution order. The configure command starts from
131  * assign and ends with online.  The disconnect command starts
132  * from offline and goes to unassign.  Steps in the sequencing may
133  * be optionally skipped.
134  */
135 #define	CMD_ASSIGN		0
136 #define	CMD_POWERON		1
137 #define	CMD_TEST		2
138 #define	CMD_CONNECT		3
139 #define	CMD_CONFIGURE		4
140 #define	CMD_RCM_ONLINE		5
141 #define	CMD_RCM_CAP_ADD		6
142 #define	CMD_SUSPEND_CHECK	7
143 #define	CMD_RCM_SUSPEND		8
144 #define	CMD_RCM_CAP_DEL		9
145 #define	CMD_RCM_OFFLINE		10
146 #define	CMD_UNCONFIGURE		11
147 #define	CMD_RCM_REMOVE		12
148 #define	CMD_RCM_CAP_NOTIFY	13
149 #define	CMD_DISCONNECT		14
150 #define	CMD_POWEROFF		15
151 #define	CMD_UNASSIGN		16
152 #define	CMD_RCM_RESUME		17
153 #define	CMD_STATUS		18
154 #define	CMD_GETNCM		19
155 #define	CMD_PASSTHRU		20
156 #define	CMD_HELP		21
157 #define	CMD_ERRTEST		22
158 #define	CMD_NONE		23
159 
160 /*
161  * Error messages.
162  */
163 #define	ERR_CMD_INVAL		0
164 #define	ERR_CMD_FAIL		1
165 #define	ERR_CMD_NACK		2
166 #define	ERR_CMD_NOTSUPP		3
167 #define	ERR_CMD_ABORT		4
168 #define	ERR_OPT_INVAL		5
169 #define	ERR_OPT_NOVAL		6
170 #define	ERR_OPT_VAL		7
171 #define	ERR_OPT_BADVAL		8
172 #define	ERR_AP_INVAL		9
173 #define	ERR_CM_INVAL		10
174 #define	ERR_TRANS_INVAL		11
175 #define	ERR_SIG_CHANGE		12
176 #define	ERR_RCM_HANDLE		13
177 #define	ERR_RCM_CMD		14
178 #define	ERR_RCM_INFO		15
179 #define	ERR_LIB_OPEN		16
180 #define	ERR_LIB_SYM		17
181 #define	ERR_STAT		18
182 #define	ERR_NOMEM		19
183 #define	ERR_PLUGIN		20
184 #define	ERR_NONE		21
185 
186 #define	MSG_ISSUE		0
187 #define	MSG_SKIP		1
188 #define	MSG_SUSPEND		2
189 #define	MSG_ABORT		3
190 #define	MSG_DONE		4
191 #define	MSG_FAIL		5
192 #define	MSG_NORCM		6
193 #define	MSG_NONE		7
194 
195 #define	s_free(x)	(((x) != NULL) ? (free(x), (x) = NULL) : (void *)0)
196 #define	str_valid(p)	((p) != NULL && *(p) != '\0')
197 #define	mask(x)		((uint_t)1 << (x))
198 
199 #define	CM_DFLT		-1	/* default (current) component */
200 
201 int ap_cnt(apd_t *);
202 int ap_parse(apd_t *, const char *);
203 int ap_confirm(apd_t *);
204 int ap_state_cmd(cfga_cmd_t, int *);
205 int ap_symid(apd_t *, char *, char *, size_t);
206 char *ap_sys_err(apd_t *, char **);
207 char *ap_cmd_name(int);
208 char *ap_opt_name(int);
209 char *ap_logid(apd_t *, char *);
210 void ap_err(apd_t *, ...);
211 void ap_msg(apd_t *, ...);
212 void ap_info(apd_t *, cfga_info_t, ap_target_t);
213 void ap_init(apd_t *, cfga_list_data_t *);
214 void ap_state(apd_t *, cfga_stat_t *, cfga_stat_t *);
215 cfga_err_t ap_stat(apd_t *a, int);
216 cfga_err_t ap_ioctl(apd_t *, int);
217 cfga_err_t ap_help(struct cfga_msg *, const char *, cfga_flags_t);
218 cfga_err_t ap_cmd_exec(apd_t *, int);
219 cfga_err_t ap_cmd_seq(apd_t *, int);
220 cfga_err_t ap_suspend_query(apd_t *, int, int *);
221 cfga_err_t ap_platopts_check(apd_t *, int, int);
222 cfga_err_t ap_cmd_parse(apd_t *, const char *, const char *, int *);
223 cfga_err_t ap_test_err(apd_t *, const char *);
224 
225 int ap_cm_capacity(apd_t *, int, void *, int *, cfga_stat_t *);
226 int ap_cm_ncap(apd_t *, int);
227 void ap_cm_id(apd_t *, int, char *, size_t);
228 void ap_cm_init(apd_t *, cfga_list_data_t *, int);
229 char *ap_cm_devpath(apd_t *, int);
230 ap_target_t ap_cm_type(apd_t *, int);
231 
232 cfga_err_t ap_rcm_init(apd_t *);
233 void ap_rcm_fini(apd_t *);
234 cfga_err_t ap_rcm_ctl(apd_t *, int);
235 int ap_rcm_info(apd_t *, char **);
236 
237 apd_t *apd_alloc(const char *, cfga_flags_t, char **,
238 	struct cfga_msg *, struct cfga_confirm *);
239 void apd_free(apd_t *a);
240 cfga_err_t apd_init(apd_t *, int);
241 
242 int debugging();
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 
248 #endif	/* _CFGA_SBD_H */
249