xref: /titanic_50/usr/src/cmd/ldmad/ldma.h (revision 269473047d747f7815af570197e4ef7322d3632c)
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 2009 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 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <libds.h>
35 #include <sys/sysmacros.h>
36 #include <sys/types.h>
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 
77 /*
78  * Size of the header of an agent message. This is the minimal size that
79  * a message can have.
80  */
81 #define	LDMA_MESSAGE_HEADER_SIZE	(sizeof (ldma_message_header_t))
82 
83 /*
84  * Macro to compute the size of a message with a msg_data of size dlen.
85  * The size of the msg_data field must be a multiple of 8-bytes so dlen
86  * is roundup to an 8-bytes multiple.
87  */
88 #define	LDMA_MESSAGE_SIZE(dlen)	(LDMA_MESSAGE_HEADER_SIZE + P2ROUNDUP(dlen, 8))
89 
90 /*
91  * Macro to compute the size of the msg_data field from the size of the message.
92  */
93 #define	LDMA_MESSAGE_DLEN(msgsize)	((msgsize) - LDMA_MESSAGE_HEADER_SIZE)
94 
95 /*
96  * Handy macros for using the message and header structures.
97  */
98 #define	LDMA_HDR2MSG(hdr)	((ldma_message_t *)(hdr))
99 #define	LDMA_HDR2DATA(hdr)	(LDMA_HDR2MSG(hdr)->msg_data)
100 #define	LDMA_MSG2HDR(msg)	((ldma_message_header_t *)(msg))
101 
102 /* agent message header structure */
103 typedef struct ldma_message_header {
104 	uint64_t	msg_num; 	/* message number */
105 	uint32_t	msg_type;	/* message type */
106 	uint32_t	msg_info;	/* message info */
107 } ldma_message_header_t;
108 
109 /* agent message structure */
110 typedef struct ldma_message {
111 	ldma_message_header_t	msg_hdr;	/* message header */
112 	char			msg_data[1];	/* message data */
113 } ldma_message_t;
114 
115 /*
116  * Additional structures and definition for the implementation.
117  */
118 typedef enum ldma_request_status_t {
119 	LDMA_REQ_COMPLETED,		/* request was completed */
120 	LDMA_REQ_FAILED,		/* request has failed */
121 	LDMA_REQ_INVALID,		/* request is invalid */
122 	LDMA_REQ_NOTSUP,		/* request is not supported */
123 	LDMA_REQ_DENIED			/* request was denied */
124 } ldma_request_status_t;
125 
126 typedef ldma_request_status_t (ldm_msg_func_t)(ds_ver_t *,
127     ldma_message_header_t *, size_t, ldma_message_header_t **, size_t *);
128 
129 typedef struct ldma_msg_handler {
130 	uint32_t		msg_type; 	/* message type */
131 	ldm_msg_func_t		*msg_handler;	/* message handler */
132 } ldma_msg_handler_t;
133 
134 typedef struct ldma_agent_info {
135 	char			*name;		/* agent name */
136 	ds_ver_t		*vers;		/* supported versions */
137 	int			nvers;		/* number of versions */
138 	ldma_msg_handler_t	*handlers;	/* message handlers */
139 	int			nhandlers;	/* number of handlers */
140 } ldma_agent_info_t;
141 
142 /*
143  * Helper functions for the daemon and agents.
144  */
145 
146 /* function to allocate a result message */
147 ldma_message_header_t *ldma_alloc_result_msg(ldma_message_header_t *, size_t);
148 
149 /* functions to log messages */
150 void ldma_err(char *module, char *fmt, ...);
151 void ldma_info(char *module, char *fmt, ...);
152 void ldma_dbg(char *module, char *fmt, ...);
153 
154 /*
155  * Macros to log messages. Each module/file using these macros should define
156  * LDMA_MODULE as the name under which messages are logged. For a given agent,
157  * LDMA_MODULE should be set to the name of the agent.
158  */
159 #define	LDMA_ERR(...)	ldma_err(LDMA_MODULE, __VA_ARGS__)
160 #define	LDMA_INFO(...)	ldma_info(LDMA_MODULE, __VA_ARGS__)
161 #define	LDMA_DBG(...)	ldma_dbg(LDMA_MODULE, __VA_ARGS__)
162 
163 #ifdef __cplusplus
164 }
165 #endif
166 
167 #endif /* _LDMA_H */
168