xref: /illumos-gate/usr/src/uts/sun4v/sys/vnet_common.h (revision 6a634c9d)
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_COMMON_H
271ae08745Sheppo #define	_VNET_COMMON_H
281ae08745Sheppo 
291ae08745Sheppo #ifdef __cplusplus
301ae08745Sheppo extern "C" {
311ae08745Sheppo #endif
321ae08745Sheppo 
331ae08745Sheppo #include <sys/vio_common.h>
341ae08745Sheppo #include <sys/vio_mailbox.h>
351ae08745Sheppo #include <sys/ethernet.h>
361ae08745Sheppo 
371ae08745Sheppo /*
381ae08745Sheppo  * This header file contains definitions common to LDoms Virtual Network
391ae08745Sheppo  * server (vsw) and client (vnet).
401ae08745Sheppo  */
411ae08745Sheppo 
427bd3a2e2SSriharsha Basavapatna /* max # of cookies per frame size in TxDring mode */
43d10e4ef2Snarayan #define	MAX_COOKIES	 ((ETHERMAX >> MMU_PAGESHIFT) + 2ULL)
441ae08745Sheppo 
457bd3a2e2SSriharsha Basavapatna /*
467bd3a2e2SSriharsha Basavapatna  * Max # of data area cookies that we support in RxDringData mode. This is
477bd3a2e2SSriharsha Basavapatna  * pre-defined to avoid allocating and importing a large # of cookies for the
487bd3a2e2SSriharsha Basavapatna  * data area. We know that the export map table on the exporting end point is
497bd3a2e2SSriharsha Basavapatna  * per LDC. We also know that a single cookie can be obtained if we manage
507bd3a2e2SSriharsha Basavapatna  * to get consecutive entries in the export map table. We use this knowledge to
517bd3a2e2SSriharsha Basavapatna  * limit the # of cookies to a pre-defined maximum value.
527bd3a2e2SSriharsha Basavapatna  */
537bd3a2e2SSriharsha Basavapatna #define	VNET_DATA_AREA_COOKIES	32
547bd3a2e2SSriharsha Basavapatna 
557bd3a2e2SSriharsha Basavapatna /*
567bd3a2e2SSriharsha Basavapatna  * Size of dring reg msg in RxDringData mode, given # of data area cookies.
577bd3a2e2SSriharsha Basavapatna  * This assumes that the # of dring cookies in vio_dring_reg_msg_t is 1.
587bd3a2e2SSriharsha Basavapatna  * The given # of data area cookies is reduced by 1, as vio_dring_reg_msg_ext_t
597bd3a2e2SSriharsha Basavapatna  * itself contains 1 data cookie.
607bd3a2e2SSriharsha Basavapatna  */
617bd3a2e2SSriharsha Basavapatna #define	VNET_DRING_REG_EXT_MSG_SIZE(data_ncookies)		\
627bd3a2e2SSriharsha Basavapatna 	(sizeof (vio_dring_reg_msg_t) + sizeof (vio_dring_reg_ext_msg_t) + \
637bd3a2e2SSriharsha Basavapatna 	(((data_ncookies) - 1) * sizeof (ldc_mem_cookie_t)))
647bd3a2e2SSriharsha Basavapatna 
657bd3a2e2SSriharsha Basavapatna /* Max supported size of dring reg msg in RxDringData mode */
667bd3a2e2SSriharsha Basavapatna #define	VNET_DRING_REG_EXT_MSG_SIZE_MAX				\
677bd3a2e2SSriharsha Basavapatna 	VNET_DRING_REG_EXT_MSG_SIZE(VNET_DATA_AREA_COOKIES)
687bd3a2e2SSriharsha Basavapatna 
691ae08745Sheppo /* initial send sequence number */
701ae08745Sheppo #define	VNET_ISS		0x1
711ae08745Sheppo 
727bd3a2e2SSriharsha Basavapatna #define	VNET_START_IDX_UNSPEC	0xFFFFFFFF /* ignore st_idx in dringdata ack */
737bd3a2e2SSriharsha Basavapatna 
74c1c61f44Ssb #define	VNET_2K			(1 << 11)
757b1f684aSSriharsha Basavapatna #define	VNET_4K			(1 << 12)
767b1f684aSSriharsha Basavapatna #define	VNET_8K			(1 << 13)
777b1f684aSSriharsha Basavapatna #define	VNET_12K		((VNET_8K) + (VNET_4K))
78d10e4ef2Snarayan #define	VNET_IPALIGN		6	/* padding for IP header alignment */
79c1c61f44Ssb #define	VNET_LDCALIGN		8	/* padding for ldc_mem_copy() align */
80c1c61f44Ssb #define	VNET_ROUNDUP_2K(n)	(((n) + (VNET_2K - 1)) & ~(VNET_2K - 1))
817b1f684aSSriharsha Basavapatna #define	VNET_ROUNDUP_4K(n)	(((n) + (VNET_4K - 1)) & ~(VNET_4K - 1))
827b1f684aSSriharsha Basavapatna #define	VNET_ROUNDUP_8K(n)	(((n) + (VNET_8K - 1)) & ~(VNET_8K - 1))
837b1f684aSSriharsha Basavapatna 
847bd3a2e2SSriharsha Basavapatna #define	MEMBAR_CONSUMER		membar_consumer
857bd3a2e2SSriharsha Basavapatna #define	MEMBAR_PRODUCER		membar_producer
867bd3a2e2SSriharsha Basavapatna 
877b1f684aSSriharsha Basavapatna /*
887b1f684aSSriharsha Basavapatna  * Maximum MTU value currently supported. MAX_COOKIES for data has been defined
897b1f684aSSriharsha Basavapatna  * already based on ETHERMAX. Hence we limit the MTU to be within 2 8K pages
907b1f684aSSriharsha Basavapatna  * and take some additional steps (see related code in .c files) to ensure that
917b1f684aSSriharsha Basavapatna  * ldc cookies for each data buffer is within the MAX_COOKIES. This allows us
927b1f684aSSriharsha Basavapatna  * to support Jumbo MTUs without changing the size of the descriptor.
937b1f684aSSriharsha Basavapatna  */
947b1f684aSSriharsha Basavapatna #define	VNET_MAX_MTU		16000
95d10e4ef2Snarayan 
9619b65a69Ssb #define	VNET_NUM_HANDSHAKES	6	/* # of handshake attempts */
97445b4c2eSsb 
98*34f94fbcSWENTAO YANG /*
99*34f94fbcSWENTAO YANG  * Max frame size to data block size in RxDringData mode
100*34f94fbcSWENTAO YANG  */
101*34f94fbcSWENTAO YANG #define	RXDRING_DBLK_SZ(mfs) \
102*34f94fbcSWENTAO YANG 	(VNET_ROUNDUP_2K((mfs) + VNET_IPALIGN + VNET_LDCALIGN))
103*34f94fbcSWENTAO YANG 
1041ae08745Sheppo /* vnet descriptor */
1051ae08745Sheppo typedef struct vnet_public_desc {
1061ae08745Sheppo 	vio_dring_entry_hdr_t	hdr;		/* descriptor header */
1071ae08745Sheppo 	uint32_t		nbytes;		/* data length */
1081ae08745Sheppo 	uint32_t		ncookies;	/* number of data cookies */
1091ae08745Sheppo 	ldc_mem_cookie_t	memcookie[MAX_COOKIES]; /* data cookies */
1101ae08745Sheppo } vnet_public_desc_t;
1111ae08745Sheppo 
1121ae08745Sheppo /*
113445b4c2eSsb  * Vnet in-band descriptor. Used by those vnet clients
1141ae08745Sheppo  * such as OBP who do not use descriptor rings.
1151ae08745Sheppo  */
116445b4c2eSsb typedef struct vnet_ibnd_desc {
1171ae08745Sheppo 	vio_inband_desc_msg_hdr_t	hdr;
1181ae08745Sheppo 
1191ae08745Sheppo 	/* payload */
1201ae08745Sheppo 	uint32_t			nbytes;
1211ae08745Sheppo 	uint32_t			ncookies;
1221ae08745Sheppo 	ldc_mem_cookie_t		memcookie[MAX_COOKIES];
123445b4c2eSsb } vnet_ibnd_desc_t;
1241ae08745Sheppo 
1257bd3a2e2SSriharsha Basavapatna /*
1267bd3a2e2SSriharsha Basavapatna  * Descriptor format in RxDringData mode.
1277bd3a2e2SSriharsha Basavapatna  */
1287bd3a2e2SSriharsha Basavapatna typedef struct vnet_rxdring_data_desc {
1297bd3a2e2SSriharsha Basavapatna 	uint8_t		dstate;			/* Descriptor state */
1307bd3a2e2SSriharsha Basavapatna 	uint8_t		resv1[3];		/* Reserved */
1317bd3a2e2SSriharsha Basavapatna 	uint32_t	nbytes;			/* Num bytes in data buffer */
1327bd3a2e2SSriharsha Basavapatna 	uint64_t	data_buf_offset;	/* Offset of data buffer */
1337bd3a2e2SSriharsha Basavapatna } vnet_rx_dringdata_desc_t;
1347bd3a2e2SSriharsha Basavapatna 
135f2b610cfSwentaoy /* exported functions */
136f2b610cfSwentaoy uint64_t vnet_macaddr_strtoul(const uint8_t *macaddr);
137f2b610cfSwentaoy void vnet_macaddr_ultostr(uint64_t value, uint8_t *macaddr);
138c1c61f44Ssb mblk_t *vnet_vlan_insert_tag(mblk_t *mp, uint16_t vid);
139c1c61f44Ssb mblk_t *vnet_vlan_remove_tag(mblk_t *mp);
140bbfa0259Sha int vnet_dring_entry_copy(vnet_public_desc_t *dst, vnet_public_desc_t *src,
141bbfa0259Sha     uint8_t mtype, ldc_dring_handle_t handle, uint64_t start, uint64_t stop);
142bbfa0259Sha int vnet_dring_entry_set_dstate(vnet_public_desc_t *descp, uint8_t mtype,
143bbfa0259Sha     ldc_dring_handle_t handle, uint64_t start, uint64_t stop, uint8_t dstate);
144f2b610cfSwentaoy 
1451ae08745Sheppo #ifdef __cplusplus
1461ae08745Sheppo }
1471ae08745Sheppo #endif
1481ae08745Sheppo 
1491ae08745Sheppo #endif	/* _VNET_COMMON_H */
150