xref: /titanic_50/usr/src/uts/sun4v/sys/vnet.h (revision 60c807700988885656502665e0cf8afd4b4346f7)
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 _VNET_H
28 #define	_VNET_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define	VNET_SUCCESS		(0)	/* successful return */
37 #define	VNET_FAILURE		(-1)	/* unsuccessful return */
38 
39 #define	KMEM_FREE(_p)		kmem_free((_p), sizeof (*(_p)))
40 
41 #define	VNET_NTXDS		512		/* power of 2 tx descriptors */
42 #define	VNET_RECLAIM_LOWAT	32		/* tx reclaim low watermark */
43 #define	VNET_RECLAIM_HIWAT	(512 - 32)	/* tx reclaim high watermark */
44 #define	VNET_LDCWD_INTERVAL	1000		/* watchdog freq in msec */
45 #define	VNET_LDCWD_TXTIMEOUT	1000		/* tx timeout in msec */
46 #define	VNET_LDC_QLEN		1024		/* ldc qlen */
47 
48 /*
49  * vnet proxy transport layer information. There is one instance of this for
50  * every transport being used by a vnet device and a list of these transports
51  * is maintained by vnet.
52  */
53 typedef struct vp_tl {
54 	struct vp_tl		*nextp;			/* next in list */
55 	mac_t			*macp;			/* transport ops */
56 	char			name[LIFNAMSIZ];	/* device name */
57 	major_t			major;			/* driver major # */
58 	uint_t			instance;		/* dev instance */
59 } vp_tl_t;
60 
61 /*
62  * Forwarding database (FDB) entry, used by vnet to provide switching
63  * functionality. Each fdb entry corresponds to a destination vnet device
64  * within the ldoms which is directly reachable by invoking a transmit
65  * function provided by a vnet proxy transport layer. Currently, the generic
66  * transport layer adds/removes/modifies entries in fdb.
67  */
68 typedef struct fdb {
69 	struct fdb	*nextp;			/* next entry in the list */
70 	uint8_t		macaddr[ETHERADDRL];	/* destination mac address */
71 	mac_tx_t	m_tx;			/* transmit function */
72 	void		*txarg;			/* arg to the transmit func */
73 } fdb_t;
74 
75 /* FDB hash queue head */
76 typedef struct fdbf_s {
77 	fdb_t		*headp;			/* head of fdb entries */
78 	krwlock_t	rwlock;			/* protect the list */
79 } fdb_fanout_t;
80 
81 #define	VNET_NFDB_HASH	4	/* default number of hash queues in fdb */
82 #define	VNET_NFDB_HASH_MAX 32	/* max number of hash queues in fdb */
83 
84 /* Hash calculation using the mac address */
85 #define	MACHASH(a, n)	((*(((uchar_t *)(a)) + 0) ^		\
86 			*(((uchar_t *)(a)) + 1) ^		\
87 			*(((uchar_t *)(a)) + 2) ^		\
88 			*(((uchar_t *)(a)) + 3) ^		\
89 			*(((uchar_t *)(a)) + 4) ^		\
90 			*(((uchar_t *)(a)) + 5)) % (uint32_t)n)
91 
92 /* rwlock macros */
93 #define	READ_ENTER(x)	rw_enter(x, RW_READER)
94 #define	WRITE_ENTER(x)	rw_enter(x, RW_WRITER)
95 #define	RW_EXIT(x)	rw_exit(x)
96 
97 /*
98  * vnet instance state information
99  */
100 typedef struct vnet {
101 	int			instance;	/* instance # */
102 	dev_info_t		*dip;		/* dev_info */
103 	struct vnet		*nextp;		/* next in list */
104 	mac_t 			*macp;		/* MAC - macinfo */
105 	uchar_t			vendor_addr[ETHERADDRL]; /* orig macadr */
106 	uchar_t			curr_macaddr[ETHERADDRL]; /* current macadr */
107 	vp_tl_t			*tlp;		/* list of vp_tl */
108 	krwlock_t		trwlock;	/* lock for vp_tl list */
109 	char			vgen_name[MAXNAMELEN];	/* name of generic tl */
110 	fdb_fanout_t		*fdbhp;		/* fdb hash queues */
111 	int			nfdb_hash;	/* num fdb hash queues */
112 } vnet_t;
113 
114 #ifdef __cplusplus
115 }
116 #endif
117 
118 #endif	/* _VNET_H */
119