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