xnb.h revision 024c26ef7a54ce7ac147c58352f2f52a28062711
843e19887f64dde75055cf8842fc4db2171eff45johnlev/*
843e19887f64dde75055cf8842fc4db2171eff45johnlev * CDDL HEADER START
843e19887f64dde75055cf8842fc4db2171eff45johnlev *
843e19887f64dde75055cf8842fc4db2171eff45johnlev * The contents of this file are subject to the terms of the
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Common Development and Distribution License (the "License").
843e19887f64dde75055cf8842fc4db2171eff45johnlev * You may not use this file except in compliance with the License.
843e19887f64dde75055cf8842fc4db2171eff45johnlev *
843e19887f64dde75055cf8842fc4db2171eff45johnlev * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
843e19887f64dde75055cf8842fc4db2171eff45johnlev * or http://www.opensolaris.org/os/licensing.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * See the License for the specific language governing permissions
843e19887f64dde75055cf8842fc4db2171eff45johnlev * and limitations under the License.
843e19887f64dde75055cf8842fc4db2171eff45johnlev *
843e19887f64dde75055cf8842fc4db2171eff45johnlev * When distributing Covered Code, include this CDDL HEADER in each
843e19887f64dde75055cf8842fc4db2171eff45johnlev * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * If applicable, add the following below this CDDL HEADER, with the
843e19887f64dde75055cf8842fc4db2171eff45johnlev * fields enclosed by brackets "[]" replaced with your own identifying
843e19887f64dde75055cf8842fc4db2171eff45johnlev * information: Portions Copyright [yyyy] [name of copyright owner]
843e19887f64dde75055cf8842fc4db2171eff45johnlev *
843e19887f64dde75055cf8842fc4db2171eff45johnlev * CDDL HEADER END
843e19887f64dde75055cf8842fc4db2171eff45johnlev */
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev/*
66f1a35af5debdb90a7c30b19488e1414a029075schuster * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * Use is subject to license terms.
843e19887f64dde75055cf8842fc4db2171eff45johnlev *
843e19887f64dde75055cf8842fc4db2171eff45johnlev * xnb.h - definitions for Xen dom0 network driver
843e19887f64dde75055cf8842fc4db2171eff45johnlev */
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev#ifndef _SYS_XNB_H
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define _SYS_XNB_H
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <sys/types.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <sys/kstat.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <sys/stream.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <sys/ethernet.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <sys/hypervisor.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <xen/public/io/netif.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev#ifdef __cplusplus
843e19887f64dde75055cf8842fc4db2171eff45johnlevextern "C" {
843e19887f64dde75055cf8842fc4db2171eff45johnlev#endif
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define NET_TX_RING_SIZE __RING_SIZE((netif_tx_sring_t *)0, PAGESIZE)
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define NET_RX_RING_SIZE __RING_SIZE((netif_rx_sring_t *)0, PAGESIZE)
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define XNBMAXPKT 1500 /* MTU size */
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev/* DEBUG flags */
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define XNBDDI 0x01
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define XNBTRACE 0x02
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define XNBSEND 0x04
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define XNBRECV 0x08
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define XNBINTR 0x10
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define XNBRING 0x20
843e19887f64dde75055cf8842fc4db2171eff45johnlev#define XNBCKSUM 0x40
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlevtypedef struct xnb xnb_t;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev/*
843e19887f64dde75055cf8842fc4db2171eff45johnlev * The xnb module provides core inter-domain network protocol functionality.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * It is connected to the rest of Solaris in two ways:
843e19887f64dde75055cf8842fc4db2171eff45johnlev * - as a GLDv3 driver (with xnbu),
843e19887f64dde75055cf8842fc4db2171eff45johnlev * - as a GLDv3 consumer (with xnbo).
843e19887f64dde75055cf8842fc4db2171eff45johnlev *
843e19887f64dde75055cf8842fc4db2171eff45johnlev * The different modes of operation are termed "flavours" and each
843e19887f64dde75055cf8842fc4db2171eff45johnlev * instance of an xnb based driver operates in one and only one mode.
843e19887f64dde75055cf8842fc4db2171eff45johnlev * The common xnb driver exports a set of functions to these drivers
843e19887f64dde75055cf8842fc4db2171eff45johnlev * (declarations at the foot of this file) and calls back into the
843e19887f64dde75055cf8842fc4db2171eff45johnlev * drivers via the xnb_flavour_t structure.
843e19887f64dde75055cf8842fc4db2171eff45johnlev */
843e19887f64dde75055cf8842fc4db2171eff45johnlevtypedef struct xnb_flavour {
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen void (*xf_from_peer)(xnb_t *, mblk_t *);
843e19887f64dde75055cf8842fc4db2171eff45johnlev void (*xf_peer_connected)(xnb_t *);
843e19887f64dde75055cf8842fc4db2171eff45johnlev void (*xf_peer_disconnected)(xnb_t *);
843e19887f64dde75055cf8842fc4db2171eff45johnlev boolean_t (*xf_hotplug_connected)(xnb_t *);
843e19887f64dde75055cf8842fc4db2171eff45johnlev mblk_t *(*xf_cksum_from_peer)(xnb_t *, mblk_t *, uint16_t);
843e19887f64dde75055cf8842fc4db2171eff45johnlev uint16_t (*xf_cksum_to_peer)(xnb_t *, mblk_t *);
843e19887f64dde75055cf8842fc4db2171eff45johnlev} xnb_flavour_t;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhentypedef struct xnb_txbuf {
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen frtn_t xt_free_rtn;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen xnb_t *xt_xnbp;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen gnttab_map_grant_ref_t xt_mop;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen RING_IDX xt_id;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen uint16_t xt_status;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen unsigned int xt_flags;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen#define XNB_TXBUF_INUSE 0x01
843e19887f64dde75055cf8842fc4db2171eff45johnlev
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen} xnb_txbuf_t;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev/* Per network-interface-controller driver private structure */
843e19887f64dde75055cf8842fc4db2171eff45johnlevstruct xnb {
843e19887f64dde75055cf8842fc4db2171eff45johnlev /* most interesting stuff first to assist debugging */
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj dev_info_t *xnb_devinfo; /* System per-device info. */
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj xnb_flavour_t *xnb_flavour;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj void *xnb_flavour_data;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj boolean_t xnb_irq;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj unsigned char xnb_mac_addr[ETHERADDRL];
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_ipackets;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_opackets;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_rbytes;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_obytes;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_intr;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen uint64_t xnb_stat_rx_defer;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen uint64_t xnb_stat_rx_cksum_deferred;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen uint64_t xnb_stat_tx_cksum_no_need;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen uint64_t xnb_stat_rx_rsp_notok;
66f1a35af5debdb90a7c30b19488e1414a029075schuster
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_tx_notify_sent;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_tx_notify_deferred;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_rx_notify_sent;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_rx_notify_deferred;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_tx_too_early;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_rx_too_early;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_rx_allocb_failed;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_tx_allocb_failed;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen uint64_t xnb_stat_rx_foreign_page;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_mac_full;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_spurious_intr;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_allocation_success;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_allocation_failure;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_small_allocation_success;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_small_allocation_failure;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_other_allocation_failure;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen uint64_t xnb_stat_rx_pagebndry_crossed;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen uint64_t xnb_stat_rx_cpoparea_grown;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_csum_hardware;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj uint64_t xnb_stat_csum_software;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj kstat_t *xnb_kstat_aux;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj boolean_t xnb_cksum_offload;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj ddi_iblock_cookie_t xnb_icookie;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj kmutex_t xnb_rx_lock;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj kmutex_t xnb_tx_lock;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen int xnb_tx_unmop_count;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen int xnb_tx_buf_count;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen boolean_t xnb_tx_pages_writable;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen boolean_t xnb_tx_always_copy;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj netif_rx_back_ring_t xnb_rx_ring; /* rx interface struct ptr */
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj void *xnb_rx_ring_addr;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj grant_ref_t xnb_rx_ring_ref;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj grant_handle_t xnb_rx_ring_handle;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj netif_tx_back_ring_t xnb_tx_ring; /* tx interface struct ptr */
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj void *xnb_tx_ring_addr;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj grant_ref_t xnb_tx_ring_ref;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj grant_handle_t xnb_tx_ring_handle;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj boolean_t xnb_connected;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj boolean_t xnb_hotplugged;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj boolean_t xnb_detachable;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj int xnb_evtchn; /* channel to front end */
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj domid_t xnb_peer;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen xnb_txbuf_t *xnb_tx_bufp[NET_TX_RING_SIZE];
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen gnttab_map_grant_ref_t xnb_tx_mop[NET_TX_RING_SIZE];
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen gnttab_unmap_grant_ref_t xnb_tx_unmop[NET_TX_RING_SIZE];
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj /* store information for unmop */
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen xnb_txbuf_t *xnb_tx_unmop_txp[NET_TX_RING_SIZE];
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen caddr_t xnb_rx_va;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen gnttab_transfer_t xnb_rx_top[NET_RX_RING_SIZE];
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj boolean_t xnb_hv_copy; /* do we do hypervisor copy? */
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen gnttab_copy_t *xnb_rx_cpop;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj#define CPOP_DEFCNT 8
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj size_t xnb_cpop_sz; /* in elements, not bytes */
843e19887f64dde75055cf8842fc4db2171eff45johnlev};
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlevextern int xnb_attach(dev_info_t *, xnb_flavour_t *, void *);
843e19887f64dde75055cf8842fc4db2171eff45johnlevextern void xnb_detach(dev_info_t *);
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrjextern mblk_t *xnb_copy_to_peer(xnb_t *, mblk_t *);
843e19887f64dde75055cf8842fc4db2171eff45johnlevextern mblk_t *xnb_process_cksum_flags(xnb_t *, mblk_t *, uint32_t);
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev#ifdef __cplusplus
843e19887f64dde75055cf8842fc4db2171eff45johnlev}
843e19887f64dde75055cf8842fc4db2171eff45johnlev#endif
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev#endif /* _SYS_XNB_H */