11991Sheppo /* 21991Sheppo * CDDL HEADER START 31991Sheppo * 41991Sheppo * The contents of this file are subject to the terms of the 51991Sheppo * Common Development and Distribution License (the "License"). 61991Sheppo * You may not use this file except in compliance with the License. 71991Sheppo * 81991Sheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91991Sheppo * or http://www.opensolaris.org/os/licensing. 101991Sheppo * See the License for the specific language governing permissions 111991Sheppo * and limitations under the License. 121991Sheppo * 131991Sheppo * When distributing Covered Code, include this CDDL HEADER in each 141991Sheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151991Sheppo * If applicable, add the following below this CDDL HEADER, with the 161991Sheppo * fields enclosed by brackets "[]" replaced with your own identifying 171991Sheppo * information: Portions Copyright [yyyy] [name of copyright owner] 181991Sheppo * 191991Sheppo * CDDL HEADER END 201991Sheppo */ 211991Sheppo 221991Sheppo /* 23*12950SWentao.Yang@Sun.COM * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 241991Sheppo */ 251991Sheppo 261991Sheppo #ifndef _SYS_VIO_MAILBOX_H 271991Sheppo #define _SYS_VIO_MAILBOX_H 281991Sheppo 291991Sheppo #ifdef __cplusplus 301991Sheppo extern "C" { 311991Sheppo #endif 321991Sheppo 331991Sheppo #include <sys/ldc.h> 341991Sheppo 351991Sheppo /* Message types */ 361991Sheppo #define VIO_TYPE_CTRL 0x1 371991Sheppo #define VIO_TYPE_DATA 0x2 381991Sheppo #define VIO_TYPE_ERR 0x4 391991Sheppo 401991Sheppo /* Message sub-types */ 411991Sheppo #define VIO_SUBTYPE_INFO 0x1 421991Sheppo #define VIO_SUBTYPE_ACK 0x2 431991Sheppo #define VIO_SUBTYPE_NACK 0x4 441991Sheppo 451991Sheppo /* 461991Sheppo * VIO specific control envelopes: 0x0000 - 0x00FF 471991Sheppo * VNET specific control envelopes: 0x0100 - 0x01FF 481991Sheppo * VDSK specific control envelopes: 0x0200 - 0x02FF 491991Sheppo * UNUSED envelopes: 0x0300 - 0x0FFF 501991Sheppo */ 511991Sheppo 521991Sheppo /* 531991Sheppo * Generic Control Subtype Envelopes: 541991Sheppo * type == VIO_TYPE_CTRL 551991Sheppo * subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 561991Sheppo * 571991Sheppo * 0x0000 - 0x003F 581991Sheppo */ 591991Sheppo #define VIO_VER_INFO 0x0001 601991Sheppo #define VIO_ATTR_INFO 0x0002 611991Sheppo #define VIO_DRING_REG 0x0003 621991Sheppo #define VIO_DRING_UNREG 0x0004 631991Sheppo #define VIO_RDX 0x0005 646495Sspeer #define VIO_DDS_INFO 0x0006 651991Sheppo 661991Sheppo /* 671991Sheppo * Generic subtype Data envelopes 681991Sheppo * type == VIO_TYPE_DATA 691991Sheppo * subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 701991Sheppo * 711991Sheppo * 0x0040 - 0x007F 721991Sheppo */ 731991Sheppo #define VIO_PKT_DATA 0x0040 741991Sheppo #define VIO_DESC_DATA 0x0041 751991Sheppo #define VIO_DRING_DATA 0x0042 761991Sheppo 771991Sheppo 781991Sheppo /* 791991Sheppo * Generic subtype Error envelopes 801991Sheppo * type == VIO_TYPE_ERR 811991Sheppo * subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 821991Sheppo * 831991Sheppo * 0x0080 - 0x00FF 841991Sheppo * 851991Sheppo * Currently unused 861991Sheppo */ 871991Sheppo 881991Sheppo /* 891991Sheppo * Supported Device Types 901991Sheppo */ 911991Sheppo #define VDEV_NETWORK 0x1 921991Sheppo #define VDEV_NETWORK_SWITCH 0x2 931991Sheppo #define VDEV_DISK 0x3 941991Sheppo #define VDEV_DISK_SERVER 0x4 951991Sheppo 961991Sheppo /* 971991Sheppo * VIO data transfer mode 981991Sheppo */ 991991Sheppo #define VIO_PKT_MODE 0x1 1001991Sheppo #define VIO_DESC_MODE 0x2 1015935Ssb155480 #define VIO_DRING_MODE_V1_0 0x3 1025935Ssb155480 #define VIO_DRING_MODE_V1_2 0x4 1031991Sheppo 1041991Sheppo /* 1051991Sheppo * VIO Descriptor Ring registration options 1061991Sheppo * (intended use for Descriptor Ring) 1071991Sheppo */ 10812011SSriharsha.Basavapatna@Sun.COM #define VIO_TX_DRING 0x1 10912011SSriharsha.Basavapatna@Sun.COM #define VIO_RX_DRING 0x2 11012011SSriharsha.Basavapatna@Sun.COM #define VIO_RX_DRING_DATA 0x4 1111991Sheppo 1121991Sheppo /* 1131991Sheppo * Size of message payload 1141991Sheppo */ 1151991Sheppo #define VIO_MSGTAG_SZ (sizeof (vio_msg_tag_t)) /* bytes */ 1161991Sheppo #define VIO_PAYLOAD_SZ (LDC_PAYLOAD_SIZE_UNRELIABLE - VIO_MSGTAG_SZ) 1171991Sheppo #define VIO_PAYLOAD_ELEMS (VIO_PAYLOAD_SZ / LDC_ELEM_SIZE) /* num words */ 1181991Sheppo 1191991Sheppo /* 1202336Snarayan * Peer dring processing state. Either actively processing dring 1212336Snarayan * or stopped. 1222336Snarayan */ 1232336Snarayan #define VIO_DP_ACTIVE 1 1242336Snarayan #define VIO_DP_STOPPED 2 1252336Snarayan 1262336Snarayan /* 1271991Sheppo * VIO device message tag. 1281991Sheppo * 1291991Sheppo * These 64 bits are used as a common header for all VIO message types. 1301991Sheppo */ 1311991Sheppo typedef union vio_msg_tag { 1321991Sheppo struct { 1331991Sheppo uint8_t _msgtype; 1341991Sheppo uint8_t _subtype; 1351991Sheppo uint16_t _subtype_env; 1361991Sheppo uint32_t _sid; /* session id */ 1371991Sheppo } _hdr; 1381991Sheppo uint64_t tagword; 1391991Sheppo } vio_msg_tag_t; 1401991Sheppo 1411991Sheppo #define vio_msgtype _hdr._msgtype 1421991Sheppo #define vio_subtype _hdr._subtype 1431991Sheppo #define vio_subtype_env _hdr._subtype_env 1441991Sheppo #define vio_sid _hdr._sid 1451991Sheppo 1461991Sheppo /* 1471991Sheppo * VIO version negotation message. 1481991Sheppo * 1491991Sheppo * tag.msgtype == VIO_TYPE_CTRL 1501991Sheppo * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK} 1511991Sheppo * tag.subtype_env == VIO_VER_INFO 1521991Sheppo */ 1532032Slm66018 1542032Slm66018 /* Structure to store a version tuple */ 1552032Slm66018 typedef struct vio_ver { 1562032Slm66018 uint16_t major; /* major version number */ 1572032Slm66018 uint16_t minor; /* minor version number */ 1582032Slm66018 } vio_ver_t; 1592032Slm66018 1601991Sheppo typedef struct vio_ver_msg { 1611991Sheppo /* Common tag */ 1621991Sheppo vio_msg_tag_t tag; 1631991Sheppo 1641991Sheppo /* version specific payload */ 1655462Swentaoy uint16_t ver_major; /* major version number */ 1665462Swentaoy uint16_t ver_minor; /* minor version number */ 1671991Sheppo 1681991Sheppo uint8_t dev_class; /* type of device */ 1691991Sheppo 1701991Sheppo /* padding */ 1711991Sheppo uint8_t resv1; 1721991Sheppo uint16_t resv2; 1731991Sheppo uint64_t resv3[VIO_PAYLOAD_ELEMS - 1]; 1741991Sheppo } vio_ver_msg_t; 1751991Sheppo 1761991Sheppo /* 1771991Sheppo * VIO Descriptor Ring Register message. 1781991Sheppo * 1791991Sheppo * tag.msgtype == VIO_TYPE_CTRL 1801991Sheppo * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK} 1811991Sheppo * tag.subtype_env == VIO_DRING_REG 1821991Sheppo */ 1831991Sheppo typedef struct vio_dring_reg_msg { 1841991Sheppo /* Common tag */ 1851991Sheppo vio_msg_tag_t tag; 1861991Sheppo 1871991Sheppo /* Descriptor ring information */ 1881991Sheppo uint64_t dring_ident; /* =0 for SUBTYPE_INFO msg */ 1891991Sheppo uint32_t num_descriptors; /* # of desc in the ring */ 1901991Sheppo uint32_t descriptor_size; /* size of each entry */ 19112011SSriharsha.Basavapatna@Sun.COM uint16_t options; /* dring mode */ 1921991Sheppo uint16_t resv; /* padding */ 1931991Sheppo uint32_t ncookies; /* # cookies exporting ring */ 1941991Sheppo 1951991Sheppo /* 19612011SSriharsha.Basavapatna@Sun.COM * The rest of the structure is variable in size. The first member that 19712011SSriharsha.Basavapatna@Sun.COM * follows is the descriptor ring cookie(s), that is used in all dring 19812011SSriharsha.Basavapatna@Sun.COM * modes. Following that are the members that are needed only in 19912011SSriharsha.Basavapatna@Sun.COM * RxDringData mode. If the dring mode is not RxDringData and the # of 20012011SSriharsha.Basavapatna@Sun.COM * dring cookies is 1, the message can be sent by LDC without 20112011SSriharsha.Basavapatna@Sun.COM * fragmentation. As dring cookie array is variable in size depending 20212011SSriharsha.Basavapatna@Sun.COM * on ncookies, the subsequent members are defined in a separate 20312011SSriharsha.Basavapatna@Sun.COM * structure vio_dring_reg_msg_ext_t as shown below. 2041991Sheppo */ 20512011SSriharsha.Basavapatna@Sun.COM 2061991Sheppo ldc_mem_cookie_t cookie[1]; 2071991Sheppo } vio_dring_reg_msg_t; 2081991Sheppo 2091991Sheppo /* 21012011SSriharsha.Basavapatna@Sun.COM * VIO Descriptor Ring Register Extended message; used in RxDringData mode. 21112011SSriharsha.Basavapatna@Sun.COM */ 21212011SSriharsha.Basavapatna@Sun.COM typedef struct vio_dring_reg_extended_msg { 21312011SSriharsha.Basavapatna@Sun.COM uint32_t data_ncookies; /* # of data area cookies */ 21412011SSriharsha.Basavapatna@Sun.COM uint32_t data_area_size; /* size of data area */ 21512011SSriharsha.Basavapatna@Sun.COM 21612011SSriharsha.Basavapatna@Sun.COM /* 21712011SSriharsha.Basavapatna@Sun.COM * The data_cookie[] array is variable in size based on data_ncookies. 21812011SSriharsha.Basavapatna@Sun.COM */ 21912011SSriharsha.Basavapatna@Sun.COM ldc_mem_cookie_t data_cookie[1]; /* data cookies */ 22012011SSriharsha.Basavapatna@Sun.COM } vio_dring_reg_ext_msg_t; 22112011SSriharsha.Basavapatna@Sun.COM 22212011SSriharsha.Basavapatna@Sun.COM /* 2231991Sheppo * VIO Descriptor Ring Unregister message. 2241991Sheppo * 2251991Sheppo * tag.msgtype == VIO_TYPE_CTRL 2261991Sheppo * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK} 2271991Sheppo * tag.subtype_env == VIO_DRING_UNREG 2281991Sheppo */ 2291991Sheppo typedef struct vio_dring_unreg_msg { 2301991Sheppo /* Common tag */ 2311991Sheppo vio_msg_tag_t tag; 2321991Sheppo 2331991Sheppo /* Descriptor ring information */ 2341991Sheppo uint64_t dring_ident; 2351991Sheppo uint64_t resv[VIO_PAYLOAD_ELEMS - 1]; 2361991Sheppo } vio_dring_unreg_msg_t; 2371991Sheppo 2381991Sheppo /* 2391991Sheppo * Definition of a generic VIO message (with no payload) which can be cast 2401991Sheppo * to other message types. 2411991Sheppo */ 2421991Sheppo typedef struct vio_msg { 2431991Sheppo /* Common tag */ 2441991Sheppo vio_msg_tag_t tag; 2451991Sheppo 2461991Sheppo /* no payload */ 2471991Sheppo uint64_t resv[VIO_PAYLOAD_ELEMS]; 2481991Sheppo } vio_msg_t; 2491991Sheppo 2501991Sheppo /* 2511991Sheppo * VIO Ready to Receive message. 2521991Sheppo * 2531991Sheppo * tag.msgtype == VIO_TYPE_CTRL 2541991Sheppo * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK} 2551991Sheppo * tag.subtype_env == VIO_RDX 2561991Sheppo */ 2571991Sheppo typedef vio_msg_t vio_rdx_msg_t; 2581991Sheppo 2591991Sheppo /* 2601991Sheppo * VIO error message. 2611991Sheppo * 2621991Sheppo * tag.msgtype == VIO_TYPE_ERR 2631991Sheppo * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 2641991Sheppo * tag.subtype_env == TBD 2651991Sheppo */ 2661991Sheppo typedef vio_msg_t vio_err_msg_t; 2671991Sheppo 2681991Sheppo /* 2691991Sheppo * VIO descriptor ring data message. 2701991Sheppo * 2711991Sheppo * tag.msgtype == VIO_TYPE_DATA 2721991Sheppo * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 2731991Sheppo * tag.subtype_env == VIO_DRING_DATA 2741991Sheppo */ 2751991Sheppo typedef struct vio_dring_msg { 2761991Sheppo /* Common message tag */ 2771991Sheppo vio_msg_tag_t tag; 2781991Sheppo 2791991Sheppo /* Data dring info */ 2801991Sheppo uint64_t seq_num; 2811991Sheppo uint64_t dring_ident; /* ident of modified DRing */ 2821991Sheppo uint32_t start_idx; /* Indx of first updated elem */ 2831991Sheppo int32_t end_idx; /* Indx of last updated elem */ 2841991Sheppo 2852336Snarayan uint8_t dring_process_state; /* Processing state */ 2862336Snarayan 2871991Sheppo /* 2881991Sheppo * Padding. 2891991Sheppo */ 2902336Snarayan uint8_t resv1; 2912336Snarayan uint16_t resv2; 2922336Snarayan uint32_t resv3; 2932336Snarayan uint64_t resv4[VIO_PAYLOAD_ELEMS - 4]; 2941991Sheppo } vio_dring_msg_t; 2951991Sheppo 2961991Sheppo /* 2971991Sheppo * VIO Common header for inband descriptor messages. 2981991Sheppo * 2991991Sheppo * Clients will then combine this header with a device specific payload. 3001991Sheppo */ 3011991Sheppo typedef struct vio_inband_desc_msg_hdr { 3021991Sheppo /* Common message tag */ 3031991Sheppo vio_msg_tag_t tag; 3041991Sheppo 3051991Sheppo uint64_t seq_num; /* sequence number */ 3061991Sheppo uint64_t desc_handle; /* opaque descriptor handle */ 3071991Sheppo } vio_inband_desc_msg_hdr_t; 3081991Sheppo 3091991Sheppo /* 3101991Sheppo * VIO raw data message. 3111991Sheppo * 3121991Sheppo * tag.msgtype == VIO_TYPE_DATA 3131991Sheppo * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK} 3141991Sheppo * tag.subtype_env == VIO_PKT_DATA 3151991Sheppo * 3161991Sheppo * Note the data payload is so small to keep this message 3171991Sheppo * within the size LDC can cope with without fragmentation. 3181991Sheppo * If it turns out in the future that we are not concerned 3191991Sheppo * with fragmentation then we can increase the size of this 3201991Sheppo * field. 3211991Sheppo */ 3221991Sheppo typedef struct vio_raw_data_msg { 3231991Sheppo /* Common message tag */ 3241991Sheppo vio_msg_tag_t tag; 3251991Sheppo 3261991Sheppo /* Raw data packet payload */ 3271991Sheppo uint64_t seq_num; /* sequence number */ 3281991Sheppo uint64_t data[VIO_PAYLOAD_ELEMS - 1]; 3291991Sheppo } vio_raw_data_msg_t; 3301991Sheppo 3315935Ssb155480 #define VIO_PKT_DATA_HDRSIZE \ 3325935Ssb155480 (sizeof (vio_msg_tag_t) + sizeof (uint64_t)) 3335935Ssb155480 3341991Sheppo /* 3351991Sheppo * Definitions of the valid states a Descriptor can be in. 3361991Sheppo */ 3371991Sheppo #define VIO_DESC_FREE 0x1 3381991Sheppo #define VIO_DESC_READY 0x2 3391991Sheppo #define VIO_DESC_ACCEPTED 0x3 3401991Sheppo #define VIO_DESC_DONE 0x4 341*12950SWentao.Yang@Sun.COM #define VIO_DESC_INITIALIZING 0x5 3421991Sheppo #define VIO_DESC_MASK 0xf 3431991Sheppo 3441991Sheppo /* Macro to populate the generic fields of the DRing data msg */ 3451991Sheppo #define VIO_INIT_DRING_DATA_TAG(dmsg) \ 3461991Sheppo dmsg.tag.vio_msgtype = VIO_TYPE_DATA; \ 3471991Sheppo dmsg.tag.vio_subtype = VIO_SUBTYPE_INFO; \ 3481991Sheppo dmsg.tag.vio_subtype_env = VIO_DRING_DATA; 3491991Sheppo 3501991Sheppo 3511991Sheppo #ifdef __cplusplus 3521991Sheppo } 3531991Sheppo #endif 3541991Sheppo 3551991Sheppo #endif /* _SYS_VIO_MAILBOX_H */ 356