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