xref: /titanic_51/usr/src/uts/sun4v/sys/vio_mailbox.h (revision 0e26330710421d79f1fbb73c4f5f75086785b207)
11ae08745Sheppo /*
21ae08745Sheppo  * CDDL HEADER START
31ae08745Sheppo  *
41ae08745Sheppo  * The contents of this file are subject to the terms of the
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * You may not use this file except in compliance with the License.
71ae08745Sheppo  *
81ae08745Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91ae08745Sheppo  * or http://www.opensolaris.org/os/licensing.
101ae08745Sheppo  * See the License for the specific language governing permissions
111ae08745Sheppo  * and limitations under the License.
121ae08745Sheppo  *
131ae08745Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
141ae08745Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151ae08745Sheppo  * If applicable, add the following below this CDDL HEADER, with the
161ae08745Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
171ae08745Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
181ae08745Sheppo  *
191ae08745Sheppo  * CDDL HEADER END
201ae08745Sheppo  */
211ae08745Sheppo 
221ae08745Sheppo /*
23*0e263307SWENTAO YANG  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
241ae08745Sheppo  */
251ae08745Sheppo 
261ae08745Sheppo #ifndef _SYS_VIO_MAILBOX_H
271ae08745Sheppo #define	_SYS_VIO_MAILBOX_H
281ae08745Sheppo 
291ae08745Sheppo #ifdef __cplusplus
301ae08745Sheppo extern "C" {
311ae08745Sheppo #endif
321ae08745Sheppo 
331ae08745Sheppo #include <sys/ldc.h>
341ae08745Sheppo 
351ae08745Sheppo /* Message types */
361ae08745Sheppo #define		VIO_TYPE_CTRL	0x1
371ae08745Sheppo #define		VIO_TYPE_DATA	0x2
381ae08745Sheppo #define		VIO_TYPE_ERR	0x4
391ae08745Sheppo 
401ae08745Sheppo /* Message sub-types */
411ae08745Sheppo #define		VIO_SUBTYPE_INFO	0x1
421ae08745Sheppo #define		VIO_SUBTYPE_ACK		0x2
431ae08745Sheppo #define		VIO_SUBTYPE_NACK	0x4
441ae08745Sheppo 
451ae08745Sheppo /*
461ae08745Sheppo  * VIO specific control envelopes:  0x0000 - 0x00FF
471ae08745Sheppo  * VNET specific control envelopes: 0x0100 - 0x01FF
481ae08745Sheppo  * VDSK specific control envelopes: 0x0200 - 0x02FF
491ae08745Sheppo  * UNUSED envelopes:                0x0300 - 0x0FFF
501ae08745Sheppo  */
511ae08745Sheppo 
521ae08745Sheppo /*
531ae08745Sheppo  * Generic Control Subtype Envelopes:
541ae08745Sheppo  * 	type == VIO_TYPE_CTRL
551ae08745Sheppo  *	subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
561ae08745Sheppo  *
571ae08745Sheppo  * 	0x0000 - 0x003F
581ae08745Sheppo  */
591ae08745Sheppo #define	VIO_VER_INFO		0x0001
601ae08745Sheppo #define	VIO_ATTR_INFO		0x0002
611ae08745Sheppo #define	VIO_DRING_REG		0x0003
621ae08745Sheppo #define	VIO_DRING_UNREG		0x0004
631ae08745Sheppo #define	VIO_RDX			0x0005
64678453a8Sspeer #define	VIO_DDS_INFO		0x0006
651ae08745Sheppo 
661ae08745Sheppo /*
671ae08745Sheppo  * Generic subtype Data envelopes
681ae08745Sheppo  * 	type == VIO_TYPE_DATA
691ae08745Sheppo  * 	subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
701ae08745Sheppo  *
711ae08745Sheppo  * 	0x0040 - 0x007F
721ae08745Sheppo  */
731ae08745Sheppo #define	VIO_PKT_DATA		0x0040
741ae08745Sheppo #define	VIO_DESC_DATA		0x0041
751ae08745Sheppo #define	VIO_DRING_DATA		0x0042
761ae08745Sheppo 
771ae08745Sheppo 
781ae08745Sheppo /*
791ae08745Sheppo  * Generic subtype Error envelopes
801ae08745Sheppo  * 	type == VIO_TYPE_ERR
811ae08745Sheppo  * 	subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
821ae08745Sheppo  *
831ae08745Sheppo  * 	0x0080 - 0x00FF
841ae08745Sheppo  *
851ae08745Sheppo  * Currently unused
861ae08745Sheppo  */
871ae08745Sheppo 
881ae08745Sheppo /*
891ae08745Sheppo  * Supported Device Types
901ae08745Sheppo  */
911ae08745Sheppo #define	VDEV_NETWORK		0x1
921ae08745Sheppo #define	VDEV_NETWORK_SWITCH	0x2
931ae08745Sheppo #define	VDEV_DISK		0x3
941ae08745Sheppo #define	VDEV_DISK_SERVER	0x4
951ae08745Sheppo 
961ae08745Sheppo /*
971ae08745Sheppo  * VIO data transfer mode
981ae08745Sheppo  */
991ae08745Sheppo #define	VIO_PKT_MODE	0x1
1001ae08745Sheppo #define	VIO_DESC_MODE	0x2
101f0ca1d9aSsb155480 #define	VIO_DRING_MODE_V1_0	0x3
102f0ca1d9aSsb155480 #define	VIO_DRING_MODE_V1_2	0x4
1031ae08745Sheppo 
1041ae08745Sheppo /*
1051ae08745Sheppo  * VIO Descriptor Ring registration options
1061ae08745Sheppo  * (intended use for Descriptor Ring)
1071ae08745Sheppo  */
1081ae08745Sheppo #define	VIO_TX_DRING		0x1
1091ae08745Sheppo #define	VIO_RX_DRING		0x2
1107bd3a2e2SSriharsha Basavapatna #define	VIO_RX_DRING_DATA	0x4
1111ae08745Sheppo 
1121ae08745Sheppo /*
1131ae08745Sheppo  * Size of message payload
1141ae08745Sheppo  */
1151ae08745Sheppo #define	VIO_MSGTAG_SZ		(sizeof (vio_msg_tag_t))	/* bytes */
1161ae08745Sheppo #define	VIO_PAYLOAD_SZ		(LDC_PAYLOAD_SIZE_UNRELIABLE - VIO_MSGTAG_SZ)
1171ae08745Sheppo #define	VIO_PAYLOAD_ELEMS	(VIO_PAYLOAD_SZ / LDC_ELEM_SIZE) /* num words */
1181ae08745Sheppo 
1191ae08745Sheppo /*
120d10e4ef2Snarayan  * Peer dring processing state. Either actively processing dring
121d10e4ef2Snarayan  * or stopped.
122d10e4ef2Snarayan  */
123d10e4ef2Snarayan #define	VIO_DP_ACTIVE		1
124d10e4ef2Snarayan #define	VIO_DP_STOPPED		2
125d10e4ef2Snarayan 
126d10e4ef2Snarayan /*
1271ae08745Sheppo  * VIO device message tag.
1281ae08745Sheppo  *
1291ae08745Sheppo  * These 64 bits are used as a common header for all VIO message types.
1301ae08745Sheppo  */
1311ae08745Sheppo typedef union vio_msg_tag {
1321ae08745Sheppo 	struct {
1331ae08745Sheppo 		uint8_t		_msgtype;
1341ae08745Sheppo 		uint8_t		_subtype;
1351ae08745Sheppo 		uint16_t	_subtype_env;
1361ae08745Sheppo 		uint32_t	_sid;		/* session id */
1371ae08745Sheppo 	} _hdr;
1381ae08745Sheppo 	uint64_t	tagword;
1391ae08745Sheppo } vio_msg_tag_t;
1401ae08745Sheppo 
1411ae08745Sheppo #define	vio_msgtype		_hdr._msgtype
1421ae08745Sheppo #define	vio_subtype		_hdr._subtype
1431ae08745Sheppo #define	vio_subtype_env		_hdr._subtype_env
1441ae08745Sheppo #define	vio_sid			_hdr._sid
1451ae08745Sheppo 
1461ae08745Sheppo /*
1471ae08745Sheppo  * VIO version negotation message.
1481ae08745Sheppo  *
1491ae08745Sheppo  * tag.msgtype == VIO_TYPE_CTRL
1501ae08745Sheppo  * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK}
1511ae08745Sheppo  * tag.subtype_env == VIO_VER_INFO
1521ae08745Sheppo  */
1530a55fbb7Slm66018 
1540a55fbb7Slm66018 /* Structure to store a version tuple */
1550a55fbb7Slm66018 typedef struct vio_ver {
1560a55fbb7Slm66018 	uint16_t		major;		/* major version number */
1570a55fbb7Slm66018 	uint16_t		minor;		/* minor version number */
1580a55fbb7Slm66018 } vio_ver_t;
1590a55fbb7Slm66018 
1601ae08745Sheppo typedef struct vio_ver_msg {
1611ae08745Sheppo 	/* Common tag */
1621ae08745Sheppo 	vio_msg_tag_t		tag;
1631ae08745Sheppo 
1641ae08745Sheppo 	/* version specific payload */
165f2b610cfSwentaoy 	uint16_t		ver_major;	/* major version number */
166f2b610cfSwentaoy 	uint16_t		ver_minor;	/* minor version number */
1671ae08745Sheppo 
1681ae08745Sheppo 	uint8_t			dev_class;	/* type of device */
1691ae08745Sheppo 
1701ae08745Sheppo 	/* padding */
1711ae08745Sheppo 	uint8_t			resv1;
1721ae08745Sheppo 	uint16_t		resv2;
1731ae08745Sheppo 	uint64_t		resv3[VIO_PAYLOAD_ELEMS - 1];
1741ae08745Sheppo } vio_ver_msg_t;
1751ae08745Sheppo 
1761ae08745Sheppo /*
1771ae08745Sheppo  * VIO Descriptor Ring Register message.
1781ae08745Sheppo  *
1791ae08745Sheppo  * tag.msgtype == VIO_TYPE_CTRL
1801ae08745Sheppo  * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK}
1811ae08745Sheppo  * tag.subtype_env == VIO_DRING_REG
1821ae08745Sheppo  */
1831ae08745Sheppo typedef struct vio_dring_reg_msg {
1841ae08745Sheppo 	/* Common tag */
1851ae08745Sheppo 	vio_msg_tag_t		tag;
1861ae08745Sheppo 
1871ae08745Sheppo 	/* Descriptor ring information */
1881ae08745Sheppo 	uint64_t		dring_ident;	/* =0 for SUBTYPE_INFO msg */
1891ae08745Sheppo 	uint32_t		num_descriptors; /* # of desc in the ring */
1901ae08745Sheppo 	uint32_t		descriptor_size; /* size of each entry */
1917bd3a2e2SSriharsha Basavapatna 	uint16_t		options;	/* dring mode */
1921ae08745Sheppo 	uint16_t		resv;		/* padding */
1931ae08745Sheppo 	uint32_t		ncookies;	/* # cookies exporting ring */
1941ae08745Sheppo 
1951ae08745Sheppo 	/*
1967bd3a2e2SSriharsha Basavapatna 	 * The rest of the structure is variable in size. The first member that
1977bd3a2e2SSriharsha Basavapatna 	 * follows is the descriptor ring cookie(s), that is used in all dring
1987bd3a2e2SSriharsha Basavapatna 	 * modes. Following that are the members that are needed only in
1997bd3a2e2SSriharsha Basavapatna 	 * RxDringData mode. If the dring mode is not RxDringData and the # of
2007bd3a2e2SSriharsha Basavapatna 	 * dring cookies is 1, the message can be sent by LDC without
2017bd3a2e2SSriharsha Basavapatna 	 * fragmentation. As dring cookie array is variable in size depending
2027bd3a2e2SSriharsha Basavapatna 	 * on ncookies, the subsequent members are defined in a separate
2037bd3a2e2SSriharsha Basavapatna 	 * structure vio_dring_reg_msg_ext_t as shown below.
2041ae08745Sheppo 	 */
2057bd3a2e2SSriharsha Basavapatna 
2061ae08745Sheppo 	ldc_mem_cookie_t	cookie[1];
2071ae08745Sheppo } vio_dring_reg_msg_t;
2081ae08745Sheppo 
2091ae08745Sheppo /*
2107bd3a2e2SSriharsha Basavapatna  * VIO Descriptor Ring Register Extended message; used in RxDringData mode.
2117bd3a2e2SSriharsha Basavapatna  */
2127bd3a2e2SSriharsha Basavapatna typedef struct vio_dring_reg_extended_msg {
2137bd3a2e2SSriharsha Basavapatna 	uint32_t		data_ncookies;	/* # of data area cookies */
2147bd3a2e2SSriharsha Basavapatna 	uint32_t		data_area_size;	/* size of data area */
2157bd3a2e2SSriharsha Basavapatna 
2167bd3a2e2SSriharsha Basavapatna 	/*
2177bd3a2e2SSriharsha Basavapatna 	 * The data_cookie[] array is variable in size based on data_ncookies.
2187bd3a2e2SSriharsha Basavapatna 	 */
2197bd3a2e2SSriharsha Basavapatna 	ldc_mem_cookie_t	data_cookie[1]; /* data cookies */
2207bd3a2e2SSriharsha Basavapatna } vio_dring_reg_ext_msg_t;
2217bd3a2e2SSriharsha Basavapatna 
2227bd3a2e2SSriharsha Basavapatna /*
2231ae08745Sheppo  * VIO Descriptor Ring Unregister message.
2241ae08745Sheppo  *
2251ae08745Sheppo  * tag.msgtype == VIO_TYPE_CTRL
2261ae08745Sheppo  * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK}
2271ae08745Sheppo  * tag.subtype_env == VIO_DRING_UNREG
2281ae08745Sheppo  */
2291ae08745Sheppo typedef struct vio_dring_unreg_msg {
2301ae08745Sheppo 	/* Common tag */
2311ae08745Sheppo 	vio_msg_tag_t	tag;
2321ae08745Sheppo 
2331ae08745Sheppo 	/* Descriptor ring information */
2341ae08745Sheppo 	uint64_t	dring_ident;
2351ae08745Sheppo 	uint64_t	resv[VIO_PAYLOAD_ELEMS - 1];
2361ae08745Sheppo } vio_dring_unreg_msg_t;
2371ae08745Sheppo 
2381ae08745Sheppo /*
2391ae08745Sheppo  * Definition of a generic VIO message (with no payload) which can be cast
2401ae08745Sheppo  * to other message types.
2411ae08745Sheppo  */
2421ae08745Sheppo typedef struct vio_msg {
2431ae08745Sheppo 	/* Common tag */
2441ae08745Sheppo 	vio_msg_tag_t		tag;
2451ae08745Sheppo 
2461ae08745Sheppo 	/* no payload */
2471ae08745Sheppo 	uint64_t		resv[VIO_PAYLOAD_ELEMS];
2481ae08745Sheppo } vio_msg_t;
2491ae08745Sheppo 
2501ae08745Sheppo /*
2511ae08745Sheppo  * VIO Ready to Receive message.
2521ae08745Sheppo  *
2531ae08745Sheppo  * tag.msgtype == VIO_TYPE_CTRL
2541ae08745Sheppo  * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK}
2551ae08745Sheppo  * tag.subtype_env == VIO_RDX
2561ae08745Sheppo  */
2571ae08745Sheppo typedef vio_msg_t	vio_rdx_msg_t;
2581ae08745Sheppo 
2591ae08745Sheppo /*
2601ae08745Sheppo  * VIO error message.
2611ae08745Sheppo  *
2621ae08745Sheppo  * tag.msgtype == VIO_TYPE_ERR
2631ae08745Sheppo  * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
2641ae08745Sheppo  * tag.subtype_env == TBD
2651ae08745Sheppo  */
2661ae08745Sheppo typedef vio_msg_t	vio_err_msg_t;
2671ae08745Sheppo 
2681ae08745Sheppo /*
2691ae08745Sheppo  * VIO descriptor ring data message.
2701ae08745Sheppo  *
2711ae08745Sheppo  * tag.msgtype == VIO_TYPE_DATA
2721ae08745Sheppo  * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
2731ae08745Sheppo  * tag.subtype_env == VIO_DRING_DATA
2741ae08745Sheppo  */
2751ae08745Sheppo typedef struct vio_dring_msg {
2761ae08745Sheppo 	/* Common message tag */
2771ae08745Sheppo 	vio_msg_tag_t		tag;
2781ae08745Sheppo 
2791ae08745Sheppo 	/* Data dring info */
2801ae08745Sheppo 	uint64_t		seq_num;
2811ae08745Sheppo 	uint64_t		dring_ident;	/* ident of modified DRing */
2821ae08745Sheppo 	uint32_t		start_idx;	/* Indx of first updated elem */
2831ae08745Sheppo 	int32_t			end_idx;	/* Indx of last updated elem */
2841ae08745Sheppo 
285d10e4ef2Snarayan 	uint8_t			dring_process_state;	/* Processing state */
286d10e4ef2Snarayan 
2871ae08745Sheppo 	/*
2881ae08745Sheppo 	 * Padding.
2891ae08745Sheppo 	 */
290d10e4ef2Snarayan 	uint8_t			resv1;
291d10e4ef2Snarayan 	uint16_t		resv2;
292d10e4ef2Snarayan 	uint32_t		resv3;
293d10e4ef2Snarayan 	uint64_t		resv4[VIO_PAYLOAD_ELEMS - 4];
2941ae08745Sheppo } vio_dring_msg_t;
2951ae08745Sheppo 
2961ae08745Sheppo /*
2971ae08745Sheppo  * VIO Common header for inband descriptor messages.
2981ae08745Sheppo  *
2991ae08745Sheppo  * Clients will then combine this header with a device specific payload.
3001ae08745Sheppo  */
3011ae08745Sheppo typedef struct vio_inband_desc_msg_hdr {
3021ae08745Sheppo 	/* Common message tag */
3031ae08745Sheppo 	vio_msg_tag_t		tag;
3041ae08745Sheppo 
3051ae08745Sheppo 	uint64_t		seq_num;	/* sequence number */
3061ae08745Sheppo 	uint64_t		desc_handle;	/* opaque descriptor handle */
3071ae08745Sheppo } vio_inband_desc_msg_hdr_t;
3081ae08745Sheppo 
3091ae08745Sheppo /*
3101ae08745Sheppo  * VIO raw data message.
3111ae08745Sheppo  *
3121ae08745Sheppo  * tag.msgtype == VIO_TYPE_DATA
3131ae08745Sheppo  * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
3141ae08745Sheppo  * tag.subtype_env == VIO_PKT_DATA
3151ae08745Sheppo  *
3161ae08745Sheppo  * Note the data payload is so small to keep this message
3171ae08745Sheppo  * within the size LDC can cope with without fragmentation.
3181ae08745Sheppo  * If it turns out in the future that we are not concerned
3191ae08745Sheppo  * with fragmentation then we can increase the size of this
3201ae08745Sheppo  * field.
3211ae08745Sheppo  */
3221ae08745Sheppo typedef struct vio_raw_data_msg {
3231ae08745Sheppo 	/* Common message tag */
3241ae08745Sheppo 	vio_msg_tag_t		tag;
3251ae08745Sheppo 
3261ae08745Sheppo 	/* Raw data packet payload */
3271ae08745Sheppo 	uint64_t		seq_num;	/* sequence number */
3281ae08745Sheppo 	uint64_t		data[VIO_PAYLOAD_ELEMS - 1];
3291ae08745Sheppo } vio_raw_data_msg_t;
3301ae08745Sheppo 
331f0ca1d9aSsb155480 #define	VIO_PKT_DATA_HDRSIZE	\
332f0ca1d9aSsb155480 	(sizeof (vio_msg_tag_t) + sizeof (uint64_t))
333f0ca1d9aSsb155480 
3341ae08745Sheppo /*
3351ae08745Sheppo  * Definitions of the valid states a Descriptor can be in.
3361ae08745Sheppo  */
3371ae08745Sheppo #define	VIO_DESC_FREE		0x1
3381ae08745Sheppo #define	VIO_DESC_READY		0x2
3391ae08745Sheppo #define	VIO_DESC_ACCEPTED	0x3
3401ae08745Sheppo #define	VIO_DESC_DONE		0x4
341*0e263307SWENTAO YANG #define	VIO_DESC_INITIALIZING	0x5
3421ae08745Sheppo #define	VIO_DESC_MASK		0xf
3431ae08745Sheppo 
3441ae08745Sheppo /* Macro to populate the generic fields of the DRing data msg */
3451ae08745Sheppo #define	VIO_INIT_DRING_DATA_TAG(dmsg)	\
3461ae08745Sheppo 		dmsg.tag.vio_msgtype = VIO_TYPE_DATA;	\
3471ae08745Sheppo 		dmsg.tag.vio_subtype = VIO_SUBTYPE_INFO;	\
3481ae08745Sheppo 		dmsg.tag.vio_subtype_env = VIO_DRING_DATA;
3491ae08745Sheppo 
3501ae08745Sheppo 
3511ae08745Sheppo #ifdef __cplusplus
3521ae08745Sheppo }
3531ae08745Sheppo #endif
3541ae08745Sheppo 
3551ae08745Sheppo #endif	/* _SYS_VIO_MAILBOX_H */
356