Current File : //usr/include/vdp.h
/*
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
 */

#ifndef _SYS_VDP_H
#define	_SYS_VDP_H

#ifdef	__cplusplus
extern "C" {
#endif

#include <sys/param.h>
#include <sys/types.h>
#include <sys/nvpair.h>
#include <syslog.h>
#include <libdlpi.h>
#include <ecp.h>
#include <sys/mac_flow.h>
/*
 * VDP TLV Types
 */
typedef enum vdp_tlv_type_s {
	VDP_TLV_NONE = 0,
	VDP_TLV_PRE_ASSOC,
	VDP_TLV_PRE_ASSOC_W_RR,
	VDP_TLV_ASSOC,
	VDP_TLV_DEASSOC,
	VDP_TLV_MGR_ID,
	VDP_TLV_TIMEDOUT,
	VDP_TLV_ORG_SPEC = 127
} vdp_tlv_type_t;

/*
 * VDP VSIID formats
 */
typedef enum vdp_tlv_vsiid_fmt_s {
	VDP_TLV_VSIID_FMT_IPV4 = 1,
	VDP_TLV_VSIID_FMT_IPV6,
	VDP_TLV_VSIID_FMT_MAC,
	VDP_TLV_VSIID_FMT_LOCAL,
	VDP_TLV_VSIID_FMT_UUID
} vdp_tlv_vsiid_fmt_t;

/*
 * VDP Filter Info Formats
 */
typedef enum vdp_tlv_fltr_fmt_s {
	VDP_FLTR_FMT_VID = 1,
	VDP_FLTR_FMT_MAC_VID,
	VDP_FLTR_FMT_GID_VID,
	VDP_FLTR_FMT_GID_MAC_VID
} vdp_tlv_fltr_fmt_t;

#define	VDP_VSI_MGR_ID_LEN	0x10
#define	VDP_TLV_VSIID_LEN	0x10

#define	VDP_VSIID_MAC_OFFSET	10

#define	VDP_ORACLE_OUI		0x0003BA

#define	VDP_ORG_HSIZE		4

/* assumes a pointer to a 3-byte array */
#define	vdp_ntoh24(p) 						\
	(*((uint8_t *)(p)) << 16 | *((uint8_t *)((p)+1)) << 8 | \
	*((uint8_t *)((p)+2)))

/* assumes a pointer to a 3 byte array, and an integer value */
#define	vdp_hton24(p, v) {\
	p[0] = (((v) >> 16) & 0xFF); \
	p[1] = (((v) >> 8) & 0xFF); \
	p[2] = ((v) & 0xFF); \
}

#define	VDP_ORGTLV_OUI(os)	vdp_ntoh24(os)
#define	VDP_ORGTLV_STYPE(os)	*((uint8_t *)((os) + 3))

/* Oracle OUI subtype */
#define	VDP_ORACLEOUI_VSIMGR_SUBTYPE	1

/* VDP Stats */
typedef struct vdp_stat_s {
	uint64_t	vs_ipkts;
	uint64_t	vs_opkts;
	uint64_t	vs_kas;
} vdp_stat_t;

/* VDP timers */
typedef struct vdp_timers_s {
	boolean_t	vt_rol_rwd;	/* local or remote RWD used */
	int		vt_rwd;	/* exponent for computing response wait delay */
	boolean_t	vt_rol_rka;	/* local or remote RKA used */
	int		vt_rka;	/* exponent for computing keep alive interval */
} vdp_timers_t;

/* VDP args passed via door */
typedef struct vdpt_arg_s {
	int			vdpt_version;
	datalink_id_t		vdpt_phy_link_id;
	datalink_id_t		vdpt_virt_link_id;

	/*
	 * The following are used by VDP_ADD_PROFILE.
	 */
	datalink_id_t		vdpt_virt_link_vid;
	uint32_t		vdpt_tlv_type_id;
	int			vdpt_tlv_type_version;
	vdp_tlv_vsiid_fmt_t	vdpt_tlv_vsiid_format;
	/*
	 * Currently only one entry is supported
	 */
	int			vdpt_tlv_fltr_entries;
	vdp_tlv_fltr_fmt_t	vdpt_tlv_fltr_info_format;
	mac_vsimgr_encoding_t	vdpt_mgrenc;
	char			vdpt_mgr_id[VDP_VSI_MGR_ID_LEN];
} vdpt_arg_t;

typedef struct vdp_link_info_s {
	size_t			vli_phy_link_maclen;
	uint8_t			vli_phy_link_mac[ETHERADDRL];
	char			vli_virt_link_name[MAXLINKNAMELEN];
	uint8_t			vli_virt_link_mac[ETHERADDRL];
	char 			vli_phy_link_name[MAXLINKNAMELEN];
} vdp_link_info_t;

/*
 * information returned for a profile
 */
#define	VDPT_TLVL_VERSION		0x1
#define	VDPT_ECPCFG_VERSION		0x1

#define	VDP_VSIID_LEN			16

/* VDP instance Information */
typedef struct vdpd_vdpinfo_t {
	int		vi_ver;
	char		vi_phys_link_name[MAXLINKNAMELEN];
	char		vi_virt_link_name[MAXLINKNAMELEN];
	vdp_tlv_type_t	vi_vsi_state;
	vdp_tlv_type_t	vi_cmd_pending;
	char		vi_vsi_state_str[16];
	char		vi_cmd_pending_str[16];
	uint8_t		vi_vsiid_format;
	uint8_t		vi_vsiid[VDP_VSIID_LEN];
	uint32_t	vi_vsitypeid;
	int		vi_vsitypevers;
	char		vi_fltr_info_str[24];
	uint_t		vi_vdp_keep_alive_time_sec;
	uint_t		vi_vdp_keep_alive_time_msec;
	uint_t		vi_vdp_resp_timeout_sec;
	uint_t		vi_vdp_resp_timeout_msec;
} vdpd_vdpinfo_t;

/* ECP information for VDP instances */
typedef struct vdpd_ecpinfo_s {
	int		ve_ver;
	char		ve_phys_link_name[MAXLINKNAMELEN];
	ushort_t	ve_req_seq;
	ushort_t	ve_ack_seq;
	ushort_t	ve_last_ack_seq;
	ushort_t	ve_max_tx_attempts;
	uint_t		ve_ack_timeout_msec;
} vdpd_ecpinfo_t;

#define	VDP_STDERR_LOG	1
#define	VDP_SYS_LOG	2

extern void vdp_init(int);
extern int vdp_tlv_add(vdpt_arg_t *, vdp_link_info_t *);
extern int vdp_tlv_del(vdpt_arg_t *);
extern int vdp_tlv_fini();
extern vdpd_vdpinfo_t *vdp_vdpinfo(vdpt_arg_t *, int *);
extern vdpd_ecpinfo_t *vdp_ecpinfo(vdpt_arg_t *, int *);
extern int vdp_vdpstats(vdpt_arg_t *, vdp_stat_t *);
extern int vdp_ecpstats(vdpt_arg_t *, ecp_stat_t *);
extern void vdp_vdptimers(vdpt_arg_t *, vdp_timers_t *);
extern void vdp_ecptimers(vdpt_arg_t *, ecp_timers_t *);
extern char *vdp_tlv_type_to_str(int);
extern char *vdp_vsiid_fmt_to_str(int);
extern char *vdp_tlv_fltr_fmt_to_str(int);
extern void vdp_reason2str(uint8_t, char *, int);
extern char *vdp_vsimgr_encoding(uint8_t);

#ifdef	__cplusplus
}
#endif

#endif /* _SYS_VDP_H */