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