xref: /titanic_53/usr/src/uts/sun4v/sys/vnet.h (revision 3fd94f8c011031b38162a1db3b554de4371c167f)
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 /*
23c1c61f44Ssb155480  * 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 
36678453a8Sspeer #include <sys/vnet_res.h>
37678453a8Sspeer #include <sys/vnet_mailbox.h>
38*3fd94f8cSam223141 #include <sys/modhash.h>
39678453a8Sspeer 
401ae08745Sheppo #define	VNET_SUCCESS		(0)	/* successful return */
411ae08745Sheppo #define	VNET_FAILURE		(-1)	/* unsuccessful return */
421ae08745Sheppo 
431ae08745Sheppo #define	KMEM_FREE(_p)		kmem_free((_p), sizeof (*(_p)))
441ae08745Sheppo 
451ae08745Sheppo #define	VNET_NTXDS		512		/* power of 2 tx descriptors */
461ae08745Sheppo #define	VNET_LDCWD_INTERVAL	1000		/* watchdog freq in msec */
471ae08745Sheppo #define	VNET_LDCWD_TXTIMEOUT	1000		/* tx timeout in msec */
48e1ebb9ecSlm66018 #define	VNET_LDC_MTU		64		/* ldc mtu */
491ae08745Sheppo 
50678453a8Sspeer 
51678453a8Sspeer #define	IS_BROADCAST(ehp) \
52678453a8Sspeer 		(ether_cmp(&ehp->ether_dhost, &etherbroadcastaddr) == 0)
53678453a8Sspeer #define	IS_MULTICAST(ehp) \
54678453a8Sspeer 		((ehp->ether_dhost.ether_addr_octet[0] & 01) == 1)
55678453a8Sspeer 
56678453a8Sspeer #define	VNET_MATCH_RES(vresp, vnetp)	\
57678453a8Sspeer 	(ether_cmp(vresp->local_macaddr, vnetp->curr_macaddr) == 0)
58c1c61f44Ssb155480 
591ae08745Sheppo /*
60678453a8Sspeer  * A vnet resource structure.
611ae08745Sheppo  */
62678453a8Sspeer typedef struct vnet_res {
63678453a8Sspeer 	struct vnet_res		*nextp;		/* next resource in the list */
64678453a8Sspeer 	mac_register_t		macreg;		/* resource's mac_reg */
65678453a8Sspeer 	vio_net_res_type_t	type;		/* resource type */
66678453a8Sspeer 	ether_addr_t		local_macaddr;	/* resource's macaddr */
67678453a8Sspeer 	ether_addr_t		rem_macaddr;	/* resource's remote macaddr */
68678453a8Sspeer 	uint32_t		flags;		/* resource flags */
69c1c61f44Ssb155480 	uint32_t		refcnt;		/* reference count */
70678453a8Sspeer 	struct	vnet		*vnetp;		/* back pointer to vnet */
71678453a8Sspeer } vnet_res_t;
72678453a8Sspeer 
73678453a8Sspeer #define	VNET_DDS_TASK_ADD_SHARE		0x01
74678453a8Sspeer #define	VNET_DDS_TASK_DEL_SHARE		0x02
75678453a8Sspeer #define	VNET_DDS_TASK_REL_SHARE		0x04
76678453a8Sspeer 
77678453a8Sspeer /* An instance specific DDS structure */
78678453a8Sspeer typedef struct vnet_dds_info {
79678453a8Sspeer 	kmutex_t	lock;		/* lock for this structure */
80678453a8Sspeer 	uint8_t		task_flags;	/* flags for taskq */
81678453a8Sspeer 	uint8_t		dds_req_id;	/* DDS message request id */
82678453a8Sspeer 	vio_dds_msg_t	dmsg;		/* Pending DDS message */
83678453a8Sspeer 	dev_info_t	*hio_dip;	/* Hybrid device's dip */
84678453a8Sspeer 	uint64_t	hio_cookie;	/* Hybrid device's cookie */
85678453a8Sspeer 	ddi_taskq_t	*dds_taskqp;	/* Taskq's used for DDS */
86678453a8Sspeer 	struct vnet	*vnetp;		/* Back pointer to vnetp */
87678453a8Sspeer } vnet_dds_info_t;
881ae08745Sheppo 
89c1c61f44Ssb155480 #define	VNET_NFDB_HASH	64
901ae08745Sheppo 
91c1c61f44Ssb155480 #define	KEY_HASH(key, addr) \
92678453a8Sspeer 	(key = (((uint64_t)(addr[0])) << 40) | \
93678453a8Sspeer 	(((uint64_t)(addr[1])) << 32) | \
94678453a8Sspeer 	(((uint64_t)(addr[2])) << 24) | \
95678453a8Sspeer 	(((uint64_t)(addr[3])) << 16) | \
96678453a8Sspeer 	(((uint64_t)(addr[4])) << 8) | \
97678453a8Sspeer 	((uint64_t)(addr[5])));
98678453a8Sspeer 
991ae08745Sheppo 
1001ae08745Sheppo /* rwlock macros */
1011ae08745Sheppo #define	READ_ENTER(x)	rw_enter(x, RW_READER)
1021ae08745Sheppo #define	WRITE_ENTER(x)	rw_enter(x, RW_WRITER)
1031ae08745Sheppo #define	RW_EXIT(x)	rw_exit(x)
1041ae08745Sheppo 
105c1c61f44Ssb155480 #define	VLAN_ID_KEY(key)	((mod_hash_key_t)(uintptr_t)(key))
106c1c61f44Ssb155480 
1071ae08745Sheppo /*
1081ae08745Sheppo  * vnet instance state information
1091ae08745Sheppo  */
1101ae08745Sheppo typedef struct vnet {
1111ae08745Sheppo 	int			instance;	/* instance # */
1121ae08745Sheppo 	dev_info_t		*dip;		/* dev_info */
113678453a8Sspeer 	uint64_t		reg;		/* reg prop value */
1141ae08745Sheppo 	struct vnet		*nextp;		/* next in list */
115ba2e4443Sseb 	mac_handle_t		mh;		/* handle to GLDv3 mac module */
1161ae08745Sheppo 	uchar_t			vendor_addr[ETHERADDRL]; /* orig macadr */
1171ae08745Sheppo 	uchar_t			curr_macaddr[ETHERADDRL]; /* current macadr */
118678453a8Sspeer 	void			*vgenhdl;	/* Handle for vgen */
119c1c61f44Ssb155480 
120c1c61f44Ssb155480 	uint32_t		fdb_nchains;	/* # of hash chains in fdbtbl */
121c1c61f44Ssb155480 	mod_hash_t		*fdb_hashp;	/* forwarding database */
122678453a8Sspeer 	vnet_res_t		*vsw_fp;	/* cached fdb entry of vsw */
123c1c61f44Ssb155480 	krwlock_t		vsw_fp_rw;	/* lock to protect vsw_fp */
124c1c61f44Ssb155480 	uint32_t		max_frame_size;	/* max frame size supported */
125c1c61f44Ssb155480 
126c1c61f44Ssb155480 	uint16_t		default_vlan_id; /* default vlan id */
127c1c61f44Ssb155480 	uint16_t		pvid;		/* port vlan id (untagged) */
128c1c61f44Ssb155480 	uint16_t		*vids;		/* vlan ids (tagged) */
129c1c61f44Ssb155480 	uint16_t		nvids;		/* # of vids */
130678453a8Sspeer 
131678453a8Sspeer 	uint32_t		flags;		/* interface flags */
132678453a8Sspeer 	vnet_res_t		*hio_fp;	/* Hybrid IO resource */
133678453a8Sspeer 	vnet_res_t		*vres_list;	/* Resource list */
134678453a8Sspeer 	vnet_dds_info_t		vdds_info;	/* DDS related info */
135678453a8Sspeer 	krwlock_t		vrwlock;	/* Resource list lock */
136678453a8Sspeer 	ddi_taskq_t		*taskqp;	/* Resource taskq */
1371ae08745Sheppo } vnet_t;
1381ae08745Sheppo 
139678453a8Sspeer #define	VNET_STARTED	0x01
140678453a8Sspeer 
141844e62a3Sraghuram #ifdef DEBUG
142844e62a3Sraghuram /*
143844e62a3Sraghuram  * debug levels:
144844e62a3Sraghuram  * DBG_LEVEL1:	Function entry/exit tracing
145844e62a3Sraghuram  * DBG_LEVEL2:	Info messages
146844e62a3Sraghuram  * DBG_LEVEL3:	Warning messages
147844e62a3Sraghuram  * DBG_LEVEL4:	Error messages
148844e62a3Sraghuram  */
149844e62a3Sraghuram 
150844e62a3Sraghuram enum	{ DBG_LEVEL1 = 0x01, DBG_LEVEL2 = 0x02, DBG_WARN = 0x04,
151844e62a3Sraghuram 	    DBG_ERR = 0x08 };
152844e62a3Sraghuram 
153844e62a3Sraghuram #define	DBG1(...)	do {						\
154844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_LEVEL1) != 0) {	\
155844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
156844e62a3Sraghuram 			    }						\
157844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
158844e62a3Sraghuram 
159844e62a3Sraghuram #define	DBG2(...)	do {						\
160844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_LEVEL2) != 0) {	\
161844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
162844e62a3Sraghuram 			    }						\
163844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
164844e62a3Sraghuram 
165844e62a3Sraghuram #define	DWARN(...)	do {						\
166844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_WARN) != 0) {	\
167844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
168844e62a3Sraghuram 			    }						\
169844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
170844e62a3Sraghuram 
171844e62a3Sraghuram #define	DERR(...)	do {						\
172844e62a3Sraghuram 			    if ((vnet_dbglevel & DBG_ERR) != 0) {	\
173844e62a3Sraghuram 				debug_printf(__func__, __VA_ARGS__);	\
174844e62a3Sraghuram 			    }						\
175844e62a3Sraghuram 			_NOTE(CONSTCOND) } while (0)
176844e62a3Sraghuram 
177844e62a3Sraghuram #else
178844e62a3Sraghuram 
179844e62a3Sraghuram #define	DBG1(...)	if (0)	do { } while (0)
180844e62a3Sraghuram #define	DBG2(...)	if (0)	do { } while (0)
181844e62a3Sraghuram #define	DWARN(...)	if (0)	do { } while (0)
182844e62a3Sraghuram #define	DERR(...)	if (0)	do { } while (0)
183844e62a3Sraghuram 
184844e62a3Sraghuram #endif
185844e62a3Sraghuram 
1861ae08745Sheppo #ifdef __cplusplus
1871ae08745Sheppo }
1881ae08745Sheppo #endif
1891ae08745Sheppo 
1901ae08745Sheppo #endif	/* _VNET_H */
191