xref: /titanic_51/usr/src/uts/sun4v/sys/vio_mailbox.h (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
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 2008 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 /*
99  * VIO data transfer mode
100  */
101 #define	VIO_PKT_MODE	0x1
102 #define	VIO_DESC_MODE	0x2
103 #define	VIO_DRING_MODE_V1_0	0x3
104 #define	VIO_DRING_MODE_V1_2	0x4
105 
106 /*
107  * VIO Descriptor Ring registration options
108  * (intended use for Descriptor Ring)
109  */
110 #define	VIO_TX_DRING	0x1
111 #define	VIO_RX_DRING	0x2
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;	/* intended use */
193 	uint16_t		resv;		/* padding */
194 	uint32_t		ncookies;	/* # cookies exporting ring */
195 
196 	/*
197 	 * cookie is a variable sized array.  If the number of cookies is 1,
198 	 * the message can be sent by LDC without fragmentation.
199 	 */
200 	ldc_mem_cookie_t	cookie[1];
201 } vio_dring_reg_msg_t;
202 
203 /*
204  * VIO Descriptor Ring Unregister message.
205  *
206  * tag.msgtype == VIO_TYPE_CTRL
207  * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK|NACK}
208  * tag.subtype_env == VIO_DRING_UNREG
209  */
210 typedef struct vio_dring_unreg_msg {
211 	/* Common tag */
212 	vio_msg_tag_t	tag;
213 
214 	/* Descriptor ring information */
215 	uint64_t	dring_ident;
216 	uint64_t	resv[VIO_PAYLOAD_ELEMS - 1];
217 } vio_dring_unreg_msg_t;
218 
219 
220 /*
221  * Definition of a generic VIO message (with no payload) which can be cast
222  * to other message types.
223  */
224 typedef struct vio_msg {
225 	/* Common tag */
226 	vio_msg_tag_t		tag;
227 
228 	/* no payload */
229 	uint64_t		resv[VIO_PAYLOAD_ELEMS];
230 } vio_msg_t;
231 
232 /*
233  * VIO Ready to Receive message.
234  *
235  * tag.msgtype == VIO_TYPE_CTRL
236  * tag.submsgtype = VIO_SUBTYPE_{INFO|ACK}
237  * tag.subtype_env == VIO_RDX
238  */
239 typedef vio_msg_t	vio_rdx_msg_t;
240 
241 /*
242  * VIO error message.
243  *
244  * tag.msgtype == VIO_TYPE_ERR
245  * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
246  * tag.subtype_env == TBD
247  */
248 typedef vio_msg_t	vio_err_msg_t;
249 
250 /*
251  * VIO descriptor ring data message.
252  *
253  * tag.msgtype == VIO_TYPE_DATA
254  * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
255  * tag.subtype_env == VIO_DRING_DATA
256  */
257 typedef struct vio_dring_msg {
258 	/* Common message tag */
259 	vio_msg_tag_t		tag;
260 
261 	/* Data dring info */
262 	uint64_t		seq_num;
263 	uint64_t		dring_ident;	/* ident of modified DRing */
264 	uint32_t		start_idx;	/* Indx of first updated elem */
265 	int32_t			end_idx;	/* Indx of last updated elem */
266 
267 	uint8_t			dring_process_state;	/* Processing state */
268 
269 	/*
270 	 * Padding.
271 	 */
272 	uint8_t			resv1;
273 	uint16_t		resv2;
274 	uint32_t		resv3;
275 	uint64_t		resv4[VIO_PAYLOAD_ELEMS - 4];
276 } vio_dring_msg_t;
277 
278 /*
279  * VIO Common header for inband descriptor messages.
280  *
281  * Clients will then combine this header with a device specific payload.
282  */
283 typedef struct vio_inband_desc_msg_hdr {
284 	/* Common message tag */
285 	vio_msg_tag_t		tag;
286 
287 	uint64_t		seq_num;	/* sequence number */
288 	uint64_t		desc_handle;	/* opaque descriptor handle */
289 } vio_inband_desc_msg_hdr_t;
290 
291 /*
292  * VIO raw data message.
293  *
294  * tag.msgtype == VIO_TYPE_DATA
295  * tag.subtype == VIO_SUBTYPE_{INFO|ACK|NACK}
296  * tag.subtype_env == VIO_PKT_DATA
297  *
298  * Note the data payload is so small to keep this message
299  * within the size LDC can cope with without fragmentation.
300  * If it turns out in the future that we are not concerned
301  * with fragmentation then we can increase the size of this
302  * field.
303  */
304 typedef struct vio_raw_data_msg {
305 	/* Common message tag */
306 	vio_msg_tag_t		tag;
307 
308 	/* Raw data packet payload */
309 	uint64_t		seq_num;	/* sequence number */
310 	uint64_t		data[VIO_PAYLOAD_ELEMS - 1];
311 } vio_raw_data_msg_t;
312 
313 #define	VIO_PKT_DATA_HDRSIZE	\
314 	(sizeof (vio_msg_tag_t) + sizeof (uint64_t))
315 
316 /*
317  * Definitions of the valid states a Descriptor can be in.
318  */
319 #define	VIO_DESC_FREE		0x1
320 #define	VIO_DESC_READY		0x2
321 #define	VIO_DESC_ACCEPTED	0x3
322 #define	VIO_DESC_DONE		0x4
323 #define	VIO_DESC_MASK		0xf
324 
325 /* Macro to populate the generic fields of the DRing data msg */
326 #define	VIO_INIT_DRING_DATA_TAG(dmsg)	\
327 		dmsg.tag.vio_msgtype = VIO_TYPE_DATA;	\
328 		dmsg.tag.vio_subtype = VIO_SUBTYPE_INFO;	\
329 		dmsg.tag.vio_subtype_env = VIO_DRING_DATA;
330 
331 
332 #ifdef __cplusplus
333 }
334 #endif
335 
336 #endif	/* _SYS_VIO_MAILBOX_H */
337