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/*
fd0939ef389f48c901faf4bf0b60b82d4bc58b64David Edmondson * Copyright 2010 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>
876de206688d9fe008ad80c116a23a56701579d1Richard Lowe#include <sys/sysmacros.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev#include <xen/public/io/netif.h>
843e19887f64dde75055cf8842fc4db2171eff45johnlev
843e19887f64dde75055cf8842fc4db2171eff45johnlev#ifdef __cplusplus
843e19887f64dde75055cf8842fc4db2171eff45johnlevextern "C" {
843e19887f64dde75055cf8842fc4db2171eff45johnlev#endif
843e19887f64dde75055cf8842fc4db2171eff45johnlev
876de206688d9fe008ad80c116a23a56701579d1Richard Lowe#define NET_TX_RING_SIZE __CONST_RING_SIZE(netif_tx, PAGESIZE)
876de206688d9fe008ad80c116a23a56701579d1Richard Lowe#define NET_RX_RING_SIZE __CONST_RING_SIZE(netif_rx, 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
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson#define XNB_STATE_INIT 0x01
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson#define XNB_STATE_READY 0x02
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson
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 *);
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson boolean_t (*xf_peer_connected)(xnb_t *);
843e19887f64dde75055cf8842fc4db2171eff45johnlev void (*xf_peer_disconnected)(xnb_t *);
843e19887f64dde75055cf8842fc4db2171eff45johnlev boolean_t (*xf_hotplug_connected)(xnb_t *);
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson boolean_t (*xf_start_connect)(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 *);
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson boolean_t (*xf_mcast_add)(xnb_t *, ether_addr_t *);
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson boolean_t (*xf_mcast_del)(xnb_t *, ether_addr_t *);
843e19887f64dde75055cf8842fc4db2171eff45johnlev} xnb_flavour_t;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhentypedef struct xnb_txbuf {
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen frtn_t xt_free_rtn;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen xnb_t *xt_xnbp;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson struct xnb_txbuf *xt_next;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen RING_IDX xt_id;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson RING_IDX xt_idx;
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen uint16_t xt_status;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson ddi_dma_handle_t xt_dma_handle;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson ddi_acc_handle_t xt_acc_handle;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson caddr_t xt_buf;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson size_t xt_buflen;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson mfn_t xt_mfn;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson mblk_t *xt_mblk;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson
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;
fd0939ef389f48c901faf4bf0b60b82d4bc58b64David Edmondson uint64_t xnb_stat_tx_overflow_page;
fd0939ef389f48c901faf4bf0b60b82d4bc58b64David Edmondson uint64_t xnb_stat_tx_unexpected_flags;
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 ddi_iblock_cookie_t xnb_icookie;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj kmutex_t xnb_rx_lock;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj kmutex_t xnb_tx_lock;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson kmutex_t xnb_state_lock;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson int xnb_be_status;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson int xnb_fe_status;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson kmem_cache_t *xnb_tx_buf_cache;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson uint32_t xnb_tx_buf_count;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson int xnb_tx_buf_outstanding;
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 */
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson evtchn_port_t xnb_fe_evtchn;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj domid_t xnb_peer;
843e19887f64dde75055cf8842fc4db2171eff45johnlev
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson xnb_txbuf_t *xnb_tx_bufp[NET_TX_RING_SIZE];
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson gnttab_copy_t xnb_tx_cop[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
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson boolean_t xnb_rx_hv_copy;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson boolean_t xnb_multicast_control;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson boolean_t xnb_no_csum_offload;
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson
024c26ef7a54ce7ac147c58352f2f52a28062711Max zhen gnttab_copy_t *xnb_rx_cpop;
551bc2a66868b5cb5be6b70ab9f55515e77a39a9mrj#define CPOP_DEFCNT 8
565679070e884800f5d041d42d226813c0bbf6d8David Edmondson size_t xnb_rx_cpop_count; /* in elements */
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 */