xref: /titanic_51/usr/src/uts/sun4v/sys/vnet.h (revision c1c61f44e88f4c8c155272ee56d868043146096a)
11ae08745Sheppo /*
21ae08745Sheppo  * CDDL HEADER START
31ae08745Sheppo  *
41ae08745Sheppo  * The contents of this file are subject to the terms of the
51ae08745Sheppo  * Common Development and Distribution License (the "License").
61ae08745Sheppo  * You may not use this file except in compliance with the License.
71ae08745Sheppo  *
81ae08745Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91ae08745Sheppo  * or http://www.opensolaris.org/os/licensing.
101ae08745Sheppo  * See the License for the specific language governing permissions
111ae08745Sheppo  * and limitations under the License.
121ae08745Sheppo  *
131ae08745Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
141ae08745Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151ae08745Sheppo  * If applicable, add the following below this CDDL HEADER, with the
161ae08745Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
171ae08745Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
181ae08745Sheppo  *
191ae08745Sheppo  * CDDL HEADER END
201ae08745Sheppo  */
211ae08745Sheppo 
221ae08745Sheppo /*
23*c1c61f44Ssb155480  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
241ae08745Sheppo  * Use is subject to license terms.
251ae08745Sheppo  */
261ae08745Sheppo 
271ae08745Sheppo #ifndef _VNET_H
281ae08745Sheppo #define	_VNET_H
291ae08745Sheppo 
301ae08745Sheppo #pragma ident	"%Z%%M%	%I%	%E% SMI"
311ae08745Sheppo 
321ae08745Sheppo #ifdef __cplusplus
331ae08745Sheppo extern "C" {
341ae08745Sheppo #endif
351ae08745Sheppo 
361ae08745Sheppo #define	VNET_SUCCESS		(0)	/* successful return */
371ae08745Sheppo #define	VNET_FAILURE		(-1)	/* unsuccessful return */
381ae08745Sheppo 
391ae08745Sheppo #define	KMEM_FREE(_p)		kmem_free((_p), sizeof (*(_p)))
401ae08745Sheppo 
411ae08745Sheppo #define	VNET_NTXDS		512		/* power of 2 tx descriptors */
421ae08745Sheppo #define	VNET_LDCWD_INTERVAL	1000		/* watchdog freq in msec */
431ae08745Sheppo #define	VNET_LDCWD_TXTIMEOUT	1000		/* tx timeout in msec */
44e1ebb9ecSlm66018 #define	VNET_LDC_MTU		64		/* ldc mtu */
451ae08745Sheppo 
46*c1c61f44Ssb155480 #define	VNET_VNETPORT		1		/* port connected to a vnet */
47*c1c61f44Ssb155480 #define	VNET_VSWPORT		2		/* port connected to vsw */
48*c1c61f44Ssb155480 
491ae08745Sheppo /*
501ae08745Sheppo  * vnet proxy transport layer information. There is one instance of this for
511ae08745Sheppo  * every transport being used by a vnet device and a list of these transports
521ae08745Sheppo  * is maintained by vnet.
531ae08745Sheppo  */
541ae08745Sheppo typedef struct vp_tl {
551ae08745Sheppo 	struct vp_tl		*nextp;			/* next in list */
56ba2e4443Sseb 	mac_register_t		*macp;			/* transport ops */
571ae08745Sheppo 	char			name[LIFNAMSIZ];	/* device name */
581ae08745Sheppo 	major_t			major;			/* driver major # */
591ae08745Sheppo 	uint_t			instance;		/* dev instance */
601ae08745Sheppo } vp_tl_t;
611ae08745Sheppo 
621ae08745Sheppo /*
63*c1c61f44Ssb155480  * Forwarding database entry. Each port of a vnet device will have an entry in
64*c1c61f44Ssb155480  * the fdb. Reference count is bumped up while sending a packet destined to a
65*c1c61f44Ssb155480  * port corresponding to the fdb entry.
661ae08745Sheppo  */
67*c1c61f44Ssb155480 typedef struct vnet_fdbe {
68*c1c61f44Ssb155480 	uint8_t		type;	/* VNET_VNETPORT or VNET_VSWPORT ? */
69*c1c61f44Ssb155480 	uint32_t	refcnt;	/* reference count */
701ae08745Sheppo 	void		*txarg;	/* arg to the transmit func */
71*c1c61f44Ssb155480 	mac_tx_t 	m_tx;	/* transmit function */
72*c1c61f44Ssb155480 } vnet_fdbe_t;
731ae08745Sheppo 
74*c1c61f44Ssb155480 #define	VNET_NFDB_HASH	64
751ae08745Sheppo 
76*c1c61f44Ssb155480 #define	KEY_HASH(key, addr) \
77*c1c61f44Ssb155480 	(key = ((((uint64_t)(addr)->ether_addr_octet[0]) << 40) | \
78*c1c61f44Ssb155480 	(((uint64_t)(addr)->ether_addr_octet[1]) << 32) | \
79*c1c61f44Ssb155480 	(((uint64_t)(addr)->ether_addr_octet[2]) << 24) | \
80*c1c61f44Ssb155480 	(((uint64_t)(addr)->ether_addr_octet[3]) << 16) | \
81*c1c61f44Ssb155480 	(((uint64_t)(addr)->ether_addr_octet[4]) << 8) | \
82*c1c61f44Ssb155480 	((uint64_t)(addr)->ether_addr_octet[5])));
831ae08745Sheppo 
841ae08745Sheppo /* rwlock macros */
851ae08745Sheppo #define	READ_ENTER(x)	rw_enter(x, RW_READER)
861ae08745Sheppo #define	WRITE_ENTER(x)	rw_enter(x, RW_WRITER)
871ae08745Sheppo #define	RW_EXIT(x)	rw_exit(x)
881ae08745Sheppo 
89*c1c61f44Ssb155480 #define	VLAN_ID_KEY(key)	((mod_hash_key_t)(uintptr_t)(key))
90*c1c61f44Ssb155480 
911ae08745Sheppo /*
921ae08745Sheppo  * vnet instance state information
931ae08745Sheppo  */
941ae08745Sheppo typedef struct vnet {
951ae08745Sheppo 	int			instance;	/* instance # */
961ae08745Sheppo 	dev_info_t		*dip;		/* dev_info */
971ae08745Sheppo 	struct vnet		*nextp;		/* next in list */
98ba2e4443Sseb 	mac_handle_t 		mh;		/* handle to GLDv3 mac module */
991ae08745Sheppo 	uchar_t			vendor_addr[ETHERADDRL]; /* orig macadr */
1001ae08745Sheppo 	uchar_t			curr_macaddr[ETHERADDRL]; /* current macadr */
1011ae08745Sheppo 	vp_tl_t			*tlp;		/* list of vp_tl */
1021ae08745Sheppo 	krwlock_t		trwlock;	/* lock for vp_tl list */
1031ae08745Sheppo 	char			vgen_name[MAXNAMELEN];	/* name of generic tl */
104*c1c61f44Ssb155480 
105*c1c61f44Ssb155480 	uint32_t		fdb_nchains;	/* # of hash chains in fdbtbl */
106*c1c61f44Ssb155480 	mod_hash_t		*fdb_hashp;	/* forwarding database */
107*c1c61f44Ssb155480 	vnet_fdbe_t		*vsw_fp;	/* cached fdb entry of vsw */
108*c1c61f44Ssb155480 	krwlock_t		vsw_fp_rw;	/* lock to protect vsw_fp */
109*c1c61f44Ssb155480 	uint32_t		max_frame_size;	/* max frame size supported */
110*c1c61f44Ssb155480 
111*c1c61f44Ssb155480 	uint16_t		default_vlan_id; /* default vlan id */
112*c1c61f44Ssb155480 	uint16_t		pvid;		/* port vlan id (untagged) */
113*c1c61f44Ssb155480 	uint16_t		*vids;		/* vlan ids (tagged) */
114*c1c61f44Ssb155480 	uint16_t		nvids;		/* # of vids */
1151ae08745Sheppo } vnet_t;
1161ae08745Sheppo 
117844e62a3Sraghuram #ifdef DEBUG
118844e62a3Sraghuram /*
119844e62a3Sraghuram  * debug levels:
120844e62a3Sraghuram  * DBG_LEVEL1:	Function entry/exit tracing
121844e62a3Sraghuram  * DBG_LEVEL2:	Info messages
122844e62a3Sraghuram  * DBG_LEVEL3:	Warning messages
123844e62a3Sraghuram  * DBG_LEVEL4:	Error messages
124844e62a3Sraghuram  */
125844e62a3Sraghuram 
126844e62a3Sraghuram enum	{ DBG_LEVEL1 = 0x01, DBG_LEVEL2 = 0x02, DBG_WARN = 0x04,
127844e62a3Sraghuram 	    DBG_ERR = 0x08 };
128844e62a3Sraghuram 
129844e62a3Sraghuram #define	DBG1(...)	do {						\
130844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_LEVEL1) != 0) {	\
131844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
132844e62a3Sraghuram 			    }						\
133844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
134844e62a3Sraghuram 
135844e62a3Sraghuram #define	DBG2(...)	do {						\
136844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_LEVEL2) != 0) {	\
137844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
138844e62a3Sraghuram 			    }						\
139844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
140844e62a3Sraghuram 
141844e62a3Sraghuram #define	DWARN(...)	do {						\
142844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_WARN) != 0) {	\
143844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
144844e62a3Sraghuram 			    }						\
145844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
146844e62a3Sraghuram 
147844e62a3Sraghuram #define	DERR(...)	do {						\
148844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_ERR) != 0) {	\
149844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
150844e62a3Sraghuram 			    }						\
151844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
152844e62a3Sraghuram 
153844e62a3Sraghuram #else
154844e62a3Sraghuram 
155844e62a3Sraghuram #define	DBG1(...)	if (0)	do { } while (0)
156844e62a3Sraghuram #define	DBG2(...)	if (0)	do { } while (0)
157844e62a3Sraghuram #define	DWARN(...)	if (0)	do { } while (0)
158844e62a3Sraghuram #define	DERR(...)	if (0)	do { } while (0)
159844e62a3Sraghuram 
160844e62a3Sraghuram #endif
161844e62a3Sraghuram 
1621ae08745Sheppo #ifdef __cplusplus
1631ae08745Sheppo }
1641ae08745Sheppo #endif
1651ae08745Sheppo 
1661ae08745Sheppo #endif	/* _VNET_H */
167