xref: /titanic_52/usr/src/uts/sun4v/sys/vnet_gen.h (revision 34f94fbc7a730740933e4776ade5f74009afe4ce)
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*34f94fbcSWENTAO YANG  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
241ae08745Sheppo  */
251ae08745Sheppo 
261ae08745Sheppo #ifndef _VNET_GEN_H
271ae08745Sheppo #define	_VNET_GEN_H
281ae08745Sheppo 
291ae08745Sheppo #ifdef __cplusplus
301ae08745Sheppo extern "C" {
311ae08745Sheppo #endif
321ae08745Sheppo 
3306db247cSraghuram #include <sys/vgen_stats.h>
3406db247cSraghuram 
351ae08745Sheppo #define	VGEN_SUCCESS		(0)	/* successful return */
361ae08745Sheppo #define	VGEN_FAILURE		(-1)	/* unsuccessful return */
371ae08745Sheppo 
381ae08745Sheppo #define	VGEN_NUM_VER		1	/* max # of vgen versions */
391ae08745Sheppo 
401ae08745Sheppo #define	VGEN_LOCAL	1	/* local ldc end-point */
411ae08745Sheppo #define	VGEN_PEER	2	/* peer ldc end-point */
421ae08745Sheppo 
431ae08745Sheppo /* vgen_t flags */
441ae08745Sheppo #define	VGEN_STOPPED		0x0
451ae08745Sheppo #define	VGEN_STARTED		0x1
461ae08745Sheppo 
471ae08745Sheppo #define	KMEM_FREE(_p)		kmem_free((_p), sizeof (*(_p)))
481ae08745Sheppo 
491ae08745Sheppo #define	VGEN_INIT_MCTAB_SIZE	16	/* initial size of multicast table */
501ae08745Sheppo 
511ae08745Sheppo #define	READ_ENTER(x)	rw_enter(x, RW_READER)
521ae08745Sheppo #define	WRITE_ENTER(x)	rw_enter(x, RW_WRITER)
531ae08745Sheppo #define	RW_EXIT(x)	rw_exit(x)
541ae08745Sheppo 
551ae08745Sheppo /* channel flags */
561ae08745Sheppo #define	CHANNEL_ATTACHED	0x1
571ae08745Sheppo #define	CHANNEL_STARTED		0x2
581ae08745Sheppo 
591ae08745Sheppo /* transmit return values */
601ae08745Sheppo #define	VGEN_TX_SUCCESS		0	/* transmit success */
611ae08745Sheppo #define	VGEN_TX_FAILURE		1	/* transmit failure */
621ae08745Sheppo #define	VGEN_TX_NORESOURCES	2	/* out of tbufs/txds */
631ae08745Sheppo 
641ae08745Sheppo /* private descriptor flags */
651ae08745Sheppo #define	VGEN_PRIV_DESC_FREE	0x0	/* desc is available */
661ae08745Sheppo #define	VGEN_PRIV_DESC_BUSY	0x1	/* desc in use */
671ae08745Sheppo 
681ae08745Sheppo #define	LDC_TO_VNET(ldcp)  ((ldcp)->portp->vgenp->vnetp)
691ae08745Sheppo #define	LDC_TO_VGEN(ldcp)  ((ldcp)->portp->vgenp)
701ae08745Sheppo 
71844e62a3Sraghuram /* receive thread flags */
726f09f0feSWENTAO YANG #define	VGEN_WTHR_DATARCVD 		0x01 /* data received */
737bd3a2e2SSriharsha Basavapatna #define	VGEN_WTHR_STOP 			0x02 /* stop worker thr request */
747bd3a2e2SSriharsha Basavapatna #define	VGEN_WTHR_PROCESSING		0x04 /* worker thr awake & processing */
75844e62a3Sraghuram 
767bd3a2e2SSriharsha Basavapatna #define	VGEN_LDC_MTU		64	/* ldc pkt transfer mtu */
778e6a2a04Slm66018 #define	VGEN_LDC_UP_DELAY	100	/* usec delay between ldc_up retries */
78195ce4e5SSriharsha Basavapatna #define	VGEN_LDC_CLOSE_DELAY	100	/* usec delay between ldc_cl retries */
797bd3a2e2SSriharsha Basavapatna #define	VGEN_LDC_UNINIT_DELAY	100	/* usec delay between uninit retries */
807bd3a2e2SSriharsha Basavapatna #define	VGEN_TXWD_INTERVAL	1000	/* tx watchdog freq in msec */
817bd3a2e2SSriharsha Basavapatna #define	VGEN_TXWD_TIMEOUT	1000	/* tx watchdog timeout in msec */
828e6a2a04Slm66018 
83844e62a3Sraghuram #define	VGEN_NUM_VMPOOLS	3	/* number of vio mblk pools */
84844e62a3Sraghuram 
85844e62a3Sraghuram #define	VGEN_DBLK_SZ_128	128	/* data buffer size 128 bytes */
86844e62a3Sraghuram #define	VGEN_DBLK_SZ_256	256	/* data buffer size 256 bytes */
87844e62a3Sraghuram #define	VGEN_DBLK_SZ_2048	2048	/* data buffer size 2K bytes */
88844e62a3Sraghuram #define	VGEN_NRBUFS		512	/* number of receive bufs */
89844e62a3Sraghuram 
90844e62a3Sraghuram #define	VGEN_TXDBLK_SZ		2048	/* Tx data buffer size */
91844e62a3Sraghuram 
927bd3a2e2SSriharsha Basavapatna #define	VGEN_NUM_DESCRIPTORS_MIN	128	/* min # of descriptors */
937bd3a2e2SSriharsha Basavapatna 
94*34f94fbcSWENTAO YANG /*
95*34f94fbcSWENTAO YANG  * Number of rcv buffers in RxDringData mode
96*34f94fbcSWENTAO YANG  */
97*34f94fbcSWENTAO YANG #define	VGEN_RXDRING_NRBUFS	(vnet_num_descriptors * vgen_nrbufs_factor)
98*34f94fbcSWENTAO YANG 
997bd3a2e2SSriharsha Basavapatna static struct ether_addr etherbroadcastaddr = {
1007bd3a2e2SSriharsha Basavapatna 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff
1017bd3a2e2SSriharsha Basavapatna };
1027bd3a2e2SSriharsha Basavapatna /*
1037bd3a2e2SSriharsha Basavapatna  * MIB II broadcast/multicast packets
1047bd3a2e2SSriharsha Basavapatna  */
1057bd3a2e2SSriharsha Basavapatna #define	IS_BROADCAST(ehp) \
1067bd3a2e2SSriharsha Basavapatna 		(ether_cmp(&ehp->ether_dhost, &etherbroadcastaddr) == 0)
1077bd3a2e2SSriharsha Basavapatna #define	IS_MULTICAST(ehp) \
1087bd3a2e2SSriharsha Basavapatna 		((ehp->ether_dhost.ether_addr_octet[0] & 01) == 1)
1097bd3a2e2SSriharsha Basavapatna 
1107bd3a2e2SSriharsha Basavapatna /*
1117bd3a2e2SSriharsha Basavapatna  * The handshake process consists of 5 phases defined below, with VH_PHASE0
1127bd3a2e2SSriharsha Basavapatna  * being the pre-handshake phase and VH_DONE is the phase to indicate
1137bd3a2e2SSriharsha Basavapatna  * successful completion of all phases. Each phase may have one to several
1147bd3a2e2SSriharsha Basavapatna  * handshake states which are required to complete successfully to move to the
1157bd3a2e2SSriharsha Basavapatna  * next phase. See functions vgen_handshake() and vgen_handshake_done() for
1167bd3a2e2SSriharsha Basavapatna  * more details.
1177bd3a2e2SSriharsha Basavapatna  */
1187bd3a2e2SSriharsha Basavapatna /* Handshake phases */
1197bd3a2e2SSriharsha Basavapatna enum {	VH_PHASE0, VH_PHASE1, VH_PHASE2, VH_PHASE3, VH_PHASE4, VH_DONE = 0x80 };
1207bd3a2e2SSriharsha Basavapatna 
1217bd3a2e2SSriharsha Basavapatna /* Handshake states */
1227bd3a2e2SSriharsha Basavapatna enum {
1237bd3a2e2SSriharsha Basavapatna 
1247bd3a2e2SSriharsha Basavapatna 	VER_INFO_SENT	=	0x1,
1257bd3a2e2SSriharsha Basavapatna 	VER_ACK_RCVD	=	0x2,
1267bd3a2e2SSriharsha Basavapatna 	VER_INFO_RCVD	=	0x4,
1277bd3a2e2SSriharsha Basavapatna 	VER_ACK_SENT	=	0x8,
1287bd3a2e2SSriharsha Basavapatna 	VER_NEGOTIATED	=	(VER_ACK_RCVD | VER_ACK_SENT),
1297bd3a2e2SSriharsha Basavapatna 
1307bd3a2e2SSriharsha Basavapatna 	ATTR_INFO_SENT	=	0x10,
1317bd3a2e2SSriharsha Basavapatna 	ATTR_ACK_RCVD	=	0x20,
1327bd3a2e2SSriharsha Basavapatna 	ATTR_INFO_RCVD	=	0x40,
1337bd3a2e2SSriharsha Basavapatna 	ATTR_ACK_SENT	=	0x80,
1347bd3a2e2SSriharsha Basavapatna 	ATTR_INFO_EXCHANGED	=	(ATTR_ACK_RCVD | ATTR_ACK_SENT),
1357bd3a2e2SSriharsha Basavapatna 
1367bd3a2e2SSriharsha Basavapatna 	DRING_INFO_SENT	=	0x100,
1377bd3a2e2SSriharsha Basavapatna 	DRING_ACK_RCVD	=	0x200,
1387bd3a2e2SSriharsha Basavapatna 	DRING_INFO_RCVD	=	0x400,
1397bd3a2e2SSriharsha Basavapatna 	DRING_ACK_SENT	=	0x800,
1407bd3a2e2SSriharsha Basavapatna 	DRING_INFO_EXCHANGED	=	(DRING_ACK_RCVD | DRING_ACK_SENT),
1417bd3a2e2SSriharsha Basavapatna 
1427bd3a2e2SSriharsha Basavapatna 	RDX_INFO_SENT	=	0x1000,
1437bd3a2e2SSriharsha Basavapatna 	RDX_ACK_RCVD	=	0x2000,
1447bd3a2e2SSriharsha Basavapatna 	RDX_INFO_RCVD	=	0x4000,
1457bd3a2e2SSriharsha Basavapatna 	RDX_ACK_SENT	=	0x8000,
1467bd3a2e2SSriharsha Basavapatna 	RDX_EXCHANGED	=	(RDX_ACK_RCVD | RDX_ACK_SENT)
1477bd3a2e2SSriharsha Basavapatna 
1487bd3a2e2SSriharsha Basavapatna };
1497bd3a2e2SSriharsha Basavapatna 
1507bd3a2e2SSriharsha Basavapatna /* reset flags */
1517bd3a2e2SSriharsha Basavapatna typedef enum {
1527bd3a2e2SSriharsha Basavapatna 	VGEN_FLAG_EVT_RESET = 0x1,	/* channel reset event */
1537bd3a2e2SSriharsha Basavapatna 	VGEN_FLAG_NEED_LDCRESET = 0x2,	/* need channel reset */
1547bd3a2e2SSriharsha Basavapatna 	VGEN_FLAG_UNINIT = 0x4		/* channel tear down */
1557bd3a2e2SSriharsha Basavapatna } vgen_reset_flags_t;
1567bd3a2e2SSriharsha Basavapatna 
1577bd3a2e2SSriharsha Basavapatna /* caller information needed in some code paths */
1587bd3a2e2SSriharsha Basavapatna typedef enum {
1597bd3a2e2SSriharsha Basavapatna 	VGEN_LDC_CB = 0x1,	/* ldc callback handler */
1607bd3a2e2SSriharsha Basavapatna 	VGEN_MSG_THR = 0x2,	/* vio message worker thread */
1617bd3a2e2SSriharsha Basavapatna 	VGEN_OTHER = 0x4	/* other threads - tx etc */
1627bd3a2e2SSriharsha Basavapatna } vgen_caller_t;
1637bd3a2e2SSriharsha Basavapatna 
1641ae08745Sheppo /* get the address of next tbuf */
1651ae08745Sheppo #define	NEXTTBUF(ldcp, tbufp)	(((tbufp) + 1) == (ldcp)->tbufendp    \
1661ae08745Sheppo 		? (ldcp)->tbufp : ((tbufp) + 1))
1671ae08745Sheppo 
1681ae08745Sheppo /* increment recv index */
1691ae08745Sheppo #define	INCR_RXI(i, ldcp)	\
1701ae08745Sheppo 		((i) = (((i) + 1) & ((ldcp)->num_rxds - 1)))
1711ae08745Sheppo 
1721ae08745Sheppo /* decrement recv index */
1731ae08745Sheppo #define	DECR_RXI(i, ldcp)	\
1741ae08745Sheppo 		((i) = (((i) - 1) & ((ldcp)->num_rxds - 1)))
1751ae08745Sheppo 
1761ae08745Sheppo /* increment tx index */
1771ae08745Sheppo #define	INCR_TXI(i, ldcp)	\
1781ae08745Sheppo 		((i) = (((i) + 1) & ((ldcp)->num_txds - 1)))
1791ae08745Sheppo 
1801ae08745Sheppo /* decrement tx index */
1811ae08745Sheppo #define	DECR_TXI(i, ldcp)	\
1821ae08745Sheppo 		((i) = (((i) - 1) & ((ldcp)->num_txds - 1)))
1831ae08745Sheppo 
1841ae08745Sheppo /* bounds check rx index */
1851ae08745Sheppo #define	CHECK_RXI(i, ldcp)	\
1861ae08745Sheppo 		(((i) >= 0) && ((i) < (ldcp)->num_rxds))
1871ae08745Sheppo 
1881ae08745Sheppo /* bounds check tx index */
1891ae08745Sheppo #define	CHECK_TXI(i, ldcp)	\
1901ae08745Sheppo 		(((i) >= 0) && ((i) < (ldcp)->num_txds))
1911ae08745Sheppo 
1927bd3a2e2SSriharsha Basavapatna #ifdef DEBUG
1937bd3a2e2SSriharsha Basavapatna 
1947bd3a2e2SSriharsha Basavapatna /* Error injection codes */
1957bd3a2e2SSriharsha Basavapatna #define	VGEN_ERR_HVER		0x1	/* handshake version */
1967bd3a2e2SSriharsha Basavapatna #define	VGEN_ERR_HTIMEOUT	0x2	/* handshake timeout */
1977bd3a2e2SSriharsha Basavapatna #define	VGEN_ERR_HSID		0x4	/* handshake session id */
1987bd3a2e2SSriharsha Basavapatna #define	VGEN_ERR_HSTATE		0x8	/* handshake state */
1997bd3a2e2SSriharsha Basavapatna #define	VGEN_ERR_TXTIMEOUT	0x10	/* tx timeout */
2007bd3a2e2SSriharsha Basavapatna #define	VGEN_ERR_RXLOST		0x20	/* rx lost pkts */
2017bd3a2e2SSriharsha Basavapatna 
2027bd3a2e2SSriharsha Basavapatna #endif
2031ae08745Sheppo /* private descriptor */
2041ae08745Sheppo typedef struct vgen_priv_desc {
2051ae08745Sheppo 	uint64_t		flags;		/* flag bits */
2061ae08745Sheppo 	vnet_public_desc_t	*descp;		/* associated public desc */
2071ae08745Sheppo 	ldc_mem_handle_t	memhandle;	/* mem handle for data */
2088e6a2a04Slm66018 	caddr_t			datap;		/* prealloc'd tx data buffer */
2091ae08745Sheppo 	uint64_t		datalen;	/* total actual datalen */
2101ae08745Sheppo 	uint64_t		ncookies;	/* num ldc_mem_cookies */
2111ae08745Sheppo 	ldc_mem_cookie_t	memcookie[MAX_COOKIES];	/* data cookies */
2121ae08745Sheppo } vgen_private_desc_t;
2131ae08745Sheppo 
2141ae08745Sheppo /*
2151ae08745Sheppo  * Handshake parameters (per vio_mailbox.h) of each ldc end point, used
2161ae08745Sheppo  * during handshake negotiation.
2171ae08745Sheppo  */
2181ae08745Sheppo typedef struct vgen_handshake_params {
2191ae08745Sheppo 	/* version specific params */
220f2b610cfSwentaoy 	uint16_t	ver_major;		/* major version number */
221f2b610cfSwentaoy 	uint16_t	ver_minor;		/* minor version number */
2221ae08745Sheppo 	uint8_t		dev_class;		/* device class */
2231ae08745Sheppo 
2241ae08745Sheppo 	/* attributes specific params */
2251ae08745Sheppo 	uint64_t		mtu;		/* max transfer unit size */
2261ae08745Sheppo 	uint64_t		addr;		/* address of the device */
2271ae08745Sheppo 	uint8_t			addr_type;	/* type of address */
2281ae08745Sheppo 	uint8_t			xfer_mode;	/* SHM or PKT */
2291ae08745Sheppo 	uint16_t		ack_freq;	/* dring data ack freq */
2301107ea93SSriharsha Basavapatna 	uint32_t		physlink_update; /* physlink updates */
2317bd3a2e2SSriharsha Basavapatna 	uint8_t			dring_mode;	/* Descriptor ring mode */
2321ae08745Sheppo 
2331ae08745Sheppo 	/* descriptor ring params */
2341ae08745Sheppo 	uint32_t		num_desc;	/* # of descriptors in ring */
2351ae08745Sheppo 	uint32_t		desc_size;	/* size of descriptor */
2361ae08745Sheppo 	ldc_mem_cookie_t	dring_cookie;	/* desc ring cookie */
2377bd3a2e2SSriharsha Basavapatna 	uint32_t		dring_ncookies;	/* # of dring cookies */
2381ae08745Sheppo 	uint64_t		dring_ident;	/* ident=0 for INFO msg */
2391ae08745Sheppo 	boolean_t		dring_ready;	/* dring ready flag */
2401ae08745Sheppo } vgen_hparams_t;
2411ae08745Sheppo 
2421ae08745Sheppo /* version info */
2431ae08745Sheppo typedef struct vgen_ver {
244f2b610cfSwentaoy 	uint16_t	ver_major;		/* major version number */
245f2b610cfSwentaoy 	uint16_t	ver_minor;		/* minor version number */
2461ae08745Sheppo } vgen_ver_t;
2471ae08745Sheppo 
248f0ca1d9aSsb155480 /*
249f0ca1d9aSsb155480  * vnet-protocol-version dependent function prototypes.
250f0ca1d9aSsb155480  */
251f0ca1d9aSsb155480 typedef int	(*vgen_ldctx_t) (void *, mblk_t *);
252f0ca1d9aSsb155480 typedef void	(*vgen_ldcrx_pktdata_t) (void *, void *, uint32_t);
2537bd3a2e2SSriharsha Basavapatna typedef int	(*vgen_ldcrx_dringdata_t) (void *, void *);
254f0ca1d9aSsb155480 
2557bd3a2e2SSriharsha Basavapatna /*
2567bd3a2e2SSriharsha Basavapatna  * LDC end point abstraction in vnet. This structure holds all the information
2577bd3a2e2SSriharsha Basavapatna  * that is required to configure and use the Channel for data transfers with
2587bd3a2e2SSriharsha Basavapatna  * the peer LDC end point (vnet or vswitch), using VIO Protocol.
2597bd3a2e2SSriharsha Basavapatna  */
2601ae08745Sheppo typedef struct vgen_ldc {
2611ae08745Sheppo 
2621ae08745Sheppo 	struct vgen_port	*portp;		/* associated port */
2631ae08745Sheppo 
2641ae08745Sheppo 	/*
2651ae08745Sheppo 	 * Locks:
2661ae08745Sheppo 	 * locking hierarchy when more than one lock is held concurrently:
267844e62a3Sraghuram 	 * cblock > rxlock > txlock > tclock.
2681ae08745Sheppo 	 */
2691ae08745Sheppo 	kmutex_t		cblock;		/* sync callback processing */
270844e62a3Sraghuram 	kmutex_t		txlock;		/* protect txd alloc */
2711ae08745Sheppo 	kmutex_t		tclock;		/* tx reclaim lock */
272844e62a3Sraghuram 	kmutex_t		wrlock;		/* sync transmits */
273844e62a3Sraghuram 	kmutex_t		rxlock;		/* sync reception */
27463f531d1SSriharsha Basavapatna 	kmutex_t		pollq_lock;	/* sync polling and rxworker */
2751ae08745Sheppo 
2767bd3a2e2SSriharsha Basavapatna 	/*
2777bd3a2e2SSriharsha Basavapatna 	 * Channel and Handshake Info
2787bd3a2e2SSriharsha Basavapatna 	 */
2791ae08745Sheppo 	uint64_t		ldc_id;		/* channel number */
2801ae08745Sheppo 	uint64_t		ldc_handle;	/* channel handle */
2811ae08745Sheppo 	ldc_status_t		ldc_status;	/* channel status */
2821ae08745Sheppo 	vgen_ver_t		vgen_versions[VGEN_NUM_VER]; /* versions */
2831ae08745Sheppo 	int			hphase;		/* handshake phase */
2841ae08745Sheppo 	int			hstate;		/* handshake state bits */
2851107ea93SSriharsha Basavapatna 	link_state_t		link_state;	/* channel link state */
2861107ea93SSriharsha Basavapatna #ifdef	VNET_IOC_DEBUG
2871107ea93SSriharsha Basavapatna 	boolean_t		link_down_forced; /* forced link down */
2881107ea93SSriharsha Basavapatna #endif
2891ae08745Sheppo 	uint32_t		local_sid;	/* local session id */
2901ae08745Sheppo 	uint32_t		peer_sid;	/* session id of peer */
2911ae08745Sheppo 	vgen_hparams_t		local_hparams;	/* local handshake params */
2921ae08745Sheppo 	vgen_hparams_t		peer_hparams;	/* peer's handshake params */
2931ae08745Sheppo 	timeout_id_t		htid;		/* handshake wd timeout id */
294bd8f0338Snarayan 	timeout_id_t		cancel_htid;	/* cancel handshake watchdog */
295bbfa0259Sha137994 	uint8_t			dring_mtype;	/* dring mem map type */
296f0ca1d9aSsb155480 	uint64_t		*ldcmsg;	/* msg buffer for ldc_read() */
297f0ca1d9aSsb155480 	uint64_t		msglen;		/* size of ldcmsg */
2981ae08745Sheppo 	uint32_t		flags;		/* flags */
2997bd3a2e2SSriharsha Basavapatna 	uint_t			reset_in_progress; /* channel being reset */
3001ae08745Sheppo 	uint32_t		hretries;	/* handshake retry count */
3017bd3a2e2SSriharsha Basavapatna 	uint32_t		ldc_reset_count; /* # of channel resets */
302844e62a3Sraghuram 
3037bd3a2e2SSriharsha Basavapatna 	/*
3047bd3a2e2SSriharsha Basavapatna 	 * Transmit Specific Fields
3057bd3a2e2SSriharsha Basavapatna 	 */
3067bd3a2e2SSriharsha Basavapatna 	/* TX-Common (Used in both TxDring and RxDringData modes) */
3077bd3a2e2SSriharsha Basavapatna 	uint32_t		num_txds;	   /* # of descriptors */
3087bd3a2e2SSriharsha Basavapatna 	uint32_t		tx_dring_ncookies; /* # of dring cookies */
3097bd3a2e2SSriharsha Basavapatna 	ldc_dring_handle_t	tx_dring_handle;   /* dring handle */
3107bd3a2e2SSriharsha Basavapatna 	ldc_mem_cookie_t	tx_dring_cookie;   /* dring cookie */
3117bd3a2e2SSriharsha Basavapatna 	uint32_t		next_txi;	   /* free descriptor index */
3127bd3a2e2SSriharsha Basavapatna 	caddr_t			tx_datap;	   /* tx data area */
3137bd3a2e2SSriharsha Basavapatna 	size_t			tx_data_sz;	   /* size of data area */
3147bd3a2e2SSriharsha Basavapatna 	size_t			tx_dblk_sz;	   /* size of data blk */
3157bd3a2e2SSriharsha Basavapatna 	timeout_id_t		wd_tid;		   /* watchdog timeout id */
3167bd3a2e2SSriharsha Basavapatna 	boolean_t		tx_blocked;	   /* flow controlled */
3177bd3a2e2SSriharsha Basavapatna 	clock_t			tx_blocked_lbolt;  /* flow controlled time */
3187bd3a2e2SSriharsha Basavapatna 	boolean_t		resched_peer;	   /* restart peer needed */
3197bd3a2e2SSriharsha Basavapatna 	uint32_t		resched_peer_txi;  /* index to resched peer */
320f0ca1d9aSsb155480 	vgen_ldctx_t		tx;		   /* transmit function */
3217bd3a2e2SSriharsha Basavapatna 	vgen_ldctx_t		tx_dringdata;	   /* dring transmit function */
322f0ca1d9aSsb155480 
3237bd3a2e2SSriharsha Basavapatna 	/* TX-TxDring mode */
3247bd3a2e2SSriharsha Basavapatna 	vnet_public_desc_t	*txdp;		/* exported dring */
3257bd3a2e2SSriharsha Basavapatna 	vgen_private_desc_t	*tbufp;		/* dring associated resources */
3267bd3a2e2SSriharsha Basavapatna 	vgen_private_desc_t	*tbufendp;	/* tbuf ring end */
3277bd3a2e2SSriharsha Basavapatna 	vgen_private_desc_t	*next_tbufp;	/* free tbuf */
3287bd3a2e2SSriharsha Basavapatna 	vgen_private_desc_t	*cur_tbufp;	/* reclaim tbuf */
3297bd3a2e2SSriharsha Basavapatna 	uint32_t		cur_txi;	/* reclaim descrptor index */
3307bd3a2e2SSriharsha Basavapatna 	uint64_t		next_txseq;	/* msg seqnum */
3317bd3a2e2SSriharsha Basavapatna 	clock_t			reclaim_lbolt;	/* time of last reclaim */
3321ae08745Sheppo 
3337bd3a2e2SSriharsha Basavapatna 	/* TX-RxDringData mode */
3347bd3a2e2SSriharsha Basavapatna 	uint32_t		tx_data_ncookies; /* # of data cookies */
3357bd3a2e2SSriharsha Basavapatna 	ldc_mem_handle_t	tx_data_handle;	  /* mapped data handle */
3367bd3a2e2SSriharsha Basavapatna 	ldc_mem_cookie_t	*tx_data_cookie;  /* mapped data cookies */
3377bd3a2e2SSriharsha Basavapatna 	vnet_rx_dringdata_desc_t *mtxdp;	  /* mapped dring */
3387bd3a2e2SSriharsha Basavapatna 	uint32_t		dringdata_msgid;  /* msg id */
3397bd3a2e2SSriharsha Basavapatna 
3407bd3a2e2SSriharsha Basavapatna 	/*
3417bd3a2e2SSriharsha Basavapatna 	 * Receive Specific Fields
3427bd3a2e2SSriharsha Basavapatna 	 */
3437bd3a2e2SSriharsha Basavapatna 	/* RX-Common (Used in both TxDring and RxDringData modes) */
3447bd3a2e2SSriharsha Basavapatna 	uint32_t		num_rxds;	   /* # of descriptors */
3457bd3a2e2SSriharsha Basavapatna 	uint32_t		rx_dring_ncookies; /* # of dring cookies */
3467bd3a2e2SSriharsha Basavapatna 	ldc_dring_handle_t	rx_dring_handle;   /* dring handle */
3477bd3a2e2SSriharsha Basavapatna 	ldc_mem_cookie_t	rx_dring_cookie;   /* dring cookie */
3487bd3a2e2SSriharsha Basavapatna 	uint32_t		next_rxi;	   /* free descriptor index */
3497bd3a2e2SSriharsha Basavapatna 	vgen_ldcrx_dringdata_t	rx_dringdata;	   /* dring rcv function */
3507bd3a2e2SSriharsha Basavapatna 	vgen_ldcrx_pktdata_t	rx_pktdata;	   /* raw data rcv function */
35163f531d1SSriharsha Basavapatna 	boolean_t		polling_on;	   /* polling enabled ? */
3527bd3a2e2SSriharsha Basavapatna 
3537bd3a2e2SSriharsha Basavapatna 	/* RX-TxDring mode */
3547bd3a2e2SSriharsha Basavapatna 	vnet_public_desc_t	*mrxdp;		 /* mapped dring */
3557bd3a2e2SSriharsha Basavapatna 	uint64_t		next_rxseq;	 /* msg seqnum */
3567bd3a2e2SSriharsha Basavapatna 	vio_multi_pool_t	vmp;		 /* mblk pools */
3577bd3a2e2SSriharsha Basavapatna 	uint32_t		max_rxpool_size; /* max size of rxpool in use */
35863f531d1SSriharsha Basavapatna 	mblk_t			*pollq_headp;	 /* head of pkts in pollq */
35963f531d1SSriharsha Basavapatna 	mblk_t			*pollq_tailp;	 /* tail of pkts in pollq */
3607bd3a2e2SSriharsha Basavapatna 	kthread_t		*msg_thread;	 /* message thread */
3617bd3a2e2SSriharsha Basavapatna 	uint32_t		msg_thr_flags;	 /* message thread flags */
3627bd3a2e2SSriharsha Basavapatna 	kmutex_t		msg_thr_lock;	 /* lock for message thread */
3637bd3a2e2SSriharsha Basavapatna 	kcondvar_t		msg_thr_cv;	 /* cond.var for msg thread */
36463f531d1SSriharsha Basavapatna 
3657bd3a2e2SSriharsha Basavapatna 	/* RX-RxDringData mode */
3667bd3a2e2SSriharsha Basavapatna 	uint32_t		num_rbufs;	  /* # of data bufs */
3677bd3a2e2SSriharsha Basavapatna 	uint32_t		rx_data_ncookies; /* # of data cookies */
3687bd3a2e2SSriharsha Basavapatna 	ldc_mem_handle_t	rx_data_handle;	  /* exported data handle */
3697bd3a2e2SSriharsha Basavapatna 	ldc_mem_cookie_t	*rx_data_cookie;  /* exported data cookies */
3707bd3a2e2SSriharsha Basavapatna 	vnet_rx_dringdata_desc_t *rxdp;		  /* exported dring */
3717bd3a2e2SSriharsha Basavapatna 	vio_mblk_pool_t		*rx_vmp;	  /* mblk pool */
3727bd3a2e2SSriharsha Basavapatna 	vio_mblk_t		**rxdp_to_vmp;	  /* descr to buf map tbl */
3737bd3a2e2SSriharsha Basavapatna 	caddr_t			rx_datap;	  /* mapped rx data area */
3747bd3a2e2SSriharsha Basavapatna 	size_t			rx_data_sz;	  /* size of mapped rx data */
3757bd3a2e2SSriharsha Basavapatna 	size_t			rx_dblk_sz;	  /* size of each rx data blk */
3767bd3a2e2SSriharsha Basavapatna 	mblk_t			*rx_pri_head;	  /* priority pkts head */
3777bd3a2e2SSriharsha Basavapatna 	mblk_t			*rx_pri_tail;	  /* priority pkts tail */
3787bd3a2e2SSriharsha Basavapatna 
3797bd3a2e2SSriharsha Basavapatna 	/* Channel Statistics */
38006db247cSraghuram 	vgen_stats_t		stats;		/* channel statistics */
3811ae08745Sheppo 	kstat_t			*ksp;		/* channel kstats */
3821ae08745Sheppo } vgen_ldc_t;
3831ae08745Sheppo 
3841ae08745Sheppo /* port information  structure */
3851ae08745Sheppo typedef struct vgen_port {
3861ae08745Sheppo 	struct vgen_port	*nextp;		/* next port in the list */
3871ae08745Sheppo 	struct vgen		*vgenp;		/* associated vgen_t */
3881ae08745Sheppo 	int			port_num;	/* port number */
3891107ea93SSriharsha Basavapatna 	boolean_t		is_vsw_port;	/* connected to vswitch ? */
390c1c61f44Ssb155480 	int			num_ldcs;	/* # of channels in this port */
391c1c61f44Ssb155480 	uint64_t		*ldc_ids;	/* channel ids */
3927bd3a2e2SSriharsha Basavapatna 	vgen_ldc_t		*ldcp;		/* list of ldcs for this port */
393678453a8Sspeer 	ether_addr_t		macaddr;	/* mac address of peer */
394c1c61f44Ssb155480 	uint16_t		pvid;		/* port vlan id (untagged) */
395c1c61f44Ssb155480 	uint16_t		*vids;		/* vlan ids (tagged) */
396c1c61f44Ssb155480 	uint16_t		nvids;		/* # of vids */
397c1c61f44Ssb155480 	mod_hash_t		*vlan_hashp;	/* vlan hash table */
398c1c61f44Ssb155480 	uint32_t		vlan_nchains;	/* # of vlan hash chains */
399678453a8Sspeer 	uint32_t		use_vsw_port;	/* Use vsw_port or not */
400678453a8Sspeer 	uint32_t		flags;		/* status of this port */
401678453a8Sspeer 	vio_net_callbacks_t	vcb;		/* vnet callbacks */
402678453a8Sspeer 	vio_net_handle_t	vhp;		/* handle from vnet */
403678453a8Sspeer 	kmutex_t		lock;		/* synchornize ops */
4041ae08745Sheppo } vgen_port_t;
4051ae08745Sheppo 
4061ae08745Sheppo /* port list structure */
4071ae08745Sheppo typedef struct vgen_portlist {
4081ae08745Sheppo 	vgen_port_t	*headp;		/* head of ports */
4091ae08745Sheppo 	vgen_port_t	*tailp;		/* tail */
4101ae08745Sheppo 	krwlock_t	rwlock;		/* sync access to the port list */
4111ae08745Sheppo } vgen_portlist_t;
4121ae08745Sheppo 
4131ae08745Sheppo /* vgen instance information  */
4141ae08745Sheppo typedef struct vgen {
415c1c61f44Ssb155480 	vnet_t			*vnetp;		/* associated vnet instance */
416678453a8Sspeer 	int			instance;	/* vnet instance */
4171ae08745Sheppo 	dev_info_t		*vnetdip;	/* dip of vnet */
418f0ca1d9aSsb155480 	uint64_t		regprop;	/* "reg" property */
419678453a8Sspeer 	ether_addr_t		macaddr;	/* mac addr of vnet */
4201ae08745Sheppo 	kmutex_t		lock;		/* synchornize ops */
4211ae08745Sheppo 	int			flags;		/* flags */
4221ae08745Sheppo 	vgen_portlist_t		vgenports;	/* Port List */
4231ae08745Sheppo 	mdeg_node_spec_t	*mdeg_parentp;
424c1c61f44Ssb155480 	mdeg_handle_t		mdeg_dev_hdl;	/* mdeg cb handle for device */
425c1c61f44Ssb155480 	mdeg_handle_t		mdeg_port_hdl;	/* mdeg cb handle for port */
4261ae08745Sheppo 	vgen_port_t		*vsw_portp;	/* port connected to vsw */
4271ae08745Sheppo 	struct ether_addr	*mctab;		/* multicast addr table */
4281ae08745Sheppo 	uint32_t		mcsize;		/* allocated size of mctab */
4291ae08745Sheppo 	uint32_t		mccount;	/* # of valid addrs in mctab */
4307bd3a2e2SSriharsha Basavapatna 	ddi_taskq_t		*rxp_taskq;	/* VIO rx pool taskq */
431f0ca1d9aSsb155480 	uint32_t		pri_num_types;	/* # of priority eth types */
432f0ca1d9aSsb155480 	uint16_t		*pri_types;	/* priority eth types */
433f0ca1d9aSsb155480 	vio_mblk_pool_t		*pri_tx_vmp;	/* tx priority mblk pool */
434c1c61f44Ssb155480 	uint32_t		max_frame_size;	/* max frame size supported */
435678453a8Sspeer 
436678453a8Sspeer 	uint32_t		vsw_port_refcnt; /* refcnt for vsw_port */
4371107ea93SSriharsha Basavapatna 	boolean_t		pls_negotiated;	/* phys link state update ? */
4381107ea93SSriharsha Basavapatna 	link_state_t		phys_link_state; /* physical link state */
4391ae08745Sheppo } vgen_t;
4401ae08745Sheppo 
4411ae08745Sheppo #ifdef __cplusplus
4421ae08745Sheppo }
4431ae08745Sheppo #endif
4441ae08745Sheppo 
4451ae08745Sheppo #endif	/* _VNET_GEN_H */
446