xref: /illumos-gate/usr/src/uts/sun4v/sys/vio_mailbox.h (revision 09295472)
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 
150 /* Structure to store a version tuple */
151 typedef struct vio_ver {
152 	uint16_t		major;		/* major version number */
153 	uint16_t		minor;		/* minor version number */
154 } vio_ver_t;
155 
156 typedef struct vio_ver_msg {
157 	/* Common tag */
158 	vio_msg_tag_t		tag;
159 
160 	/* version specific payload */
161 	uint32_t		ver_major:16,	/* major version number */
162 				ver_minor:16;	/* minor version number */
163 
164 	uint8_t			dev_class;	/* type of device */
165 
166 	/* padding */
167 	uint8_t			resv1;
168 	uint16_t		resv2;
169 	uint64_t		resv3[VIO_PAYLOAD_ELEMS - 1];
170 } vio_ver_msg_t;
171 
172 
173 /*
174  * VIO Descriptor Ring Register message.
175  *
176  * tag.msgtype == VIO_TYPE_CTRL
177  * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK}
178  * tag.subtype_env == VIO_DRING_REG
179  */
180 typedef struct vio_dring_reg_msg {
181 	/* Common tag */
182 	vio_msg_tag_t		tag;
183 
184 	/* Descriptor ring information */
185 	uint64_t		dring_ident;	/* =0 for SUBTYPE_INFO msg */
186 	uint32_t		num_descriptors; /* # of desc in the ring */
187 	uint32_t		descriptor_size; /* size of each entry */
188 	uint16_t		options;	/* intended use */
189 	uint16_t		resv;		/* padding */
190 	uint32_t		ncookies;	/* # cookies exporting ring */
191 
192 	/*
193 	 * cookie is a variable sized array.  If the number of cookies is 1,
194 	 * the message can be sent by LDC without fragmentation.
195 	 */
196 	ldc_mem_cookie_t	cookie[1];
197 } vio_dring_reg_msg_t;
198 
199 /*
200  * VIO Descriptor Ring Unregister message.
201  *
202  * tag.msgtype == VIO_TYPE_CTRL
203  * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK}
204  * tag.subtype_env == VIO_DRING_UNREG
205  */
206 typedef struct vio_dring_unreg_msg {
207 	/* Common tag */
208 	vio_msg_tag_t	tag;
209 
210 	/* Descriptor ring information */
211 	uint64_t	dring_ident;
212 	uint64_t	resv[VIO_PAYLOAD_ELEMS - 1];
213 } vio_dring_unreg_msg_t;
214 
215 
216 /*
217  * Definition of a generic VIO message (with no payload) which can be cast
218  * to other message types.
219  */
220 typedef struct vio_msg {
221 	/* Common tag */
222 	vio_msg_tag_t		tag;
223 
224 	/* no payload */
225 	uint64_t		resv[VIO_PAYLOAD_ELEMS];
226 } vio_msg_t;
227 
228 /*
229  * VIO Ready to Receive message.
230  *
231  * tag.msgtype == VIO_TYPE_CTRL
232  * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK}
233  * tag.subtype_env == VIO_RDX
234  */
235 typedef vio_msg_t	vio_rdx_msg_t;
236 
237 /*
238  * VIO error message.
239  *
240  * tag.msgtype == VIO_TYPE_ERR
241  * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
242  * tag.subtype_env == TBD
243  */
244 typedef vio_msg_t	vio_err_msg_t;
245 
246 /*
247  * VIO descriptor ring data message.
248  *
249  * tag.msgtype == VIO_TYPE_DATA
250  * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
251  * tag.subtype_env == VIO_DRING_DATA
252  */
253 typedef struct vio_dring_msg {
254 	/* Common message tag */
255 	vio_msg_tag_t		tag;
256 
257 	/* Data dring info */
258 	uint64_t		seq_num;
259 	uint64_t		dring_ident;	/* ident of modified DRing */
260 	uint32_t		start_idx;	/* Indx of first updated elem */
261 	int32_t			end_idx;	/* Indx of last updated elem */
262 
263 	/*
264 	 * Padding.
265 	 */
266 	uint64_t	resv[VIO_PAYLOAD_ELEMS - 3];
267 } vio_dring_msg_t;
268 
269 /*
270  * VIO Common header for inband descriptor messages.
271  *
272  * Clients will then combine this header with a device specific payload.
273  */
274 typedef struct vio_inband_desc_msg_hdr {
275 	/* Common message tag */
276 	vio_msg_tag_t		tag;
277 
278 	uint64_t		seq_num;	/* sequence number */
279 	uint64_t		desc_handle;	/* opaque descriptor handle */
280 } vio_inband_desc_msg_hdr_t;
281 
282 /*
283  * VIO raw data message.
284  *
285  * tag.msgtype == VIO_TYPE_DATA
286  * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
287  * tag.subtype_env == VIO_PKT_DATA
288  *
289  * Note the data payload is so small to keep this message
290  * within the size LDC can cope with without fragmentation.
291  * If it turns out in the future that we are not concerned
292  * with fragmentation then we can increase the size of this
293  * field.
294  */
295 typedef struct vio_raw_data_msg {
296 	/* Common message tag */
297 	vio_msg_tag_t		tag;
298 
299 	/* Raw data packet payload */
300 	uint64_t		seq_num;	/* sequence number */
301 	uint64_t		data[VIO_PAYLOAD_ELEMS - 1];
302 } vio_raw_data_msg_t;
303 
304 /*
305  * Definitions of the valid states a Descriptor can be in.
306  */
307 #define	VIO_DESC_FREE		0x1
308 #define	VIO_DESC_READY		0x2
309 #define	VIO_DESC_ACCEPTED	0x3
310 #define	VIO_DESC_DONE		0x4
311 #define	VIO_DESC_MASK		0xf
312 
313 /* Macro to check that the state in variable supplied is a valid DRing state */
314 #define	VIO_IS_VALID_DESC_STATE(flag)					\
315 	(((flag | VIO_DESC_MASK) == VIO_DESC_FREE) ||			\
316 		((flag | VIO_DESC_MASK) == VIO_DESC_READY) ||		\
317 		((flag | VIO_DESC_MASK) == VIO_DESC_ACCEPTED) ||	\
318 		((flag | VIO_DESC_MASK) == VIO_DESC_READY))
319 
320 #define	VIO_SET_DESC_STATE(flag, state)					\
321 	{								\
322 		flag &= (flag | ~VIO_DESC_MASK);			\
323 		flag |= (state & VIO_DESC_MASK);			\
324 	}
325 
326 #define	VIO_GET_DESC_STATE(flag)	((flag) & VIO_DESC_MASK)
327 
328 /* Macro to populate the generic fields of the DRing data msg */
329 #define	VIO_INIT_DRING_DATA_TAG(dmsg)	\
330 		dmsg.tag.vio_msgtype = VIO_TYPE_DATA;	\
331 		dmsg.tag.vio_subtype = VIO_SUBTYPE_INFO;	\
332 		dmsg.tag.vio_subtype_env = VIO_DRING_DATA;
333 
334 
335 #ifdef __cplusplus
336 }
337 #endif
338 
339 #endif	/* _SYS_VIO_MAILBOX_H */
340