/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
*/
#ifndef _SYS_VDP_IMPL_H
#define _SYS_VDP_IMPL_H
#ifdef __cplusplus
extern "C" {
#endif
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <sys/types.h>
#include <stddef.h>
#include <door.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <paths.h>
#include <sys/param.h>
#include <sys/list.h>
#include <libdllink.h>
#include <libdlpi.h>
#include <pthread.h>
#include <string.h>
#include <strings.h>
#include <sys/socket_impl.h>
#include <sys/socket.h>
#include <assert.h>
#include <ecp.h>
#include <vdp.h>
#include <libinetutil.h>
#define D_ALL 0xffff
/*
* VDP Timers
*/
#define VDP_RESP_WAIT_DELAY_MSEC 11600
#define VDP_REINIT_KEEP_ALIVE_TIME_MSEC 10500
#define VDP_KEEP_ALIVE_EXPONENT 20
#define VDP_RESOURCE_WAIT_DELAY_EXPONENT 20
typedef enum vdp_state {
VDP_REC_INIT,
VDP_REC_ACTIVE,
VDP_REC_DELETED,
VDP_REC_TIMEDOUT
} vdp_state_t;
typedef enum vdp_prof_proc_state_s {
VDP_PROF_INIT = 0,
VDP_PROF_PROCESSING,
VDP_PROF_WAIT_SYS_CMD,
VDP_PROF_TX_KEEP_ALIVE,
VDP_PROF_TIMEDOUT,
VDP_PROF_TX_DEASSOC,
VDP_PROF_DELETED,
} vdp_prof_proc_state_t;
#define VDP_TLV_TYPE_MASK 0xFE
#define VDP_TLV_LEN_MASK 0x1FF
#define VDP_TLV_REASON_OFFSET 0x02
#define VDP_TLV_REASON_MASK 0xF
#define VDP_TLV_TYPE_SHIFT 9
#define VDP_TLV_LEN_SHIFT 0
#define VDP_TLV_VSIID_OFFSET 0x08
#pragma pack(1)
typedef struct vdp_tlv_s {
uint16_t vdp_tlv_type_len;
uint8_t vdp_tlv_reason;
uint8_t vdp_tlv_vsi_type[3];
uint8_t vdp_tlv_vsi_type_ver;
uint8_t vdp_tlv_vsiid_format;
uint8_t vdp_tlv_vsiid[16];
uint8_t vdp_tlv_fltr_format;
uint16_t vdp_tlv_fltr_entries;
} vdp_tlv_t;
typedef struct vdp_tlv_mgr_s {
uint16_t vdp_mgr_tlv_type_len;
uint8_t vdp_mgr_tlv_id[16];
} vdp_tlv_mgr_t;
/* Org specific TLV that follows the VSI Manager TLV. */
typedef struct vdp_tlv_mgrenc_s {
uint16_t vtme_type_len;
uint8_t vtme_ouistype[VDP_ORG_HSIZE];
uint8_t vtme_encid;
} vdp_tlv_mgrenc_t;
/*
* VDP Filters
*/
#define VTF_PS_MASK 0x1
#define VTF_PCP_MASK 0x7
#define VTF_VID_MASK 0xFFF
#define VTF_PS_SHIFT 15
#define VTF_PCP_SHIFT 12
typedef short vtf_ps_pcp_vid_t;
typedef struct vdp_tlv_fltr_vid_s {
vtf_ps_pcp_vid_t vtf_vid_ps_pcp_vid;
}vtf_vid_t;
typedef struct vtf_mac_s {
uint8_t vtf_mac_addr[6];
vtf_ps_pcp_vid_t vtf_mac_ps_pcp_vid;
} vtf_mac_t;
typedef struct vtf_group_s {
char vtf_group_id[4];
vtf_ps_pcp_vid_t vtf_group_ps_pcp_vid;
} vtf_group_t;
typedef struct vtf_group_mac_s {
char vtf_group_mac_id[4];
uint8_t vtf_group_mac_addr[6];
vtf_ps_pcp_vid_t vtf_group_mac_ps_pcp_vid;
} vtf_group_mac_t;
#pragma pack()
/* VDP profile for each VSI/VNIC */
typedef struct vdp_profile_s {
char vdp_prof_vnic_name[MAXLINKNAMELEN];
datalink_id_t vdp_prof_vnic_id;
uint8_t vdp_prof_vsiid_format;
uint8_t vdp_prof_vsiid[16];
uint_t vdp_prof_id_type;
uint_t vdp_prof_id_vers;
vdp_prof_proc_state_t vdp_prof_proc_state;
vdp_tlv_type_t vdp_prof_vsi_state; /* same as TLV type */
vdp_tlv_type_t vdp_prof_cmd_pending; /* same as TLV type */
vdp_tlv_t vdp_prof_tlv;
char vdp_prof_wire_tlv[ETHERMTU];
int vdp_prof_tlv_len;
int vdp_prof_timer_id;
struct vdp_inst_struct_s *vdp_prof_instp;
boolean_t vdp_prof_deleted;
int vdp_prof_fltr_entries;
vdp_tlv_fltr_fmt_t vdp_prof_fltr_info_format;
vtf_mac_t vdp_prof_tlv_fltr_mac;
list_node_t vdp_profile_node;
vdp_tlv_mgr_t vdp_prof_mgr_tlv;
vdp_tlv_mgrenc_t vdp_prof_mgr_enc_tlv;
/* per-vsi Statistics */
uint64_t vdp_prof_ipkts;
uint64_t vdp_prof_opkts;
uint64_t vdp_prof_kas;
} vdp_profile_t;
#define VDP_PROF_STAT_UPDATE(v, s, c) { \
vdp_profile_t *vp = (vdp_profile_t *)(v); \
vdp_inst_t *vi = (vdp_inst_t *)vp->vdp_prof_instp; \
vp->vdp_prof_##s += ((uint64_t)(c)); \
vi->vdp_inst_##s += ((uint64_t)(c)); \
}
/* VDP instance for each physical port */
typedef struct vdp_inst_struct_s {
char vdp_inst_phy_link_name[MAXLINKNAMELEN];
datalink_id_t vdp_inst_phy_id;
vdp_state_t vdp_inst_state;
void *vdp_inst_ecp_handle;
size_t vdp_inst_ecp_offset; /* offset for ECP header */
pthread_cond_t vdp_inst_cv;
pthread_mutex_t vdp_inst_lock;
uint8_t vdp_inst_lphysaddr[DLPI_PHYSADDR_MAX];
size_t vdp_inst_lphysaddr_len;
int vdp_inst_sockfd;
pthread_t vdp_inst_timeout_process_thread;
list_t vdp_inst_profiles; /* list of profiles */
list_node_t vdp_inst_node; /* link in Global instance list */
iu_tq_t *vdp_inst_tq;
/* Statistics */
uint64_t vdp_inst_ipkts;
uint64_t vdp_inst_opkts;
uint64_t vdp_inst_kas;
} vdp_inst_t;
extern void vdp_logmsg(int, const char *, ...);
#define logerr(...) vdp_logmsg(LOG_ERR, __VA_ARGS__)
#define logtrace(...) vdp_logmsg(LOG_INFO, __VA_ARGS__)
#define logdebug(...) vdp_logmsg(LOG_DEBUG, __VA_ARGS__)
#ifdef __cplusplus
}
#endif
#endif /* _SYS_VDP_IMPL_H */