11991Sheppo /* 21991Sheppo * CDDL HEADER START 31991Sheppo * 41991Sheppo * The contents of this file are subject to the terms of the 51991Sheppo * Common Development and Distribution License (the "License"). 61991Sheppo * You may not use this file except in compliance with the License. 71991Sheppo * 81991Sheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91991Sheppo * or http://www.opensolaris.org/os/licensing. 101991Sheppo * See the License for the specific language governing permissions 111991Sheppo * and limitations under the License. 121991Sheppo * 131991Sheppo * When distributing Covered Code, include this CDDL HEADER in each 141991Sheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151991Sheppo * If applicable, add the following below this CDDL HEADER, with the 161991Sheppo * fields enclosed by brackets "[]" replaced with your own identifying 171991Sheppo * information: Portions Copyright [yyyy] [name of copyright owner] 181991Sheppo * 191991Sheppo * CDDL HEADER END 201991Sheppo */ 211991Sheppo 221991Sheppo /* 23*13098SWentao.Yang@Sun.COM * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. 241991Sheppo */ 251991Sheppo 261991Sheppo #ifndef _VNET_COMMON_H 271991Sheppo #define _VNET_COMMON_H 281991Sheppo 291991Sheppo #ifdef __cplusplus 301991Sheppo extern "C" { 311991Sheppo #endif 321991Sheppo 331991Sheppo #include <sys/vio_common.h> 341991Sheppo #include <sys/vio_mailbox.h> 351991Sheppo #include <sys/ethernet.h> 361991Sheppo 371991Sheppo /* 381991Sheppo * This header file contains definitions common to LDoms Virtual Network 391991Sheppo * server (vsw) and client (vnet). 401991Sheppo */ 411991Sheppo 4212011SSriharsha.Basavapatna@Sun.COM /* max # of cookies per frame size in TxDring mode */ 432336Snarayan #define MAX_COOKIES ((ETHERMAX >> MMU_PAGESHIFT) + 2ULL) 441991Sheppo 4512011SSriharsha.Basavapatna@Sun.COM /* 4612011SSriharsha.Basavapatna@Sun.COM * Max # of data area cookies that we support in RxDringData mode. This is 4712011SSriharsha.Basavapatna@Sun.COM * pre-defined to avoid allocating and importing a large # of cookies for the 4812011SSriharsha.Basavapatna@Sun.COM * data area. We know that the export map table on the exporting end point is 4912011SSriharsha.Basavapatna@Sun.COM * per LDC. We also know that a single cookie can be obtained if we manage 5012011SSriharsha.Basavapatna@Sun.COM * to get consecutive entries in the export map table. We use this knowledge to 5112011SSriharsha.Basavapatna@Sun.COM * limit the # of cookies to a pre-defined maximum value. 5212011SSriharsha.Basavapatna@Sun.COM */ 5312011SSriharsha.Basavapatna@Sun.COM #define VNET_DATA_AREA_COOKIES 32 5412011SSriharsha.Basavapatna@Sun.COM 5512011SSriharsha.Basavapatna@Sun.COM /* 5612011SSriharsha.Basavapatna@Sun.COM * Size of dring reg msg in RxDringData mode, given # of data area cookies. 5712011SSriharsha.Basavapatna@Sun.COM * This assumes that the # of dring cookies in vio_dring_reg_msg_t is 1. 5812011SSriharsha.Basavapatna@Sun.COM * The given # of data area cookies is reduced by 1, as vio_dring_reg_msg_ext_t 5912011SSriharsha.Basavapatna@Sun.COM * itself contains 1 data cookie. 6012011SSriharsha.Basavapatna@Sun.COM */ 6112011SSriharsha.Basavapatna@Sun.COM #define VNET_DRING_REG_EXT_MSG_SIZE(data_ncookies) \ 6212011SSriharsha.Basavapatna@Sun.COM (sizeof (vio_dring_reg_msg_t) + sizeof (vio_dring_reg_ext_msg_t) + \ 6312011SSriharsha.Basavapatna@Sun.COM (((data_ncookies) - 1) * sizeof (ldc_mem_cookie_t))) 6412011SSriharsha.Basavapatna@Sun.COM 6512011SSriharsha.Basavapatna@Sun.COM /* Max supported size of dring reg msg in RxDringData mode */ 6612011SSriharsha.Basavapatna@Sun.COM #define VNET_DRING_REG_EXT_MSG_SIZE_MAX \ 6712011SSriharsha.Basavapatna@Sun.COM VNET_DRING_REG_EXT_MSG_SIZE(VNET_DATA_AREA_COOKIES) 6812011SSriharsha.Basavapatna@Sun.COM 691991Sheppo /* initial send sequence number */ 701991Sheppo #define VNET_ISS 0x1 711991Sheppo 7212011SSriharsha.Basavapatna@Sun.COM #define VNET_START_IDX_UNSPEC 0xFFFFFFFF /* ignore st_idx in dringdata ack */ 7312011SSriharsha.Basavapatna@Sun.COM 746419Ssb155480 #define VNET_2K (1 << 11) 757529SSriharsha.Basavapatna@Sun.COM #define VNET_4K (1 << 12) 767529SSriharsha.Basavapatna@Sun.COM #define VNET_8K (1 << 13) 777529SSriharsha.Basavapatna@Sun.COM #define VNET_12K ((VNET_8K) + (VNET_4K)) 782336Snarayan #define VNET_IPALIGN 6 /* padding for IP header alignment */ 796419Ssb155480 #define VNET_LDCALIGN 8 /* padding for ldc_mem_copy() align */ 806419Ssb155480 #define VNET_ROUNDUP_2K(n) (((n) + (VNET_2K - 1)) & ~(VNET_2K - 1)) 817529SSriharsha.Basavapatna@Sun.COM #define VNET_ROUNDUP_4K(n) (((n) + (VNET_4K - 1)) & ~(VNET_4K - 1)) 827529SSriharsha.Basavapatna@Sun.COM #define VNET_ROUNDUP_8K(n) (((n) + (VNET_8K - 1)) & ~(VNET_8K - 1)) 837529SSriharsha.Basavapatna@Sun.COM 8412011SSriharsha.Basavapatna@Sun.COM #define MEMBAR_CONSUMER membar_consumer 8512011SSriharsha.Basavapatna@Sun.COM #define MEMBAR_PRODUCER membar_producer 8612011SSriharsha.Basavapatna@Sun.COM 877529SSriharsha.Basavapatna@Sun.COM /* 887529SSriharsha.Basavapatna@Sun.COM * Maximum MTU value currently supported. MAX_COOKIES for data has been defined 897529SSriharsha.Basavapatna@Sun.COM * already based on ETHERMAX. Hence we limit the MTU to be within 2 8K pages 907529SSriharsha.Basavapatna@Sun.COM * and take some additional steps (see related code in .c files) to ensure that 917529SSriharsha.Basavapatna@Sun.COM * ldc cookies for each data buffer is within the MAX_COOKIES. This allows us 927529SSriharsha.Basavapatna@Sun.COM * to support Jumbo MTUs without changing the size of the descriptor. 937529SSriharsha.Basavapatna@Sun.COM */ 947529SSriharsha.Basavapatna@Sun.COM #define VNET_MAX_MTU 16000 952336Snarayan 965171Ssb155480 #define VNET_NUM_HANDSHAKES 6 /* # of handshake attempts */ 973297Ssb155480 98*13098SWentao.Yang@Sun.COM /* 99*13098SWentao.Yang@Sun.COM * Max frame size to data block size in RxDringData mode 100*13098SWentao.Yang@Sun.COM */ 101*13098SWentao.Yang@Sun.COM #define RXDRING_DBLK_SZ(mfs) \ 102*13098SWentao.Yang@Sun.COM (VNET_ROUNDUP_2K((mfs) + VNET_IPALIGN + VNET_LDCALIGN)) 103*13098SWentao.Yang@Sun.COM 1041991Sheppo /* vnet descriptor */ 1051991Sheppo typedef struct vnet_public_desc { 1061991Sheppo vio_dring_entry_hdr_t hdr; /* descriptor header */ 1071991Sheppo uint32_t nbytes; /* data length */ 1081991Sheppo uint32_t ncookies; /* number of data cookies */ 1091991Sheppo ldc_mem_cookie_t memcookie[MAX_COOKIES]; /* data cookies */ 1101991Sheppo } vnet_public_desc_t; 1111991Sheppo 1121991Sheppo /* 1133297Ssb155480 * Vnet in-band descriptor. Used by those vnet clients 1141991Sheppo * such as OBP who do not use descriptor rings. 1151991Sheppo */ 1163297Ssb155480 typedef struct vnet_ibnd_desc { 1171991Sheppo vio_inband_desc_msg_hdr_t hdr; 1181991Sheppo 1191991Sheppo /* payload */ 1201991Sheppo uint32_t nbytes; 1211991Sheppo uint32_t ncookies; 1221991Sheppo ldc_mem_cookie_t memcookie[MAX_COOKIES]; 1233297Ssb155480 } vnet_ibnd_desc_t; 1241991Sheppo 12512011SSriharsha.Basavapatna@Sun.COM /* 12612011SSriharsha.Basavapatna@Sun.COM * Descriptor format in RxDringData mode. 12712011SSriharsha.Basavapatna@Sun.COM */ 12812011SSriharsha.Basavapatna@Sun.COM typedef struct vnet_rxdring_data_desc { 12912011SSriharsha.Basavapatna@Sun.COM uint8_t dstate; /* Descriptor state */ 13012011SSriharsha.Basavapatna@Sun.COM uint8_t resv1[3]; /* Reserved */ 13112011SSriharsha.Basavapatna@Sun.COM uint32_t nbytes; /* Num bytes in data buffer */ 13212011SSriharsha.Basavapatna@Sun.COM uint64_t data_buf_offset; /* Offset of data buffer */ 13312011SSriharsha.Basavapatna@Sun.COM } vnet_rx_dringdata_desc_t; 13412011SSriharsha.Basavapatna@Sun.COM 1355462Swentaoy /* exported functions */ 1365462Swentaoy uint64_t vnet_macaddr_strtoul(const uint8_t *macaddr); 1375462Swentaoy void vnet_macaddr_ultostr(uint64_t value, uint8_t *macaddr); 1386419Ssb155480 mblk_t *vnet_vlan_insert_tag(mblk_t *mp, uint16_t vid); 1396419Ssb155480 mblk_t *vnet_vlan_remove_tag(mblk_t *mp); 1406845Sha137994 int vnet_dring_entry_copy(vnet_public_desc_t *dst, vnet_public_desc_t *src, 1416845Sha137994 uint8_t mtype, ldc_dring_handle_t handle, uint64_t start, uint64_t stop); 1426845Sha137994 int vnet_dring_entry_set_dstate(vnet_public_desc_t *descp, uint8_t mtype, 1436845Sha137994 ldc_dring_handle_t handle, uint64_t start, uint64_t stop, uint8_t dstate); 1445462Swentaoy 1451991Sheppo #ifdef __cplusplus 1461991Sheppo } 1471991Sheppo #endif 1481991Sheppo 1491991Sheppo #endif /* _VNET_COMMON_H */ 150