summaryrefslogtreecommitdiff
path: root/usr/src/cmd/ldmad/ldma.h
blob: f0253b6af75b6f8c91a8bc8da29ce1bc1617d5e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

#ifndef _LDMA_H
#define	_LDMA_H

#include <libds.h>
#include <sys/sysmacros.h>
#include <sys/types.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * The following definitions are part of the LDoms Agent specification.
 */

/* reply message types */
#define	LDMA_MSG_RESULT			0x8000	/* result message */
#define	LDMA_MSG_ERROR			0x8001	/* error message */

/* error codes for error messages */
#define	LDMA_MSGERR_FAIL		0x0000	/* request has failed */
#define	LDMA_MSGERR_INVALID		0x8001	/* request is invalid */
#define	LDMA_MSGERR_NOTSUP		0x8002	/* request is not supported */
#define	LDMA_MSGERR_DENY		0x8003	/* request is denied */

/*
 * LDoms Device Agent
 */
#define	LDMA_NAME_DEVICE		"agent-device"

#define	LDMA_MSGDEV_VALIDATE_PATH	0x01	/* validate path */
#define	LDMA_MSGDEV_VALIDATE_NIC	0x02	/* validate network interface */

#define	LDMA_DEVPATH_EXIST		0x01	/* path is accessible */
#define	LDMA_DEVPATH_OPENRW		0x02	/* path can be opened rw */
#define	LDMA_DEVPATH_OPENRO		0x04	/* path can be opened ro */

#define	LDMA_DEVPATH_TYPE_UNKNOWN	0x00	/* path points to unknown */
#define	LDMA_DEVPATH_TYPE_FILE		0x01    /* path points to a file */
#define	LDMA_DEVPATH_TYPE_DEVICE	0x02	/* path points to a device */

#define	LDMA_DEVNIC_EXIST		0x01	/* nic is accessible */

/*
 * LDoms System Agent
 */
#define	LDMA_NAME_SYSTEM		"agent-system"

#define	LDMA_MSGSYS_GET_SYSINFO		0x01	/* get system info request */
#define	LDMA_MSGSYS_GET_CHASSISNO	0x02	/* get chassis sno request */

/*
 * LDoms Direct IO Agent
 */
#define	LDMA_NAME_DIO		"agent-dio"

#define	MSGDIO_PCIDEV_INFO	0x1		/* pci device info request */


/*
 * Size of the header of an agent message. This is the minimal size that
 * a message can have.
 */
#define	LDMA_MESSAGE_HEADER_SIZE	(sizeof (ldma_message_header_t))

/*
 * Macro to compute the size of a message with a msg_data of size dlen.
 * The size of the msg_data field must be a multiple of 8-bytes so dlen
 * is roundup to an 8-bytes multiple.
 */
#define	LDMA_MESSAGE_SIZE(dlen)	(LDMA_MESSAGE_HEADER_SIZE + P2ROUNDUP(dlen, 8))

/*
 * Macro to compute the size of the msg_data field from the size of the message.
 */
#define	LDMA_MESSAGE_DLEN(msgsize)	((msgsize) - LDMA_MESSAGE_HEADER_SIZE)

/*
 * Handy macros for using the message and header structures.
 */
#define	LDMA_HDR2MSG(hdr)	((ldma_message_t *)(hdr))
#define	LDMA_HDR2DATA(hdr)	(LDMA_HDR2MSG(hdr)->msg_data)
#define	LDMA_MSG2HDR(msg)	((ldma_message_header_t *)(msg))

/* agent message header structure */
typedef struct ldma_message_header {
	uint64_t	msg_num; 	/* message number */
	uint32_t	msg_type;	/* message type */
	uint32_t	msg_info;	/* message info */
} ldma_message_header_t;

/* agent message structure */
typedef struct ldma_message {
	ldma_message_header_t	msg_hdr;	/* message header */
	char			msg_data[1];	/* message data */
} ldma_message_t;

/*
 * Additional structures and definition for the implementation.
 */
typedef enum ldma_request_status_t {
	LDMA_REQ_COMPLETED,		/* request was completed */
	LDMA_REQ_FAILED,		/* request has failed */
	LDMA_REQ_INVALID,		/* request is invalid */
	LDMA_REQ_NOTSUP,		/* request is not supported */
	LDMA_REQ_DENIED			/* request was denied */
} ldma_request_status_t;

typedef ldma_request_status_t (ldm_msg_func_t)(ds_ver_t *,
    ldma_message_header_t *, size_t, ldma_message_header_t **, size_t *);

/*
 * The domain service framework only allows connexion of a domain with
 * the control domain. So agents not running in the control domain can
 * only receive requests from the control domain. But, agents running
 * on the control can receive requests from any domain.
 *
 * For agents running in the control domain, the LDMA_MSGFLG_ACCESS_*
 * flags control whether messages sent by domains different from the
 * control domain should be processed or not.
 *
 * If a message handler is defined with LDMA_MSGFLG_ACCESS_CONTROL then
 * only messages sent by the control domain should be processed. Otherwise
 * if a message handler is defined with LDMA_MSGFLG_ACCESS_ANY then messages
 * sent by any domain can be processed.
 */
#define	LDMA_MSGFLG_ACCESS_CONTROL	0x00
#define	LDMA_MSGFLG_ACCESS_ANY		0x01

typedef struct ldma_msg_handler {
	uint32_t		msg_type; 	/* message type */
	uint32_t		msg_flags;	/* message flags */
	ldm_msg_func_t		*msg_handler;	/* message handler */
} ldma_msg_handler_t;

typedef struct ldma_agent_info {
	char			*name;		/* agent name */
	ds_ver_t		*vers;		/* supported versions */
	int			nvers;		/* number of versions */
	ldma_msg_handler_t	*handlers;	/* message handlers */
	int			nhandlers;	/* number of handlers */
} ldma_agent_info_t;

/*
 * Helper functions for the daemon and agents.
 */

/* function to allocate a result message */
ldma_message_header_t *ldma_alloc_result_msg(ldma_message_header_t *, size_t);

/* functions to log messages */
void ldma_err(char *module, char *fmt, ...);
void ldma_info(char *module, char *fmt, ...);
void ldma_dbg(char *module, char *fmt, ...);

/*
 * Macros to log messages. Each module/file using these macros should define
 * LDMA_MODULE as the name under which messages are logged. For a given agent,
 * LDMA_MODULE should be set to the name of the agent.
 */
#define	LDMA_ERR(...)	ldma_err(LDMA_MODULE, __VA_ARGS__)
#define	LDMA_INFO(...)	ldma_info(LDMA_MODULE, __VA_ARGS__)
#define	LDMA_DBG(...)	ldma_dbg(LDMA_MODULE, __VA_ARGS__)

#ifdef __cplusplus
}
#endif

#endif /* _LDMA_H */