xref: /titanic_41/usr/src/cmd/ldmad/ldma.h (revision f3312ec0e8acbd249df97358fb8c3ca92f4e089c)
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 /*
23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _LDMA_H
28 #define	_LDMA_H
29 
30 #include <libds.h>
31 #include <sys/sysmacros.h>
32 #include <sys/types.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * The following definitions are part of the LDoms Agent specification.
40  */
41 
42 /* reply message types */
43 #define	LDMA_MSG_RESULT			0x8000	/* result message */
44 #define	LDMA_MSG_ERROR			0x8001	/* error message */
45 
46 /* error codes for error messages */
47 #define	LDMA_MSGERR_FAIL		0x0000	/* request has failed */
48 #define	LDMA_MSGERR_INVALID		0x8001	/* request is invalid */
49 #define	LDMA_MSGERR_NOTSUP		0x8002	/* request is not supported */
50 #define	LDMA_MSGERR_DENY		0x8003	/* request is denied */
51 
52 /*
53  * LDoms Device Agent
54  */
55 #define	LDMA_NAME_DEVICE		"agent-device"
56 
57 #define	LDMA_MSGDEV_VALIDATE_PATH	0x01	/* validate path */
58 #define	LDMA_MSGDEV_VALIDATE_NIC	0x02	/* validate network interface */
59 
60 #define	LDMA_DEVPATH_EXIST		0x01	/* path is accessible */
61 #define	LDMA_DEVPATH_OPENRW		0x02	/* path can be opened rw */
62 #define	LDMA_DEVPATH_OPENRO		0x04	/* path can be opened ro */
63 
64 #define	LDMA_DEVPATH_TYPE_UNKNOWN	0x00	/* path points to unknown */
65 #define	LDMA_DEVPATH_TYPE_FILE		0x01    /* path points to a file */
66 #define	LDMA_DEVPATH_TYPE_DEVICE	0x02	/* path points to a device */
67 
68 #define	LDMA_DEVNIC_EXIST		0x01	/* nic is accessible */
69 
70 /*
71  * LDoms System Agent
72  */
73 #define	LDMA_NAME_SYSTEM		"agent-system"
74 
75 #define	LDMA_MSGSYS_GET_SYSINFO		0x01	/* get system info request */
76 #define	LDMA_MSGSYS_GET_CHASSISNO	0x02	/* get chassis sno request */
77 
78 /*
79  * LDoms Direct IO Agent
80  */
81 #define	LDMA_NAME_DIO		"agent-dio"
82 
83 #define	MSGDIO_PCIDEV_INFO	0x1		/* pci device info request */
84 
85 
86 /*
87  * Size of the header of an agent message. This is the minimal size that
88  * a message can have.
89  */
90 #define	LDMA_MESSAGE_HEADER_SIZE	(sizeof (ldma_message_header_t))
91 
92 /*
93  * Macro to compute the size of a message with a msg_data of size dlen.
94  * The size of the msg_data field must be a multiple of 8-bytes so dlen
95  * is roundup to an 8-bytes multiple.
96  */
97 #define	LDMA_MESSAGE_SIZE(dlen)	(LDMA_MESSAGE_HEADER_SIZE + P2ROUNDUP(dlen, 8))
98 
99 /*
100  * Macro to compute the size of the msg_data field from the size of the message.
101  */
102 #define	LDMA_MESSAGE_DLEN(msgsize)	((msgsize) - LDMA_MESSAGE_HEADER_SIZE)
103 
104 /*
105  * Handy macros for using the message and header structures.
106  */
107 #define	LDMA_HDR2MSG(hdr)	((ldma_message_t *)(hdr))
108 #define	LDMA_HDR2DATA(hdr)	(LDMA_HDR2MSG(hdr)->msg_data)
109 #define	LDMA_MSG2HDR(msg)	((ldma_message_header_t *)(msg))
110 
111 /* agent message header structure */
112 typedef struct ldma_message_header {
113 	uint64_t	msg_num; 	/* message number */
114 	uint32_t	msg_type;	/* message type */
115 	uint32_t	msg_info;	/* message info */
116 } ldma_message_header_t;
117 
118 /* agent message structure */
119 typedef struct ldma_message {
120 	ldma_message_header_t	msg_hdr;	/* message header */
121 	char			msg_data[1];	/* message data */
122 } ldma_message_t;
123 
124 /*
125  * Additional structures and definition for the implementation.
126  */
127 typedef enum ldma_request_status_t {
128 	LDMA_REQ_COMPLETED,		/* request was completed */
129 	LDMA_REQ_FAILED,		/* request has failed */
130 	LDMA_REQ_INVALID,		/* request is invalid */
131 	LDMA_REQ_NOTSUP,		/* request is not supported */
132 	LDMA_REQ_DENIED			/* request was denied */
133 } ldma_request_status_t;
134 
135 typedef ldma_request_status_t (ldm_msg_func_t)(ds_ver_t *,
136     ldma_message_header_t *, size_t, ldma_message_header_t **, size_t *);
137 
138 /*
139  * The domain service framework only allows connexion of a domain with
140  * the control domain. So agents not running in the control domain can
141  * only receive requests from the control domain. But, agents running
142  * on the control can receive requests from any domain.
143  *
144  * For agents running in the control domain, the LDMA_MSGFLG_ACCESS_*
145  * flags control whether messages sent by domains different from the
146  * control domain should be processed or not.
147  *
148  * If a message handler is defined with LDMA_MSGFLG_ACCESS_CONTROL then
149  * only messages sent by the control domain should be processed. Otherwise
150  * if a message handler is defined with LDMA_MSGFLG_ACCESS_ANY then messages
151  * sent by any domain can be processed.
152  */
153 #define	LDMA_MSGFLG_ACCESS_CONTROL	0x00
154 #define	LDMA_MSGFLG_ACCESS_ANY		0x01
155 
156 typedef struct ldma_msg_handler {
157 	uint32_t		msg_type; 	/* message type */
158 	uint32_t		msg_flags;	/* message flags */
159 	ldm_msg_func_t		*msg_handler;	/* message handler */
160 } ldma_msg_handler_t;
161 
162 typedef struct ldma_agent_info {
163 	char			*name;		/* agent name */
164 	ds_ver_t		*vers;		/* supported versions */
165 	int			nvers;		/* number of versions */
166 	ldma_msg_handler_t	*handlers;	/* message handlers */
167 	int			nhandlers;	/* number of handlers */
168 } ldma_agent_info_t;
169 
170 /*
171  * Helper functions for the daemon and agents.
172  */
173 
174 /* function to allocate a result message */
175 ldma_message_header_t *ldma_alloc_result_msg(ldma_message_header_t *, size_t);
176 
177 /* functions to log messages */
178 void ldma_err(char *module, char *fmt, ...);
179 void ldma_info(char *module, char *fmt, ...);
180 void ldma_dbg(char *module, char *fmt, ...);
181 
182 /*
183  * Macros to log messages. Each module/file using these macros should define
184  * LDMA_MODULE as the name under which messages are logged. For a given agent,
185  * LDMA_MODULE should be set to the name of the agent.
186  */
187 #define	LDMA_ERR(...)	ldma_err(LDMA_MODULE, __VA_ARGS__)
188 #define	LDMA_INFO(...)	ldma_info(LDMA_MODULE, __VA_ARGS__)
189 #define	LDMA_DBG(...)	ldma_dbg(LDMA_MODULE, __VA_ARGS__)
190 
191 #ifdef __cplusplus
192 }
193 #endif
194 
195 #endif /* _LDMA_H */
196