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