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