1843e1988Sjohnlev /* 2843e1988Sjohnlev * CDDL HEADER START 3843e1988Sjohnlev * 4843e1988Sjohnlev * The contents of this file are subject to the terms of the 5843e1988Sjohnlev * Common Development and Distribution License (the "License"). 6843e1988Sjohnlev * You may not use this file except in compliance with the License. 7843e1988Sjohnlev * 8843e1988Sjohnlev * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9843e1988Sjohnlev * or http://www.opensolaris.org/os/licensing. 10843e1988Sjohnlev * See the License for the specific language governing permissions 11843e1988Sjohnlev * and limitations under the License. 12843e1988Sjohnlev * 13843e1988Sjohnlev * When distributing Covered Code, include this CDDL HEADER in each 14843e1988Sjohnlev * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15843e1988Sjohnlev * If applicable, add the following below this CDDL HEADER, with the 16843e1988Sjohnlev * fields enclosed by brackets "[]" replaced with your own identifying 17843e1988Sjohnlev * information: Portions Copyright [yyyy] [name of copyright owner] 18843e1988Sjohnlev * 19843e1988Sjohnlev * CDDL HEADER END 20843e1988Sjohnlev */ 21843e1988Sjohnlev 22843e1988Sjohnlev /* 23fd0939efSDavid Edmondson * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24843e1988Sjohnlev * Use is subject to license terms. 25843e1988Sjohnlev * 26843e1988Sjohnlev * xnb.h - definitions for Xen dom0 network driver 27843e1988Sjohnlev */ 28843e1988Sjohnlev 29843e1988Sjohnlev #ifndef _SYS_XNB_H 30843e1988Sjohnlev #define _SYS_XNB_H 31843e1988Sjohnlev 32843e1988Sjohnlev #include <sys/types.h> 33843e1988Sjohnlev #include <sys/kstat.h> 34843e1988Sjohnlev #include <sys/stream.h> 35843e1988Sjohnlev #include <sys/ethernet.h> 36843e1988Sjohnlev #include <sys/hypervisor.h> 37*876de206SRichard Lowe #include <sys/sysmacros.h> 38843e1988Sjohnlev #include <xen/public/io/netif.h> 39843e1988Sjohnlev 40843e1988Sjohnlev #ifdef __cplusplus 41843e1988Sjohnlev extern "C" { 42843e1988Sjohnlev #endif 43843e1988Sjohnlev 44*876de206SRichard Lowe #define NET_TX_RING_SIZE __CONST_RING_SIZE(netif_tx, PAGESIZE) 45*876de206SRichard Lowe #define NET_RX_RING_SIZE __CONST_RING_SIZE(netif_rx, PAGESIZE) 46843e1988Sjohnlev 47843e1988Sjohnlev #define XNBMAXPKT 1500 /* MTU size */ 48843e1988Sjohnlev 49843e1988Sjohnlev /* DEBUG flags */ 50843e1988Sjohnlev #define XNBDDI 0x01 51843e1988Sjohnlev #define XNBTRACE 0x02 52843e1988Sjohnlev #define XNBSEND 0x04 53843e1988Sjohnlev #define XNBRECV 0x08 54843e1988Sjohnlev #define XNBINTR 0x10 55843e1988Sjohnlev #define XNBRING 0x20 56843e1988Sjohnlev #define XNBCKSUM 0x40 57843e1988Sjohnlev 5856567907SDavid Edmondson #define XNB_STATE_INIT 0x01 5956567907SDavid Edmondson #define XNB_STATE_READY 0x02 6056567907SDavid Edmondson 61843e1988Sjohnlev typedef struct xnb xnb_t; 62843e1988Sjohnlev 63843e1988Sjohnlev /* 64843e1988Sjohnlev * The xnb module provides core inter-domain network protocol functionality. 65843e1988Sjohnlev * It is connected to the rest of Solaris in two ways: 66843e1988Sjohnlev * - as a GLDv3 driver (with xnbu), 67843e1988Sjohnlev * - as a GLDv3 consumer (with xnbo). 68843e1988Sjohnlev * 69843e1988Sjohnlev * The different modes of operation are termed "flavours" and each 70843e1988Sjohnlev * instance of an xnb based driver operates in one and only one mode. 71843e1988Sjohnlev * The common xnb driver exports a set of functions to these drivers 72843e1988Sjohnlev * (declarations at the foot of this file) and calls back into the 73843e1988Sjohnlev * drivers via the xnb_flavour_t structure. 74843e1988Sjohnlev */ 75843e1988Sjohnlev typedef struct xnb_flavour { 76024c26efSMax zhen void (*xf_from_peer)(xnb_t *, mblk_t *); 7756567907SDavid Edmondson boolean_t (*xf_peer_connected)(xnb_t *); 78843e1988Sjohnlev void (*xf_peer_disconnected)(xnb_t *); 79843e1988Sjohnlev boolean_t (*xf_hotplug_connected)(xnb_t *); 8056567907SDavid Edmondson boolean_t (*xf_start_connect)(xnb_t *); 81843e1988Sjohnlev mblk_t *(*xf_cksum_from_peer)(xnb_t *, mblk_t *, uint16_t); 82843e1988Sjohnlev uint16_t (*xf_cksum_to_peer)(xnb_t *, mblk_t *); 8356567907SDavid Edmondson boolean_t (*xf_mcast_add)(xnb_t *, ether_addr_t *); 8456567907SDavid Edmondson boolean_t (*xf_mcast_del)(xnb_t *, ether_addr_t *); 85843e1988Sjohnlev } xnb_flavour_t; 86843e1988Sjohnlev 87024c26efSMax zhen typedef struct xnb_txbuf { 88024c26efSMax zhen frtn_t xt_free_rtn; 89024c26efSMax zhen xnb_t *xt_xnbp; 9056567907SDavid Edmondson struct xnb_txbuf *xt_next; 91024c26efSMax zhen RING_IDX xt_id; 9256567907SDavid Edmondson RING_IDX xt_idx; 93024c26efSMax zhen uint16_t xt_status; 9456567907SDavid Edmondson 9556567907SDavid Edmondson ddi_dma_handle_t xt_dma_handle; 9656567907SDavid Edmondson ddi_acc_handle_t xt_acc_handle; 9756567907SDavid Edmondson caddr_t xt_buf; 9856567907SDavid Edmondson size_t xt_buflen; 9956567907SDavid Edmondson mfn_t xt_mfn; 10056567907SDavid Edmondson 10156567907SDavid Edmondson mblk_t *xt_mblk; 10256567907SDavid Edmondson 103024c26efSMax zhen unsigned int xt_flags; 104843e1988Sjohnlev 105024c26efSMax zhen #define XNB_TXBUF_INUSE 0x01 106843e1988Sjohnlev 107024c26efSMax zhen } xnb_txbuf_t; 108843e1988Sjohnlev 109843e1988Sjohnlev /* Per network-interface-controller driver private structure */ 110843e1988Sjohnlev struct xnb { 111843e1988Sjohnlev /* most interesting stuff first to assist debugging */ 112551bc2a6Smrj dev_info_t *xnb_devinfo; /* System per-device info. */ 113843e1988Sjohnlev 114551bc2a6Smrj xnb_flavour_t *xnb_flavour; 115551bc2a6Smrj void *xnb_flavour_data; 116843e1988Sjohnlev 117551bc2a6Smrj boolean_t xnb_irq; 118551bc2a6Smrj unsigned char xnb_mac_addr[ETHERADDRL]; 119843e1988Sjohnlev 120551bc2a6Smrj uint64_t xnb_stat_ipackets; 121551bc2a6Smrj uint64_t xnb_stat_opackets; 122551bc2a6Smrj uint64_t xnb_stat_rbytes; 123551bc2a6Smrj uint64_t xnb_stat_obytes; 124843e1988Sjohnlev 125551bc2a6Smrj uint64_t xnb_stat_intr; 126024c26efSMax zhen uint64_t xnb_stat_rx_defer; 127843e1988Sjohnlev 128024c26efSMax zhen uint64_t xnb_stat_rx_cksum_deferred; 129024c26efSMax zhen uint64_t xnb_stat_tx_cksum_no_need; 130843e1988Sjohnlev 131024c26efSMax zhen uint64_t xnb_stat_rx_rsp_notok; 13266f1a35aSschuster 133551bc2a6Smrj uint64_t xnb_stat_tx_notify_sent; 134551bc2a6Smrj uint64_t xnb_stat_tx_notify_deferred; 135843e1988Sjohnlev 136551bc2a6Smrj uint64_t xnb_stat_rx_notify_sent; 137551bc2a6Smrj uint64_t xnb_stat_rx_notify_deferred; 138843e1988Sjohnlev 139551bc2a6Smrj uint64_t xnb_stat_tx_too_early; 140551bc2a6Smrj uint64_t xnb_stat_rx_too_early; 141551bc2a6Smrj uint64_t xnb_stat_rx_allocb_failed; 142551bc2a6Smrj uint64_t xnb_stat_tx_allocb_failed; 143024c26efSMax zhen uint64_t xnb_stat_rx_foreign_page; 144fd0939efSDavid Edmondson uint64_t xnb_stat_tx_overflow_page; 145fd0939efSDavid Edmondson uint64_t xnb_stat_tx_unexpected_flags; 146551bc2a6Smrj uint64_t xnb_stat_mac_full; 147551bc2a6Smrj uint64_t xnb_stat_spurious_intr; 148551bc2a6Smrj uint64_t xnb_stat_allocation_success; 149551bc2a6Smrj uint64_t xnb_stat_allocation_failure; 150551bc2a6Smrj uint64_t xnb_stat_small_allocation_success; 151551bc2a6Smrj uint64_t xnb_stat_small_allocation_failure; 152551bc2a6Smrj uint64_t xnb_stat_other_allocation_failure; 153843e1988Sjohnlev 154024c26efSMax zhen uint64_t xnb_stat_rx_pagebndry_crossed; 155024c26efSMax zhen uint64_t xnb_stat_rx_cpoparea_grown; 156843e1988Sjohnlev 157551bc2a6Smrj uint64_t xnb_stat_csum_hardware; 158551bc2a6Smrj uint64_t xnb_stat_csum_software; 159843e1988Sjohnlev 160551bc2a6Smrj kstat_t *xnb_kstat_aux; 161843e1988Sjohnlev 162551bc2a6Smrj ddi_iblock_cookie_t xnb_icookie; 163843e1988Sjohnlev 164551bc2a6Smrj kmutex_t xnb_rx_lock; 165551bc2a6Smrj kmutex_t xnb_tx_lock; 16656567907SDavid Edmondson kmutex_t xnb_state_lock; 167843e1988Sjohnlev 16856567907SDavid Edmondson int xnb_be_status; 16956567907SDavid Edmondson int xnb_fe_status; 17056567907SDavid Edmondson 17156567907SDavid Edmondson kmem_cache_t *xnb_tx_buf_cache; 17256567907SDavid Edmondson uint32_t xnb_tx_buf_count; 17356567907SDavid Edmondson int xnb_tx_buf_outstanding; 174843e1988Sjohnlev 175551bc2a6Smrj netif_rx_back_ring_t xnb_rx_ring; /* rx interface struct ptr */ 176551bc2a6Smrj void *xnb_rx_ring_addr; 177551bc2a6Smrj grant_ref_t xnb_rx_ring_ref; 178551bc2a6Smrj grant_handle_t xnb_rx_ring_handle; 179843e1988Sjohnlev 180551bc2a6Smrj netif_tx_back_ring_t xnb_tx_ring; /* tx interface struct ptr */ 181551bc2a6Smrj void *xnb_tx_ring_addr; 182551bc2a6Smrj grant_ref_t xnb_tx_ring_ref; 183551bc2a6Smrj grant_handle_t xnb_tx_ring_handle; 184843e1988Sjohnlev 185551bc2a6Smrj boolean_t xnb_connected; 186551bc2a6Smrj boolean_t xnb_hotplugged; 187551bc2a6Smrj boolean_t xnb_detachable; 188551bc2a6Smrj int xnb_evtchn; /* channel to front end */ 18956567907SDavid Edmondson evtchn_port_t xnb_fe_evtchn; 190551bc2a6Smrj domid_t xnb_peer; 191843e1988Sjohnlev 192024c26efSMax zhen xnb_txbuf_t *xnb_tx_bufp[NET_TX_RING_SIZE]; 19356567907SDavid Edmondson gnttab_copy_t xnb_tx_cop[NET_TX_RING_SIZE]; 194551bc2a6Smrj 195024c26efSMax zhen caddr_t xnb_rx_va; 196024c26efSMax zhen gnttab_transfer_t xnb_rx_top[NET_RX_RING_SIZE]; 197551bc2a6Smrj 19856567907SDavid Edmondson boolean_t xnb_rx_hv_copy; 19956567907SDavid Edmondson boolean_t xnb_multicast_control; 20056567907SDavid Edmondson boolean_t xnb_no_csum_offload; 20156567907SDavid Edmondson 202024c26efSMax zhen gnttab_copy_t *xnb_rx_cpop; 203551bc2a6Smrj #define CPOP_DEFCNT 8 20456567907SDavid Edmondson size_t xnb_rx_cpop_count; /* in elements */ 205843e1988Sjohnlev }; 206843e1988Sjohnlev 207843e1988Sjohnlev extern int xnb_attach(dev_info_t *, xnb_flavour_t *, void *); 208843e1988Sjohnlev extern void xnb_detach(dev_info_t *); 209551bc2a6Smrj extern mblk_t *xnb_copy_to_peer(xnb_t *, mblk_t *); 210843e1988Sjohnlev extern mblk_t *xnb_process_cksum_flags(xnb_t *, mblk_t *, uint32_t); 211843e1988Sjohnlev 212843e1988Sjohnlev #ifdef __cplusplus 213843e1988Sjohnlev } 214843e1988Sjohnlev #endif 215843e1988Sjohnlev 216843e1988Sjohnlev #endif /* _SYS_XNB_H */ 217