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