xref: /titanic_51/usr/src/lib/fm/libldom/sparc/ldmsvcs_utils.h (revision 25351652d920ae27c5a56c199da581033ce763f6)
131e37bb4Svn83148 /*
231e37bb4Svn83148  * CDDL HEADER START
331e37bb4Svn83148  *
431e37bb4Svn83148  * The contents of this file are subject to the terms of the
531e37bb4Svn83148  * Common Development and Distribution License (the "License").
631e37bb4Svn83148  * You may not use this file except in compliance with the License.
731e37bb4Svn83148  *
831e37bb4Svn83148  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
931e37bb4Svn83148  * or http://www.opensolaris.org/os/licensing.
1031e37bb4Svn83148  * See the License for the specific language governing permissions
1131e37bb4Svn83148  * and limitations under the License.
1231e37bb4Svn83148  *
1331e37bb4Svn83148  * When distributing Covered Code, include this CDDL HEADER in each
1431e37bb4Svn83148  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1531e37bb4Svn83148  * If applicable, add the following below this CDDL HEADER, with the
1631e37bb4Svn83148  * fields enclosed by brackets "[]" replaced with your own identifying
1731e37bb4Svn83148  * information: Portions Copyright [yyyy] [name of copyright owner]
1831e37bb4Svn83148  *
1931e37bb4Svn83148  * CDDL HEADER END
2031e37bb4Svn83148  */
2131e37bb4Svn83148 /*
225f149bcaScy152378  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
2331e37bb4Svn83148  * Use is subject to license terms.
2431e37bb4Svn83148  */
2531e37bb4Svn83148 
2631e37bb4Svn83148 #ifndef	_LDMSVCS_UTILS_H
2731e37bb4Svn83148 #define	_LDMSVCS_UTILS_H
2831e37bb4Svn83148 
2931e37bb4Svn83148 #include <stdlib.h>
3031e37bb4Svn83148 #include <sys/types.h>
3131e37bb4Svn83148 #include <sys/ldc.h>
3231e37bb4Svn83148 #include <sys/vldc.h>
3331e37bb4Svn83148 #include <sys/ds.h>
3431e37bb4Svn83148 #include <sys/ds_impl.h>
3531e37bb4Svn83148 
3631e37bb4Svn83148 #ifdef	__cplusplus
3731e37bb4Svn83148 extern "C" {
3831e37bb4Svn83148 #endif
3931e37bb4Svn83148 
4031e37bb4Svn83148 /*
4131e37bb4Svn83148  * Service Information
4231e37bb4Svn83148  */
4331e37bb4Svn83148 typedef struct fds_svc {
4431e37bb4Svn83148 	ds_svc_hdl_t hdl;	/* handle assigned by DS */
4531e37bb4Svn83148 	ds_svc_state_t state;	/* current service state */
4631e37bb4Svn83148 	ds_ver_t ver;		/* svc protocol version in use */
4731e37bb4Svn83148 	char *name;
4831e37bb4Svn83148 } fds_svc_t;
4931e37bb4Svn83148 
5031e37bb4Svn83148 /*
5131e37bb4Svn83148  * table of registered services
5231e37bb4Svn83148  */
5331e37bb4Svn83148 typedef struct fds_reg_svcs {
5431e37bb4Svn83148 	pthread_mutex_t mt;
5531e37bb4Svn83148 	pthread_cond_t cv;
5631e37bb4Svn83148 	fds_svc_t **tbl;		/* the table itself */
5731e37bb4Svn83148 	uint_t nsvcs;		/* current number of items */
5831e37bb4Svn83148 } fds_reg_svcs_t;
5931e37bb4Svn83148 
6031e37bb4Svn83148 
6131e37bb4Svn83148 typedef enum {
6231e37bb4Svn83148 	CHANNEL_UNINITIALIZED,	/* status of channel unknown */
6331e37bb4Svn83148 	CHANNEL_CLOSED,		/* port structure not in use */
6431e37bb4Svn83148 	CHANNEL_OPEN,		/* open but not initialized/reset */
6531e37bb4Svn83148 	CHANNEL_READY,		/* init/reset done */
6631e37bb4Svn83148 	CHANNEL_UNUSABLE,	/* cannot be used (possibly busy) */
6731e37bb4Svn83148 	CHANNEL_EXIT		/* normal exit */
6831e37bb4Svn83148 } fds_chan_state_t;
6931e37bb4Svn83148 
7031e37bb4Svn83148 typedef struct fds_channel {
7131e37bb4Svn83148 	int fd;			/* FD for this channel */
7231e37bb4Svn83148 	fds_chan_state_t state; /* state of the port */
7331e37bb4Svn83148 	ds_ver_t ver;		/* DS protocol version in use */
7431e37bb4Svn83148 } fds_channel_t;
7531e37bb4Svn83148 
7631e37bb4Svn83148 
7731e37bb4Svn83148 /*
7831e37bb4Svn83148  * FMA services
7931e37bb4Svn83148  */
80*25351652SVuong Nguyen 
81*25351652SVuong Nguyen #define	LDM_DS_NAME_CPU		"fma-phys-cpu-service"
82*25351652SVuong Nguyen #define	LDM_DS_NAME_MEM		"fma-phys-mem-service"
83*25351652SVuong Nguyen #define	LDM_DS_NAME_PRI		"fma-pri-service"
84*25351652SVuong Nguyen #define	LDM_DS_NAME_IOD		"fma-io-domain-service"
85*25351652SVuong Nguyen 
8631e37bb4Svn83148 typedef struct {
8731e37bb4Svn83148 	uint64_t req_num;
8831e37bb4Svn83148 } fma_req_pri_t;
8931e37bb4Svn83148 
9031e37bb4Svn83148 /*
9131e37bb4Svn83148  * definition of fma_pri_resp_t is not shown here.  for more details,
9231e37bb4Svn83148  * see ldmsvcs_utils.c:ldmsvcs_get_core_md().
9331e37bb4Svn83148  */
9431e37bb4Svn83148 
9531e37bb4Svn83148 #define	FMA_CPU_REQ_STATUS	0
9631e37bb4Svn83148 #define	FMA_CPU_REQ_OFFLINE	1
9731e37bb4Svn83148 #define	FMA_CPU_REQ_ONLINE	2
9831e37bb4Svn83148 
9931e37bb4Svn83148 #define	FMA_CPU_RESP_OK		0
10031e37bb4Svn83148 #define	FMA_CPU_RESP_FAILURE	1
10131e37bb4Svn83148 
10231e37bb4Svn83148 #define	FMA_CPU_STAT_ONLINE	0
10331e37bb4Svn83148 #define	FMA_CPU_STAT_OFFLINE	1
10431e37bb4Svn83148 #define	FMA_CPU_STAT_ILLEGAL	2
10531e37bb4Svn83148 
10631e37bb4Svn83148 typedef struct {
10731e37bb4Svn83148 	uint64_t req_num;
10831e37bb4Svn83148 	uint32_t msg_type;
10931e37bb4Svn83148 	uint32_t cpu_id;
11031e37bb4Svn83148 } fma_cpu_service_req_t;
11131e37bb4Svn83148 
11231e37bb4Svn83148 typedef struct {
11331e37bb4Svn83148 	uint64_t req_num;
11431e37bb4Svn83148 	uint32_t result;
11531e37bb4Svn83148 	uint32_t status;
11631e37bb4Svn83148 } fma_cpu_resp_t;
11731e37bb4Svn83148 
11831e37bb4Svn83148 #define	FMA_MEM_REQ_STATUS	0
11931e37bb4Svn83148 #define	FMA_MEM_REQ_RETIRE	1
12031e37bb4Svn83148 #define	FMA_MEM_REQ_RESURRECT	2
12131e37bb4Svn83148 
12231e37bb4Svn83148 #define	FMA_MEM_RESP_OK		0
12331e37bb4Svn83148 #define	FMA_MEM_RESP_FAILURE	1
12431e37bb4Svn83148 
12531e37bb4Svn83148 #define	FMA_MEM_STAT_NOTRETIRED	0
12631e37bb4Svn83148 #define	FMA_MEM_STAT_RETIRED	1
12731e37bb4Svn83148 #define	FMA_MEM_STAT_ILLEGAL	2
12831e37bb4Svn83148 
12931e37bb4Svn83148 typedef struct {
13031e37bb4Svn83148 	uint64_t req_num;
13131e37bb4Svn83148 	uint32_t msg_type;
13231e37bb4Svn83148 	uint32_t _resvd;
13331e37bb4Svn83148 	uint64_t real_addr;
13431e37bb4Svn83148 	uint64_t length;
13531e37bb4Svn83148 } fma_mem_service_req_t;
13631e37bb4Svn83148 
13731e37bb4Svn83148 typedef struct {
13831e37bb4Svn83148 	uint64_t req_num;
13931e37bb4Svn83148 	uint32_t result;
14031e37bb4Svn83148 	uint32_t status;
14131e37bb4Svn83148 	uint64_t res_addr;
14231e37bb4Svn83148 	uint64_t res_length;
14331e37bb4Svn83148 } fma_mem_resp_t;
14431e37bb4Svn83148 
14531e37bb4Svn83148 
146*25351652SVuong Nguyen #define	FMA_IO_RESP_OK		0
147*25351652SVuong Nguyen #define	FMA_IO_RESP_FAILURE	1
148*25351652SVuong Nguyen #define	FMA_IO_RESP_ILLEGAL	2
149*25351652SVuong Nguyen #define	FMA_IO_RESP_UNASSIGNED	3
150*25351652SVuong Nguyen 
151*25351652SVuong Nguyen typedef struct {
152*25351652SVuong Nguyen 	uint64_t req_num;
153*25351652SVuong Nguyen 	uint32_t msg_type;
154*25351652SVuong Nguyen 	uint32_t reserved;
155*25351652SVuong Nguyen 	uint64_t rsrc_address;
156*25351652SVuong Nguyen } fma_io_req_t;
157*25351652SVuong Nguyen 
158*25351652SVuong Nguyen typedef struct {
159*25351652SVuong Nguyen 	uint64_t req_num;
160*25351652SVuong Nguyen 	uint32_t result;
161*25351652SVuong Nguyen 	uint32_t reserved;
162*25351652SVuong Nguyen 	uint64_t virt_rsrc_address;
163*25351652SVuong Nguyen 	uint64_t domain_id;
164*25351652SVuong Nguyen } fma_io_resp_t;
165*25351652SVuong Nguyen 
166*25351652SVuong Nguyen 
16731e37bb4Svn83148 struct ldom_hdl {
16831e37bb4Svn83148 	void *(*allocp)(size_t size);
16931e37bb4Svn83148 	void (*freep)(void *addr, size_t size);
17031e37bb4Svn83148 	struct ldmsvcs_info *lsinfo;
17131e37bb4Svn83148 };
17231e37bb4Svn83148 
173c3b50bc5Srb144127 /*
174c3b50bc5Srb144127  * in the default case of ldmd (the LDOM manager daemon/service)
175c3b50bc5Srb144127  * not installed/running, set short timeouts for contacting ldmd,
176c3b50bc5Srb144127  * so that higher levels in the software stack (ex: diagnosis engines)
177c3b50bc5Srb144127  * are not excessively delayed by ldmd's absence. both timeouts are tunable
178c3b50bc5Srb144127  * via SMF properties in ldmd's service manifest, and expected to be set
179c3b50bc5Srb144127  * thusly to appropriate values when ldmd is installed.
180c3b50bc5Srb144127  *
181c3b50bc5Srb144127  * timeouts are in seconds. init is the initial timeout; running is
182c3b50bc5Srb144127  * for subsequent timeouts.
183c3b50bc5Srb144127  */
184c3b50bc5Srb144127 #define	LDM_INIT_WAIT_TIME	2
185c3b50bc5Srb144127 #define	LDM_RUNNING_WAIT_TIME	2
186c3b50bc5Srb144127 
187c3b50bc5Srb144127 #define	LDM_SVC_NM		"svc:/ldoms/ldmd:default"
188c3b50bc5Srb144127 #define	LDM_PROP_GROUP_NM	"fmd_config"
189c3b50bc5Srb144127 
190c3b50bc5Srb144127 #define	LDM_INIT_TO_PROP_NM	"fmd_to_ldmd_init_timeout"
191c3b50bc5Srb144127 #define	LDM_RUNNING_TO_PROP_NM	"fmd_to_ldmd_running_timeout"
19231e37bb4Svn83148 
19331e37bb4Svn83148 extern int ldmsvcs_check_channel(void);
19431e37bb4Svn83148 
19531e37bb4Svn83148 extern void ldmsvcs_init(struct ldom_hdl *lhp);
19631e37bb4Svn83148 
19731e37bb4Svn83148 extern void ldmsvcs_fini(struct ldom_hdl *lhp);
19831e37bb4Svn83148 
19931e37bb4Svn83148 extern ssize_t ldmsvcs_get_core_md(struct ldom_hdl *lhp, uint64_t **buf);
20031e37bb4Svn83148 
20131e37bb4Svn83148 extern int ldmsvcs_cpu_req_status(struct ldom_hdl *lhp, uint32_t cpuid);
20231e37bb4Svn83148 
20331e37bb4Svn83148 extern int ldmsvcs_mem_req_status(struct ldom_hdl *lhp, uint64_t pa);
20431e37bb4Svn83148 
20531e37bb4Svn83148 extern int ldmsvcs_cpu_req_offline(struct ldom_hdl *lhp, uint32_t cpuid);
20631e37bb4Svn83148 
20731e37bb4Svn83148 extern int ldmsvcs_mem_req_retire(struct ldom_hdl *lhp, uint64_t pa);
20831e37bb4Svn83148 
2095f149bcaScy152378 extern int ldmsvcs_cpu_req_online(struct ldom_hdl *lhp, uint32_t cpuid);
2105f149bcaScy152378 
2115f149bcaScy152378 extern int ldmsvcs_mem_req_unretire(struct ldom_hdl *lhp, uint64_t pa);
2125f149bcaScy152378 
213*25351652SVuong Nguyen extern int ldmsvcs_io_req_id(struct ldom_hdl *lhp, uint64_t addr, uint_t type,
214*25351652SVuong Nguyen     uint64_t *virt_addr, char *name, int name_len, uint64_t *did);
215*25351652SVuong Nguyen 
21631e37bb4Svn83148 #ifdef	__cplusplus
21731e37bb4Svn83148 }
21831e37bb4Svn83148 #endif
21931e37bb4Svn83148 
22031e37bb4Svn83148 #endif	/* _LDMSVCS_UTILS_H */
221