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 2006 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 /* addr_type */ 99 #define ADDR_TYPE_MAC 0x1 /* XXX move to vnet_mailbox.h ? */ 100 101 /* 102 * VIO data transfer mode 103 */ 104 #define VIO_PKT_MODE 0x1 105 #define VIO_DESC_MODE 0x2 106 #define VIO_DRING_MODE 0x3 107 108 /* 109 * VIO Descriptor Ring registration options 110 * (intended use for Descriptor Ring) 111 */ 112 #define VIO_TX_DRING 0x1 113 #define VIO_RX_DRING 0x2 114 115 /* 116 * Size of message payload 117 */ 118 #define VIO_MSGTAG_SZ (sizeof (vio_msg_tag_t)) /* bytes */ 119 #define VIO_PAYLOAD_SZ (LDC_PAYLOAD_SIZE_UNRELIABLE - VIO_MSGTAG_SZ) 120 #define VIO_PAYLOAD_ELEMS (VIO_PAYLOAD_SZ / LDC_ELEM_SIZE) /* num words */ 121 122 /* 123 * VIO device message tag. 124 * 125 * These 64 bits are used as a common header for all VIO message types. 126 */ 127 typedef union vio_msg_tag { 128 struct { 129 uint8_t _msgtype; 130 uint8_t _subtype; 131 uint16_t _subtype_env; 132 uint32_t _sid; /* session id */ 133 } _hdr; 134 uint64_t tagword; 135 } vio_msg_tag_t; 136 137 #define vio_msgtype _hdr._msgtype 138 #define vio_subtype _hdr._subtype 139 #define vio_subtype_env _hdr._subtype_env 140 #define vio_sid _hdr._sid 141 142 /* 143 * VIO version negotation message. 144 * 145 * tag.msgtype == VIO_TYPE_CTRL 146 * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK} 147 * tag.subtype_env == VIO_VER_INFO 148 */ 149 typedef struct vio_ver_msg { 150 /* Common tag */ 151 vio_msg_tag_t tag; 152 153 /* version specific payload */ 154 uint32_t ver_major:16, /* major version number */ 155 ver_minor:16; /* minor version number */ 156 157 uint8_t dev_class; /* type of device */ 158 159 /* padding */ 160 uint8_t resv1; 161 uint16_t resv2; 162 uint64_t resv3[VIO_PAYLOAD_ELEMS - 1]; 163 } vio_ver_msg_t; 164 165 /* 166 * VIO Descriptor Ring Register message. 167 * 168 * tag.msgtype == VIO_TYPE_CTRL 169 * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK} 170 * tag.subtype_env == VIO_DRING_REG 171 */ 172 typedef struct vio_dring_reg_msg { 173 /* Common tag */ 174 vio_msg_tag_t tag; 175 176 /* Descriptor ring information */ 177 uint64_t dring_ident; /* =0 for SUBTYPE_INFO msg */ 178 uint32_t num_descriptors; /* # of desc in the ring */ 179 uint32_t descriptor_size; /* size of each entry */ 180 uint16_t options; /* intended use */ 181 uint16_t resv; /* padding */ 182 uint32_t ncookies; /* # cookies exporting ring */ 183 184 /* 185 * cookie is a variable sized array. If the number of cookies is 1, 186 * the message can be sent by LDC without fragmentation. 187 */ 188 ldc_mem_cookie_t cookie[1]; 189 } vio_dring_reg_msg_t; 190 191 /* 192 * VIO Descriptor Ring Unregister message. 193 * 194 * tag.msgtype == VIO_TYPE_CTRL 195 * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK} 196 * tag.subtype_env == VIO_DRING_UNREG 197 */ 198 typedef struct vio_dring_unreg_msg { 199 /* Common tag */ 200 vio_msg_tag_t tag; 201 202 /* Descriptor ring information */ 203 uint64_t dring_ident; 204 uint64_t resv[VIO_PAYLOAD_ELEMS - 1]; 205 } vio_dring_unreg_msg_t; 206 207 208 /* 209 * Definition of a generic VIO message (with no payload) which can be cast 210 * to other message types. 211 */ 212 typedef struct vio_msg { 213 /* Common tag */ 214 vio_msg_tag_t tag; 215 216 /* no payload */ 217 uint64_t resv[VIO_PAYLOAD_ELEMS]; 218 } vio_msg_t; 219 220 /* 221 * VIO Ready to Receive message. 222 * 223 * tag.msgtype == VIO_TYPE_CTRL 224 * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK} 225 * tag.subtype_env == VIO_RDX 226 */ 227 typedef vio_msg_t vio_rdx_msg_t; 228 229 /* 230 * VIO error message. 231 * 232 * tag.msgtype == VIO_TYPE_ERR 233 * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 234 * tag.subtype_env == TBD 235 */ 236 typedef vio_msg_t vio_err_msg_t; 237 238 /* 239 * VIO descriptor ring data message. 240 * 241 * tag.msgtype == VIO_TYPE_DATA 242 * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 243 * tag.subtype_env == VIO_DRING_DATA 244 */ 245 typedef struct vio_dring_msg { 246 /* Common message tag */ 247 vio_msg_tag_t tag; 248 249 /* Data dring info */ 250 uint64_t seq_num; 251 uint64_t dring_ident; /* ident of modified DRing */ 252 uint32_t start_idx; /* Indx of first updated elem */ 253 int32_t end_idx; /* Indx of last updated elem */ 254 255 /* 256 * Padding. 257 */ 258 uint64_t resv[VIO_PAYLOAD_ELEMS - 3]; 259 } vio_dring_msg_t; 260 261 /* 262 * VIO Common header for inband descriptor messages. 263 * 264 * Clients will then combine this header with a device specific payload. 265 */ 266 typedef struct vio_inband_desc_msg_hdr { 267 /* Common message tag */ 268 vio_msg_tag_t tag; 269 270 uint64_t seq_num; /* sequence number */ 271 uint64_t desc_handle; /* opaque descriptor handle */ 272 } vio_inband_desc_msg_hdr_t; 273 274 /* 275 * VIO raw data message. 276 * 277 * tag.msgtype == VIO_TYPE_DATA 278 * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 279 * tag.subtype_env == VIO_PKT_DATA 280 * 281 * Note the data payload is so small to keep this message 282 * within the size LDC can cope with without fragmentation. 283 * If it turns out in the future that we are not concerned 284 * with fragmentation then we can increase the size of this 285 * field. 286 */ 287 typedef struct vio_raw_data_msg { 288 /* Common message tag */ 289 vio_msg_tag_t tag; 290 291 /* Raw data packet payload */ 292 uint64_t seq_num; /* sequence number */ 293 uint64_t data[VIO_PAYLOAD_ELEMS - 1]; 294 } vio_raw_data_msg_t; 295 296 /* 297 * Definitions of the valid states a Descriptor can be in. 298 */ 299 #define VIO_DESC_FREE 0x1 300 #define VIO_DESC_READY 0x2 301 #define VIO_DESC_ACCEPTED 0x3 302 #define VIO_DESC_DONE 0x4 303 #define VIO_DESC_MASK 0xf 304 305 /* Macro to check that the state in variable supplied is a valid DRing state */ 306 #define VIO_IS_VALID_DESC_STATE(flag) \ 307 (((flag | VIO_DESC_MASK) == VIO_DESC_FREE) || \ 308 ((flag | VIO_DESC_MASK) == VIO_DESC_READY) || \ 309 ((flag | VIO_DESC_MASK) == VIO_DESC_ACCEPTED) || \ 310 ((flag | VIO_DESC_MASK) == VIO_DESC_READY)) 311 312 #define VIO_SET_DESC_STATE(flag, state) \ 313 { \ 314 flag &= (flag | ~VIO_DESC_MASK); \ 315 flag |= (state & VIO_DESC_MASK); \ 316 } 317 318 #define VIO_GET_DESC_STATE(flag) ((flag) & VIO_DESC_MASK) 319 320 /* Macro to populate the generic fields of the DRing data msg */ 321 #define VIO_INIT_DRING_DATA_TAG(dmsg) \ 322 dmsg.tag.vio_msgtype = VIO_TYPE_DATA; \ 323 dmsg.tag.vio_subtype = VIO_SUBTYPE_INFO; \ 324 dmsg.tag.vio_subtype_env = VIO_DRING_DATA; 325 326 327 #ifdef __cplusplus 328 } 329 #endif 330 331 #endif /* _SYS_VIO_MAILBOX_H */ 332