xref: /titanic_41/usr/src/lib/fm/libldom/sparc/ldmsvcs_utils.h (revision 43b9c05035ac59f7f7a8e7827598db5a15f30ed3)
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	_LDMSVCS_UTILS_H
27 #define	_LDMSVCS_UTILS_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <stdlib.h>
32 #include <sys/types.h>
33 #include <sys/ldc.h>
34 #include <sys/vldc.h>
35 #include <sys/ds.h>
36 #include <sys/ds_impl.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Service Information
44  */
45 typedef struct fds_svc {
46 	ds_svc_hdl_t hdl;	/* handle assigned by DS */
47 	ds_svc_state_t state;	/* current service state */
48 	ds_ver_t ver;		/* svc protocol version in use */
49 	char *name;
50 } fds_svc_t;
51 
52 /*
53  * table of registered services
54  */
55 typedef struct fds_reg_svcs {
56 	pthread_mutex_t mt;
57 	pthread_cond_t cv;
58 	fds_svc_t **tbl;		/* the table itself */
59 	uint_t nsvcs;		/* current number of items */
60 } fds_reg_svcs_t;
61 
62 
63 typedef enum {
64 	CHANNEL_UNINITIALIZED,	/* status of channel unknown */
65 	CHANNEL_CLOSED,		/* port structure not in use */
66 	CHANNEL_OPEN,		/* open but not initialized/reset */
67 	CHANNEL_READY,		/* init/reset done */
68 	CHANNEL_UNUSABLE,	/* cannot be used (possibly busy) */
69 	CHANNEL_EXIT		/* normal exit */
70 } fds_chan_state_t;
71 
72 typedef struct fds_channel {
73 	int fd;			/* FD for this channel */
74 	fds_chan_state_t state; /* state of the port */
75 	ds_ver_t ver;		/* DS protocol version in use */
76 } fds_channel_t;
77 
78 
79 /*
80  * FMA services
81  */
82 typedef struct {
83 	uint64_t req_num;
84 } fma_req_pri_t;
85 
86 /*
87  * definition of fma_pri_resp_t is not shown here.  for more details,
88  * see ldmsvcs_utils.c:ldmsvcs_get_core_md().
89  */
90 
91 #define	FMA_CPU_REQ_STATUS	0
92 #define	FMA_CPU_REQ_OFFLINE	1
93 #define	FMA_CPU_REQ_ONLINE	2
94 
95 #define	FMA_CPU_RESP_OK		0
96 #define	FMA_CPU_RESP_FAILURE	1
97 
98 #define	FMA_CPU_STAT_ONLINE	0
99 #define	FMA_CPU_STAT_OFFLINE	1
100 #define	FMA_CPU_STAT_ILLEGAL	2
101 
102 typedef struct {
103 	uint64_t req_num;
104 	uint32_t msg_type;
105 	uint32_t cpu_id;
106 } fma_cpu_service_req_t;
107 
108 typedef struct {
109 	uint64_t req_num;
110 	uint32_t result;
111 	uint32_t status;
112 } fma_cpu_resp_t;
113 
114 #define	FMA_MEM_REQ_STATUS	0
115 #define	FMA_MEM_REQ_RETIRE	1
116 #define	FMA_MEM_REQ_RESURRECT	2
117 
118 #define	FMA_MEM_RESP_OK		0
119 #define	FMA_MEM_RESP_FAILURE	1
120 
121 #define	FMA_MEM_STAT_NOTRETIRED	0
122 #define	FMA_MEM_STAT_RETIRED	1
123 #define	FMA_MEM_STAT_ILLEGAL	2
124 
125 typedef struct {
126 	uint64_t req_num;
127 	uint32_t msg_type;
128 	uint32_t _resvd;
129 	uint64_t real_addr;
130 	uint64_t length;
131 } fma_mem_service_req_t;
132 
133 typedef struct {
134 	uint64_t req_num;
135 	uint32_t result;
136 	uint32_t status;
137 	uint64_t res_addr;
138 	uint64_t res_length;
139 } fma_mem_resp_t;
140 
141 
142 struct ldom_hdl {
143 	int major_version;
144 	int service_ldom;
145 	void *(*allocp)(size_t size);
146 	void (*freep)(void *addr, size_t size);
147 	struct ldmsvcs_info *lsinfo;
148 };
149 
150 /*
151  * in the default case of ldmd (the LDOM manager daemon/service)
152  * not installed/running, set short timeouts for contacting ldmd,
153  * so that higher levels in the software stack (ex: diagnosis engines)
154  * are not excessively delayed by ldmd's absence. both timeouts are tunable
155  * via SMF properties in ldmd's service manifest, and expected to be set
156  * thusly to appropriate values when ldmd is installed.
157  *
158  * timeouts are in seconds. init is the initial timeout; running is
159  * for subsequent timeouts.
160  */
161 #define	LDM_INIT_WAIT_TIME	2
162 #define	LDM_RUNNING_WAIT_TIME	2
163 
164 #define	LDM_SVC_NM		"svc:/ldoms/ldmd:default"
165 #define	LDM_PROP_GROUP_NM	"fmd_config"
166 
167 #define	LDM_INIT_TO_PROP_NM	"fmd_to_ldmd_init_timeout"
168 #define	LDM_RUNNING_TO_PROP_NM	"fmd_to_ldmd_running_timeout"
169 
170 extern int ldmsvcs_check_channel(void);
171 
172 extern void ldmsvcs_init(struct ldom_hdl *lhp);
173 
174 extern void ldmsvcs_fini(struct ldom_hdl *lhp);
175 
176 extern ssize_t ldmsvcs_get_core_md(struct ldom_hdl *lhp, uint64_t **buf);
177 
178 extern int ldmsvcs_cpu_req_status(struct ldom_hdl *lhp, uint32_t cpuid);
179 
180 extern int ldmsvcs_mem_req_status(struct ldom_hdl *lhp, uint64_t pa);
181 
182 extern int ldmsvcs_cpu_req_offline(struct ldom_hdl *lhp, uint32_t cpuid);
183 
184 extern int ldmsvcs_mem_req_retire(struct ldom_hdl *lhp, uint64_t pa);
185 
186 extern int ldmsvcs_cpu_req_online(struct ldom_hdl *lhp, uint32_t cpuid);
187 
188 extern int ldmsvcs_mem_req_unretire(struct ldom_hdl *lhp, uint64_t pa);
189 
190 #ifdef	__cplusplus
191 }
192 #endif
193 
194 #endif	/* _LDMSVCS_UTILS_H */
195