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 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_VIO_MAILBOX_H 28 #define _SYS_VIO_MAILBOX_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #include <sys/ldc.h> 37 38 /* Message types */ 39 #define VIO_TYPE_CTRL 0x1 40 #define VIO_TYPE_DATA 0x2 41 #define VIO_TYPE_ERR 0x4 42 43 /* Message sub-types */ 44 #define VIO_SUBTYPE_INFO 0x1 45 #define VIO_SUBTYPE_ACK 0x2 46 #define VIO_SUBTYPE_NACK 0x4 47 48 /* 49 * VIO specific control envelopes: 0x0000 - 0x00FF 50 * VNET specific control envelopes: 0x0100 - 0x01FF 51 * VDSK specific control envelopes: 0x0200 - 0x02FF 52 * UNUSED envelopes: 0x0300 - 0x0FFF 53 */ 54 55 /* 56 * Generic Control Subtype Envelopes: 57 * type == VIO_TYPE_CTRL 58 * subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 59 * 60 * 0x0000 - 0x003F 61 */ 62 #define VIO_VER_INFO 0x0001 63 #define VIO_ATTR_INFO 0x0002 64 #define VIO_DRING_REG 0x0003 65 #define VIO_DRING_UNREG 0x0004 66 #define VIO_RDX 0x0005 67 68 /* 69 * Generic subtype Data envelopes 70 * type == VIO_TYPE_DATA 71 * subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 72 * 73 * 0x0040 - 0x007F 74 */ 75 #define VIO_PKT_DATA 0x0040 76 #define VIO_DESC_DATA 0x0041 77 #define VIO_DRING_DATA 0x0042 78 79 80 /* 81 * Generic subtype Error envelopes 82 * type == VIO_TYPE_ERR 83 * subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 84 * 85 * 0x0080 - 0x00FF 86 * 87 * Currently unused 88 */ 89 90 /* 91 * Supported Device Types 92 */ 93 #define VDEV_NETWORK 0x1 94 #define VDEV_NETWORK_SWITCH 0x2 95 #define VDEV_DISK 0x3 96 #define VDEV_DISK_SERVER 0x4 97 98 /* 99 * VIO data transfer mode 100 */ 101 #define VIO_PKT_MODE 0x1 102 #define VIO_DESC_MODE 0x2 103 #define VIO_DRING_MODE 0x3 104 105 /* 106 * VIO Descriptor Ring registration options 107 * (intended use for Descriptor Ring) 108 */ 109 #define VIO_TX_DRING 0x1 110 #define VIO_RX_DRING 0x2 111 112 /* 113 * Size of message payload 114 */ 115 #define VIO_MSGTAG_SZ (sizeof (vio_msg_tag_t)) /* bytes */ 116 #define VIO_PAYLOAD_SZ (LDC_PAYLOAD_SIZE_UNRELIABLE - VIO_MSGTAG_SZ) 117 #define VIO_PAYLOAD_ELEMS (VIO_PAYLOAD_SZ / LDC_ELEM_SIZE) /* num words */ 118 119 /* 120 * Peer dring processing state. Either actively processing dring 121 * or stopped. 122 */ 123 #define VIO_DP_ACTIVE 1 124 #define VIO_DP_STOPPED 2 125 126 /* 127 * VIO device message tag. 128 * 129 * These 64 bits are used as a common header for all VIO message types. 130 */ 131 typedef union vio_msg_tag { 132 struct { 133 uint8_t _msgtype; 134 uint8_t _subtype; 135 uint16_t _subtype_env; 136 uint32_t _sid; /* session id */ 137 } _hdr; 138 uint64_t tagword; 139 } vio_msg_tag_t; 140 141 #define vio_msgtype _hdr._msgtype 142 #define vio_subtype _hdr._subtype 143 #define vio_subtype_env _hdr._subtype_env 144 #define vio_sid _hdr._sid 145 146 /* 147 * VIO version negotation message. 148 * 149 * tag.msgtype == VIO_TYPE_CTRL 150 * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK} 151 * tag.subtype_env == VIO_VER_INFO 152 */ 153 154 /* Structure to store a version tuple */ 155 typedef struct vio_ver { 156 uint16_t major; /* major version number */ 157 uint16_t minor; /* minor version number */ 158 } vio_ver_t; 159 160 typedef struct vio_ver_msg { 161 /* Common tag */ 162 vio_msg_tag_t tag; 163 164 /* version specific payload */ 165 uint16_t ver_major; /* major version number */ 166 uint16_t ver_minor; /* minor version number */ 167 168 uint8_t dev_class; /* type of device */ 169 170 /* padding */ 171 uint8_t resv1; 172 uint16_t resv2; 173 uint64_t resv3[VIO_PAYLOAD_ELEMS - 1]; 174 } vio_ver_msg_t; 175 176 /* 177 * VIO Descriptor Ring Register message. 178 * 179 * tag.msgtype == VIO_TYPE_CTRL 180 * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK} 181 * tag.subtype_env == VIO_DRING_REG 182 */ 183 typedef struct vio_dring_reg_msg { 184 /* Common tag */ 185 vio_msg_tag_t tag; 186 187 /* Descriptor ring information */ 188 uint64_t dring_ident; /* =0 for SUBTYPE_INFO msg */ 189 uint32_t num_descriptors; /* # of desc in the ring */ 190 uint32_t descriptor_size; /* size of each entry */ 191 uint16_t options; /* intended use */ 192 uint16_t resv; /* padding */ 193 uint32_t ncookies; /* # cookies exporting ring */ 194 195 /* 196 * cookie is a variable sized array. If the number of cookies is 1, 197 * the message can be sent by LDC without fragmentation. 198 */ 199 ldc_mem_cookie_t cookie[1]; 200 } vio_dring_reg_msg_t; 201 202 /* 203 * VIO Descriptor Ring Unregister message. 204 * 205 * tag.msgtype == VIO_TYPE_CTRL 206 * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK} 207 * tag.subtype_env == VIO_DRING_UNREG 208 */ 209 typedef struct vio_dring_unreg_msg { 210 /* Common tag */ 211 vio_msg_tag_t tag; 212 213 /* Descriptor ring information */ 214 uint64_t dring_ident; 215 uint64_t resv[VIO_PAYLOAD_ELEMS - 1]; 216 } vio_dring_unreg_msg_t; 217 218 219 /* 220 * Definition of a generic VIO message (with no payload) which can be cast 221 * to other message types. 222 */ 223 typedef struct vio_msg { 224 /* Common tag */ 225 vio_msg_tag_t tag; 226 227 /* no payload */ 228 uint64_t resv[VIO_PAYLOAD_ELEMS]; 229 } vio_msg_t; 230 231 /* 232 * VIO Ready to Receive message. 233 * 234 * tag.msgtype == VIO_TYPE_CTRL 235 * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK} 236 * tag.subtype_env == VIO_RDX 237 */ 238 typedef vio_msg_t vio_rdx_msg_t; 239 240 /* 241 * VIO error message. 242 * 243 * tag.msgtype == VIO_TYPE_ERR 244 * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 245 * tag.subtype_env == TBD 246 */ 247 typedef vio_msg_t vio_err_msg_t; 248 249 /* 250 * VIO descriptor ring data message. 251 * 252 * tag.msgtype == VIO_TYPE_DATA 253 * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 254 * tag.subtype_env == VIO_DRING_DATA 255 */ 256 typedef struct vio_dring_msg { 257 /* Common message tag */ 258 vio_msg_tag_t tag; 259 260 /* Data dring info */ 261 uint64_t seq_num; 262 uint64_t dring_ident; /* ident of modified DRing */ 263 uint32_t start_idx; /* Indx of first updated elem */ 264 int32_t end_idx; /* Indx of last updated elem */ 265 266 uint8_t dring_process_state; /* Processing state */ 267 268 /* 269 * Padding. 270 */ 271 uint8_t resv1; 272 uint16_t resv2; 273 uint32_t resv3; 274 uint64_t resv4[VIO_PAYLOAD_ELEMS - 4]; 275 } vio_dring_msg_t; 276 277 /* 278 * VIO Common header for inband descriptor messages. 279 * 280 * Clients will then combine this header with a device specific payload. 281 */ 282 typedef struct vio_inband_desc_msg_hdr { 283 /* Common message tag */ 284 vio_msg_tag_t tag; 285 286 uint64_t seq_num; /* sequence number */ 287 uint64_t desc_handle; /* opaque descriptor handle */ 288 } vio_inband_desc_msg_hdr_t; 289 290 /* 291 * VIO raw data message. 292 * 293 * tag.msgtype == VIO_TYPE_DATA 294 * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 295 * tag.subtype_env == VIO_PKT_DATA 296 * 297 * Note the data payload is so small to keep this message 298 * within the size LDC can cope with without fragmentation. 299 * If it turns out in the future that we are not concerned 300 * with fragmentation then we can increase the size of this 301 * field. 302 */ 303 typedef struct vio_raw_data_msg { 304 /* Common message tag */ 305 vio_msg_tag_t tag; 306 307 /* Raw data packet payload */ 308 uint64_t seq_num; /* sequence number */ 309 uint64_t data[VIO_PAYLOAD_ELEMS - 1]; 310 } vio_raw_data_msg_t; 311 312 /* 313 * Definitions of the valid states a Descriptor can be in. 314 */ 315 #define VIO_DESC_FREE 0x1 316 #define VIO_DESC_READY 0x2 317 #define VIO_DESC_ACCEPTED 0x3 318 #define VIO_DESC_DONE 0x4 319 #define VIO_DESC_MASK 0xf 320 321 /* Macro to populate the generic fields of the DRing data msg */ 322 #define VIO_INIT_DRING_DATA_TAG(dmsg) \ 323 dmsg.tag.vio_msgtype = VIO_TYPE_DATA; \ 324 dmsg.tag.vio_subtype = VIO_SUBTYPE_INFO; \ 325 dmsg.tag.vio_subtype_env = VIO_DRING_DATA; 326 327 328 #ifdef __cplusplus 329 } 330 #endif 331 332 #endif /* _SYS_VIO_MAILBOX_H */ 333