Home | History | Annotate | Download | only in io
      1   5084   johnlev /*
      2   5084   johnlev  * CDDL HEADER START
      3   5084   johnlev  *
      4   5084   johnlev  * The contents of this file are subject to the terms of the
      5   5084   johnlev  * Common Development and Distribution License (the "License").
      6   5084   johnlev  * You may not use this file except in compliance with the License.
      7   5084   johnlev  *
      8   5084   johnlev  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9   5084   johnlev  * or http://www.opensolaris.org/os/licensing.
     10   5084   johnlev  * See the License for the specific language governing permissions
     11   5084   johnlev  * and limitations under the License.
     12   5084   johnlev  *
     13   5084   johnlev  * When distributing Covered Code, include this CDDL HEADER in each
     14   5084   johnlev  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15   5084   johnlev  * If applicable, add the following below this CDDL HEADER, with the
     16   5084   johnlev  * fields enclosed by brackets "[]" replaced with your own identifying
     17   5084   johnlev  * information: Portions Copyright [yyyy] [name of copyright owner]
     18   5084   johnlev  *
     19   5084   johnlev  * CDDL HEADER END
     20   5084   johnlev  */
     21   5084   johnlev 
     22   5084   johnlev /*
     23  10958       dme  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
     24   5084   johnlev  * Use is subject to license terms.
     25   5084   johnlev  *
     26   5084   johnlev  * xnb.h - definitions for Xen dom0 network driver
     27   5084   johnlev  */
     28   5084   johnlev 
     29   5084   johnlev #ifndef _SYS_XNB_H
     30   5084   johnlev #define	_SYS_XNB_H
     31   5084   johnlev 
     32   5084   johnlev #include <sys/types.h>
     33   5084   johnlev #include <sys/kstat.h>
     34   5084   johnlev #include <sys/stream.h>
     35   5084   johnlev #include <sys/ethernet.h>
     36   5084   johnlev #include <sys/hypervisor.h>
     37   5084   johnlev #include <xen/public/io/netif.h>
     38   5084   johnlev 
     39   5084   johnlev #ifdef __cplusplus
     40   5084   johnlev extern "C" {
     41   5084   johnlev #endif
     42   5084   johnlev 
     43   5084   johnlev #define	NET_TX_RING_SIZE  __RING_SIZE((netif_tx_sring_t *)0, PAGESIZE)
     44   5084   johnlev #define	NET_RX_RING_SIZE  __RING_SIZE((netif_rx_sring_t *)0, PAGESIZE)
     45   5084   johnlev 
     46   5084   johnlev #define	XNBMAXPKT	1500		/* MTU size */
     47   5084   johnlev 
     48   5084   johnlev /* DEBUG flags */
     49   5084   johnlev #define	XNBDDI		0x01
     50   5084   johnlev #define	XNBTRACE	0x02
     51   5084   johnlev #define	XNBSEND		0x04
     52   5084   johnlev #define	XNBRECV		0x08
     53   5084   johnlev #define	XNBINTR		0x10
     54   5084   johnlev #define	XNBRING		0x20
     55   5084   johnlev #define	XNBCKSUM	0x40
     56   5084   johnlev 
     57  10958       dme #define	XNB_STATE_INIT	0x01
     58  10958       dme #define	XNB_STATE_READY	0x02
     59  10958       dme 
     60   5084   johnlev typedef struct xnb xnb_t;
     61   5084   johnlev 
     62   5084   johnlev /*
     63   5084   johnlev  * The xnb module provides core inter-domain network protocol functionality.
     64   5084   johnlev  * It is connected to the rest of Solaris in two ways:
     65   5084   johnlev  * - as a GLDv3 driver (with xnbu),
     66   5084   johnlev  * - as a GLDv3 consumer (with xnbo).
     67   5084   johnlev  *
     68   5084   johnlev  * The different modes of operation are termed "flavours" and each
     69   5084   johnlev  * instance of an xnb based driver operates in one and only one mode.
     70   5084   johnlev  * The common xnb driver exports a set of functions to these drivers
     71   5084   johnlev  * (declarations at the foot of this file) and calls back into the
     72   5084   johnlev  * drivers via the xnb_flavour_t structure.
     73   5084   johnlev  */
     74   5084   johnlev typedef struct xnb_flavour {
     75   7615       Max 	void		(*xf_from_peer)(xnb_t *, mblk_t *);
     76  10958       dme 	boolean_t	(*xf_peer_connected)(xnb_t *);
     77   5084   johnlev 	void		(*xf_peer_disconnected)(xnb_t *);
     78   5084   johnlev 	boolean_t	(*xf_hotplug_connected)(xnb_t *);
     79  10958       dme 	boolean_t	(*xf_start_connect)(xnb_t *);
     80   5084   johnlev 	mblk_t		*(*xf_cksum_from_peer)(xnb_t *, mblk_t *, uint16_t);
     81   5084   johnlev 	uint16_t	(*xf_cksum_to_peer)(xnb_t *, mblk_t *);
     82  10958       dme 	boolean_t	(*xf_mcast_add)(xnb_t *, ether_addr_t *);
     83  10958       dme 	boolean_t	(*xf_mcast_del)(xnb_t *, ether_addr_t *);
     84   5084   johnlev } xnb_flavour_t;
     85   5084   johnlev 
     86   7615       Max typedef struct xnb_txbuf {
     87   7615       Max 	frtn_t			xt_free_rtn;
     88   7615       Max 	xnb_t			*xt_xnbp;
     89  10958       dme 	struct xnb_txbuf	*xt_next;
     90   7615       Max 	RING_IDX		xt_id;
     91  10958       dme 	RING_IDX		xt_idx;
     92   7615       Max 	uint16_t		xt_status;
     93  10958       dme 
     94  10958       dme 	ddi_dma_handle_t	xt_dma_handle;
     95  10958       dme 	ddi_acc_handle_t	xt_acc_handle;
     96  10958       dme 	caddr_t			xt_buf;
     97  10958       dme 	size_t			xt_buflen;
     98  10958       dme 	mfn_t			xt_mfn;
     99  10958       dme 
    100  10958       dme 	mblk_t			*xt_mblk;
    101  10958       dme 
    102   7615       Max 	unsigned int		xt_flags;
    103   5084   johnlev 
    104   7615       Max #define	XNB_TXBUF_INUSE	0x01
    105   5084   johnlev 
    106   7615       Max } xnb_txbuf_t;
    107   5084   johnlev 
    108   5084   johnlev /* Per network-interface-controller driver private structure */
    109   5084   johnlev struct xnb {
    110   5084   johnlev 	/* most interesting stuff first to assist debugging */
    111   5741       mrj 	dev_info_t		*xnb_devinfo;	/* System per-device info. */
    112   5084   johnlev 
    113   5741       mrj 	xnb_flavour_t		*xnb_flavour;
    114   5741       mrj 	void			*xnb_flavour_data;
    115   5084   johnlev 
    116   5741       mrj 	boolean_t		xnb_irq;
    117   5741       mrj 	unsigned char		xnb_mac_addr[ETHERADDRL];
    118   5084   johnlev 
    119   5741       mrj 	uint64_t		xnb_stat_ipackets;
    120   5741       mrj 	uint64_t		xnb_stat_opackets;
    121   5741       mrj 	uint64_t		xnb_stat_rbytes;
    122   5741       mrj 	uint64_t		xnb_stat_obytes;
    123   5084   johnlev 
    124   5741       mrj 	uint64_t		xnb_stat_intr;
    125   7615       Max 	uint64_t		xnb_stat_rx_defer;
    126   5084   johnlev 
    127   7615       Max 	uint64_t		xnb_stat_rx_cksum_deferred;
    128   7615       Max 	uint64_t		xnb_stat_tx_cksum_no_need;
    129   5084   johnlev 
    130   7615       Max 	uint64_t		xnb_stat_rx_rsp_notok;
    131   5990  schuster 
    132   5741       mrj 	uint64_t		xnb_stat_tx_notify_sent;
    133   5741       mrj 	uint64_t		xnb_stat_tx_notify_deferred;
    134   5084   johnlev 
    135   5741       mrj 	uint64_t		xnb_stat_rx_notify_sent;
    136   5741       mrj 	uint64_t		xnb_stat_rx_notify_deferred;
    137   5084   johnlev 
    138   5741       mrj 	uint64_t		xnb_stat_tx_too_early;
    139   5741       mrj 	uint64_t		xnb_stat_rx_too_early;
    140   5741       mrj 	uint64_t		xnb_stat_rx_allocb_failed;
    141   5741       mrj 	uint64_t		xnb_stat_tx_allocb_failed;
    142   7615       Max 	uint64_t		xnb_stat_rx_foreign_page;
    143   5741       mrj 	uint64_t		xnb_stat_mac_full;
    144   5741       mrj 	uint64_t		xnb_stat_spurious_intr;
    145   5741       mrj 	uint64_t		xnb_stat_allocation_success;
    146   5741       mrj 	uint64_t		xnb_stat_allocation_failure;
    147   5741       mrj 	uint64_t		xnb_stat_small_allocation_success;
    148   5741       mrj 	uint64_t		xnb_stat_small_allocation_failure;
    149   5741       mrj 	uint64_t		xnb_stat_other_allocation_failure;
    150   5084   johnlev 
    151   7615       Max 	uint64_t		xnb_stat_rx_pagebndry_crossed;
    152   7615       Max 	uint64_t		xnb_stat_rx_cpoparea_grown;
    153   5084   johnlev 
    154   5741       mrj 	uint64_t		xnb_stat_csum_hardware;
    155   5741       mrj 	uint64_t		xnb_stat_csum_software;
    156   5084   johnlev 
    157   5741       mrj 	kstat_t			*xnb_kstat_aux;
    158   5084   johnlev 
    159   5741       mrj 	ddi_iblock_cookie_t	xnb_icookie;
    160   5084   johnlev 
    161   5741       mrj 	kmutex_t		xnb_rx_lock;
    162   5741       mrj 	kmutex_t		xnb_tx_lock;
    163  10958       dme 	kmutex_t		xnb_state_lock;
    164   5084   johnlev 
    165  10958       dme 	int			xnb_be_status;
    166  10958       dme 	int			xnb_fe_status;
    167  10958       dme 
    168  10958       dme 	kmem_cache_t		*xnb_tx_buf_cache;
    169  10958       dme 	uint32_t		xnb_tx_buf_count;
    170  10958       dme 	int			xnb_tx_buf_outstanding;
    171   5084   johnlev 
    172   5741       mrj 	netif_rx_back_ring_t	xnb_rx_ring;	/* rx interface struct ptr */
    173   5741       mrj 	void			*xnb_rx_ring_addr;
    174   5741       mrj 	grant_ref_t		xnb_rx_ring_ref;
    175   5741       mrj 	grant_handle_t		xnb_rx_ring_handle;
    176   5084   johnlev 
    177   5741       mrj 	netif_tx_back_ring_t	xnb_tx_ring;	/* tx interface struct ptr */
    178   5741       mrj 	void			*xnb_tx_ring_addr;
    179   5741       mrj 	grant_ref_t		xnb_tx_ring_ref;
    180   5741       mrj 	grant_handle_t		xnb_tx_ring_handle;
    181   5084   johnlev 
    182   5741       mrj 	boolean_t		xnb_connected;
    183   5741       mrj 	boolean_t		xnb_hotplugged;
    184   5741       mrj 	boolean_t		xnb_detachable;
    185   5741       mrj 	int			xnb_evtchn;	/* channel to front end */
    186  10958       dme 	evtchn_port_t		xnb_fe_evtchn;
    187   5741       mrj 	domid_t			xnb_peer;
    188   5084   johnlev 
    189  10958       dme 	xnb_txbuf_t		*xnb_tx_bufp[NET_TX_RING_SIZE];
    190  10958       dme 	gnttab_copy_t		xnb_tx_cop[NET_TX_RING_SIZE];
    191   5741       mrj 
    192   7615       Max 	caddr_t			xnb_rx_va;
    193   7615       Max 	gnttab_transfer_t	xnb_rx_top[NET_RX_RING_SIZE];
    194   5741       mrj 
    195  10958       dme 	boolean_t		xnb_rx_hv_copy;
    196  10958       dme 	boolean_t		xnb_multicast_control;
    197  10958       dme 	boolean_t		xnb_no_csum_offload;
    198  10958       dme 
    199   7615       Max 	gnttab_copy_t		*xnb_rx_cpop;
    200   5741       mrj #define	CPOP_DEFCNT 	8
    201  10958       dme 	size_t			xnb_rx_cpop_count; 	/* in elements */
    202   5084   johnlev };
    203   5084   johnlev 
    204   5084   johnlev extern int xnb_attach(dev_info_t *, xnb_flavour_t *, void *);
    205   5084   johnlev extern void xnb_detach(dev_info_t *);
    206   5741       mrj extern mblk_t *xnb_copy_to_peer(xnb_t *, mblk_t *);
    207   5084   johnlev extern mblk_t *xnb_process_cksum_flags(xnb_t *, mblk_t *, uint32_t);
    208   5084   johnlev 
    209   5084   johnlev #ifdef __cplusplus
    210   5084   johnlev }
    211   5084   johnlev #endif
    212   5084   johnlev 
    213   5084   johnlev #endif	/* _SYS_XNB_H */
    214