xref: /titanic_44/usr/src/uts/sun4v/sys/vnet_common.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 _VNET_COMMON_H
28 #define	_VNET_COMMON_H
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #include <sys/vio_common.h>
35 #include <sys/vio_mailbox.h>
36 #include <sys/ethernet.h>
37 
38 /*
39  * This header file contains definitions common to LDoms Virtual Network
40  * server (vsw) and client (vnet).
41  */
42 
43 /* max # of cookies per frame size */
44 #define	MAX_COOKIES	 ((ETHERMAX >> MMU_PAGESHIFT) + 2ULL)
45 
46 /* initial send sequence number */
47 #define	VNET_ISS		0x1
48 
49 #define	VNET_2K			(1 << 11)
50 #define	VNET_4K			(1 << 12)
51 #define	VNET_8K			(1 << 13)
52 #define	VNET_12K		((VNET_8K) + (VNET_4K))
53 #define	VNET_IPALIGN		6	/* padding for IP header alignment */
54 #define	VNET_LDCALIGN		8	/* padding for ldc_mem_copy() align */
55 #define	VNET_ROUNDUP_2K(n)	(((n) + (VNET_2K - 1)) & ~(VNET_2K - 1))
56 #define	VNET_ROUNDUP_4K(n)	(((n) + (VNET_4K - 1)) & ~(VNET_4K - 1))
57 #define	VNET_ROUNDUP_8K(n)	(((n) + (VNET_8K - 1)) & ~(VNET_8K - 1))
58 
59 /*
60  * Maximum MTU value currently supported. MAX_COOKIES for data has been defined
61  * already based on ETHERMAX. Hence we limit the MTU to be within 2 8K pages
62  * and take some additional steps (see related code in .c files) to ensure that
63  * ldc cookies for each data buffer is within the MAX_COOKIES. This allows us
64  * to support Jumbo MTUs without changing the size of the descriptor.
65  */
66 #define	VNET_MAX_MTU		16000
67 
68 #define	VNET_NUM_HANDSHAKES	6	/* # of handshake attempts */
69 
70 /* vnet descriptor */
71 typedef struct vnet_public_desc {
72 	vio_dring_entry_hdr_t	hdr;		/* descriptor header */
73 	uint32_t		nbytes;		/* data length */
74 	uint32_t		ncookies;	/* number of data cookies */
75 	ldc_mem_cookie_t	memcookie[MAX_COOKIES]; /* data cookies */
76 } vnet_public_desc_t;
77 
78 /*
79  * Vnet in-band descriptor. Used by those vnet clients
80  * such as OBP who do not use descriptor rings.
81  */
82 typedef struct vnet_ibnd_desc {
83 	vio_inband_desc_msg_hdr_t	hdr;
84 
85 	/* payload */
86 	uint32_t			nbytes;
87 	uint32_t			ncookies;
88 	ldc_mem_cookie_t		memcookie[MAX_COOKIES];
89 } vnet_ibnd_desc_t;
90 
91 /* exported functions */
92 uint64_t vnet_macaddr_strtoul(const uint8_t *macaddr);
93 void vnet_macaddr_ultostr(uint64_t value, uint8_t *macaddr);
94 mblk_t *vnet_vlan_insert_tag(mblk_t *mp, uint16_t vid);
95 mblk_t *vnet_vlan_remove_tag(mblk_t *mp);
96 int vnet_dring_entry_copy(vnet_public_desc_t *dst, vnet_public_desc_t *src,
97     uint8_t mtype, ldc_dring_handle_t handle, uint64_t start, uint64_t stop);
98 int vnet_dring_entry_set_dstate(vnet_public_desc_t *descp, uint8_t mtype,
99     ldc_dring_handle_t handle, uint64_t start, uint64_t stop, uint8_t dstate);
100 
101 #ifdef __cplusplus
102 }
103 #endif
104 
105 #endif	/* _VNET_COMMON_H */
106