xref: /titanic_52/usr/src/uts/sun4v/sys/vnet_common.h (revision 34f94fbc7a730740933e4776ade5f74009afe4ce)
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 (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
24  */
25 
26 #ifndef _VNET_COMMON_H
27 #define	_VNET_COMMON_H
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <sys/vio_common.h>
34 #include <sys/vio_mailbox.h>
35 #include <sys/ethernet.h>
36 
37 /*
38  * This header file contains definitions common to LDoms Virtual Network
39  * server (vsw) and client (vnet).
40  */
41 
42 /* max # of cookies per frame size in TxDring mode */
43 #define	MAX_COOKIES	 ((ETHERMAX >> MMU_PAGESHIFT) + 2ULL)
44 
45 /*
46  * Max # of data area cookies that we support in RxDringData mode. This is
47  * pre-defined to avoid allocating and importing a large # of cookies for the
48  * data area. We know that the export map table on the exporting end point is
49  * per LDC. We also know that a single cookie can be obtained if we manage
50  * to get consecutive entries in the export map table. We use this knowledge to
51  * limit the # of cookies to a pre-defined maximum value.
52  */
53 #define	VNET_DATA_AREA_COOKIES	32
54 
55 /*
56  * Size of dring reg msg in RxDringData mode, given # of data area cookies.
57  * This assumes that the # of dring cookies in vio_dring_reg_msg_t is 1.
58  * The given # of data area cookies is reduced by 1, as vio_dring_reg_msg_ext_t
59  * itself contains 1 data cookie.
60  */
61 #define	VNET_DRING_REG_EXT_MSG_SIZE(data_ncookies)		\
62 	(sizeof (vio_dring_reg_msg_t) + sizeof (vio_dring_reg_ext_msg_t) + \
63 	(((data_ncookies) - 1) * sizeof (ldc_mem_cookie_t)))
64 
65 /* Max supported size of dring reg msg in RxDringData mode */
66 #define	VNET_DRING_REG_EXT_MSG_SIZE_MAX				\
67 	VNET_DRING_REG_EXT_MSG_SIZE(VNET_DATA_AREA_COOKIES)
68 
69 /* initial send sequence number */
70 #define	VNET_ISS		0x1
71 
72 #define	VNET_START_IDX_UNSPEC	0xFFFFFFFF /* ignore st_idx in dringdata ack */
73 
74 #define	VNET_2K			(1 << 11)
75 #define	VNET_4K			(1 << 12)
76 #define	VNET_8K			(1 << 13)
77 #define	VNET_12K		((VNET_8K) + (VNET_4K))
78 #define	VNET_IPALIGN		6	/* padding for IP header alignment */
79 #define	VNET_LDCALIGN		8	/* padding for ldc_mem_copy() align */
80 #define	VNET_ROUNDUP_2K(n)	(((n) + (VNET_2K - 1)) & ~(VNET_2K - 1))
81 #define	VNET_ROUNDUP_4K(n)	(((n) + (VNET_4K - 1)) & ~(VNET_4K - 1))
82 #define	VNET_ROUNDUP_8K(n)	(((n) + (VNET_8K - 1)) & ~(VNET_8K - 1))
83 
84 #define	MEMBAR_CONSUMER		membar_consumer
85 #define	MEMBAR_PRODUCER		membar_producer
86 
87 /*
88  * Maximum MTU value currently supported. MAX_COOKIES for data has been defined
89  * already based on ETHERMAX. Hence we limit the MTU to be within 2 8K pages
90  * and take some additional steps (see related code in .c files) to ensure that
91  * ldc cookies for each data buffer is within the MAX_COOKIES. This allows us
92  * to support Jumbo MTUs without changing the size of the descriptor.
93  */
94 #define	VNET_MAX_MTU		16000
95 
96 #define	VNET_NUM_HANDSHAKES	6	/* # of handshake attempts */
97 
98 /*
99  * Max frame size to data block size in RxDringData mode
100  */
101 #define	RXDRING_DBLK_SZ(mfs) \
102 	(VNET_ROUNDUP_2K((mfs) + VNET_IPALIGN + VNET_LDCALIGN))
103 
104 /* vnet descriptor */
105 typedef struct vnet_public_desc {
106 	vio_dring_entry_hdr_t	hdr;		/* descriptor header */
107 	uint32_t		nbytes;		/* data length */
108 	uint32_t		ncookies;	/* number of data cookies */
109 	ldc_mem_cookie_t	memcookie[MAX_COOKIES]; /* data cookies */
110 } vnet_public_desc_t;
111 
112 /*
113  * Vnet in-band descriptor. Used by those vnet clients
114  * such as OBP who do not use descriptor rings.
115  */
116 typedef struct vnet_ibnd_desc {
117 	vio_inband_desc_msg_hdr_t	hdr;
118 
119 	/* payload */
120 	uint32_t			nbytes;
121 	uint32_t			ncookies;
122 	ldc_mem_cookie_t		memcookie[MAX_COOKIES];
123 } vnet_ibnd_desc_t;
124 
125 /*
126  * Descriptor format in RxDringData mode.
127  */
128 typedef struct vnet_rxdring_data_desc {
129 	uint8_t		dstate;			/* Descriptor state */
130 	uint8_t		resv1[3];		/* Reserved */
131 	uint32_t	nbytes;			/* Num bytes in data buffer */
132 	uint64_t	data_buf_offset;	/* Offset of data buffer */
133 } vnet_rx_dringdata_desc_t;
134 
135 /* exported functions */
136 uint64_t vnet_macaddr_strtoul(const uint8_t *macaddr);
137 void vnet_macaddr_ultostr(uint64_t value, uint8_t *macaddr);
138 mblk_t *vnet_vlan_insert_tag(mblk_t *mp, uint16_t vid);
139 mblk_t *vnet_vlan_remove_tag(mblk_t *mp);
140 int vnet_dring_entry_copy(vnet_public_desc_t *dst, vnet_public_desc_t *src,
141     uint8_t mtype, ldc_dring_handle_t handle, uint64_t start, uint64_t stop);
142 int vnet_dring_entry_set_dstate(vnet_public_desc_t *descp, uint8_t mtype,
143     ldc_dring_handle_t handle, uint64_t start, uint64_t stop, uint8_t dstate);
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif	/* _VNET_COMMON_H */
150