8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / ldmad / ldma.h
blobf0253b6af75b6f8c91a8bc8da29ce1bc1617d5e8
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _LDMA_H
28 #define _LDMA_H
30 #include <libds.h>
31 #include <sys/sysmacros.h>
32 #include <sys/types.h>
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
39 * The following definitions are part of the LDoms Agent specification.
42 /* reply message types */
43 #define LDMA_MSG_RESULT 0x8000 /* result message */
44 #define LDMA_MSG_ERROR 0x8001 /* error message */
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 */
53 * LDoms Device Agent
55 #define LDMA_NAME_DEVICE "agent-device"
57 #define LDMA_MSGDEV_VALIDATE_PATH 0x01 /* validate path */
58 #define LDMA_MSGDEV_VALIDATE_NIC 0x02 /* validate network interface */
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 */
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 */
68 #define LDMA_DEVNIC_EXIST 0x01 /* nic is accessible */
71 * LDoms System Agent
73 #define LDMA_NAME_SYSTEM "agent-system"
75 #define LDMA_MSGSYS_GET_SYSINFO 0x01 /* get system info request */
76 #define LDMA_MSGSYS_GET_CHASSISNO 0x02 /* get chassis sno request */
79 * LDoms Direct IO Agent
81 #define LDMA_NAME_DIO "agent-dio"
83 #define MSGDIO_PCIDEV_INFO 0x1 /* pci device info request */
87 * Size of the header of an agent message. This is the minimal size that
88 * a message can have.
90 #define LDMA_MESSAGE_HEADER_SIZE (sizeof (ldma_message_header_t))
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.
97 #define LDMA_MESSAGE_SIZE(dlen) (LDMA_MESSAGE_HEADER_SIZE + P2ROUNDUP(dlen, 8))
100 * Macro to compute the size of the msg_data field from the size of the message.
102 #define LDMA_MESSAGE_DLEN(msgsize) ((msgsize) - LDMA_MESSAGE_HEADER_SIZE)
105 * Handy macros for using the message and header structures.
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))
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;
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;
125 * Additional structures and definition for the implementation.
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;
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 *);
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.
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.
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.
153 #define LDMA_MSGFLG_ACCESS_CONTROL 0x00
154 #define LDMA_MSGFLG_ACCESS_ANY 0x01
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;
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;
171 * Helper functions for the daemon and agents.
174 /* function to allocate a result message */
175 ldma_message_header_t *ldma_alloc_result_msg(ldma_message_header_t *, size_t);
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, ...);
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.
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__)
191 #ifdef __cplusplus
193 #endif
195 #endif /* _LDMA_H */