xref: /onnv-gate/usr/src/uts/common/xen/io/xnb.h (revision 11588:618490a7401f)
15084Sjohnlev /*
25084Sjohnlev  * CDDL HEADER START
35084Sjohnlev  *
45084Sjohnlev  * The contents of this file are subject to the terms of the
55084Sjohnlev  * Common Development and Distribution License (the "License").
65084Sjohnlev  * You may not use this file except in compliance with the License.
75084Sjohnlev  *
85084Sjohnlev  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
95084Sjohnlev  * or http://www.opensolaris.org/os/licensing.
105084Sjohnlev  * See the License for the specific language governing permissions
115084Sjohnlev  * and limitations under the License.
125084Sjohnlev  *
135084Sjohnlev  * When distributing Covered Code, include this CDDL HEADER in each
145084Sjohnlev  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
155084Sjohnlev  * If applicable, add the following below this CDDL HEADER, with the
165084Sjohnlev  * fields enclosed by brackets "[]" replaced with your own identifying
175084Sjohnlev  * information: Portions Copyright [yyyy] [name of copyright owner]
185084Sjohnlev  *
195084Sjohnlev  * CDDL HEADER END
205084Sjohnlev  */
215084Sjohnlev 
225084Sjohnlev /*
23*11588Sdavid.edmondson@sun.com  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
245084Sjohnlev  * Use is subject to license terms.
255084Sjohnlev  *
265084Sjohnlev  * xnb.h - definitions for Xen dom0 network driver
275084Sjohnlev  */
285084Sjohnlev 
295084Sjohnlev #ifndef _SYS_XNB_H
305084Sjohnlev #define	_SYS_XNB_H
315084Sjohnlev 
325084Sjohnlev #include <sys/types.h>
335084Sjohnlev #include <sys/kstat.h>
345084Sjohnlev #include <sys/stream.h>
355084Sjohnlev #include <sys/ethernet.h>
365084Sjohnlev #include <sys/hypervisor.h>
375084Sjohnlev #include <xen/public/io/netif.h>
385084Sjohnlev 
395084Sjohnlev #ifdef __cplusplus
405084Sjohnlev extern "C" {
415084Sjohnlev #endif
425084Sjohnlev 
435084Sjohnlev #define	NET_TX_RING_SIZE  __RING_SIZE((netif_tx_sring_t *)0, PAGESIZE)
445084Sjohnlev #define	NET_RX_RING_SIZE  __RING_SIZE((netif_rx_sring_t *)0, PAGESIZE)
455084Sjohnlev 
465084Sjohnlev #define	XNBMAXPKT	1500		/* MTU size */
475084Sjohnlev 
485084Sjohnlev /* DEBUG flags */
495084Sjohnlev #define	XNBDDI		0x01
505084Sjohnlev #define	XNBTRACE	0x02
515084Sjohnlev #define	XNBSEND		0x04
525084Sjohnlev #define	XNBRECV		0x08
535084Sjohnlev #define	XNBINTR		0x10
545084Sjohnlev #define	XNBRING		0x20
555084Sjohnlev #define	XNBCKSUM	0x40
565084Sjohnlev 
5710958Sdme@sun.com #define	XNB_STATE_INIT	0x01
5810958Sdme@sun.com #define	XNB_STATE_READY	0x02
5910958Sdme@sun.com 
605084Sjohnlev typedef struct xnb xnb_t;
615084Sjohnlev 
625084Sjohnlev /*
635084Sjohnlev  * The xnb module provides core inter-domain network protocol functionality.
645084Sjohnlev  * It is connected to the rest of Solaris in two ways:
655084Sjohnlev  * - as a GLDv3 driver (with xnbu),
665084Sjohnlev  * - as a GLDv3 consumer (with xnbo).
675084Sjohnlev  *
685084Sjohnlev  * The different modes of operation are termed "flavours" and each
695084Sjohnlev  * instance of an xnb based driver operates in one and only one mode.
705084Sjohnlev  * The common xnb driver exports a set of functions to these drivers
715084Sjohnlev  * (declarations at the foot of this file) and calls back into the
725084Sjohnlev  * drivers via the xnb_flavour_t structure.
735084Sjohnlev  */
745084Sjohnlev typedef struct xnb_flavour {
757615SMax.Zhen@Sun.COM 	void		(*xf_from_peer)(xnb_t *, mblk_t *);
7610958Sdme@sun.com 	boolean_t	(*xf_peer_connected)(xnb_t *);
775084Sjohnlev 	void		(*xf_peer_disconnected)(xnb_t *);
785084Sjohnlev 	boolean_t	(*xf_hotplug_connected)(xnb_t *);
7910958Sdme@sun.com 	boolean_t	(*xf_start_connect)(xnb_t *);
805084Sjohnlev 	mblk_t		*(*xf_cksum_from_peer)(xnb_t *, mblk_t *, uint16_t);
815084Sjohnlev 	uint16_t	(*xf_cksum_to_peer)(xnb_t *, mblk_t *);
8210958Sdme@sun.com 	boolean_t	(*xf_mcast_add)(xnb_t *, ether_addr_t *);
8310958Sdme@sun.com 	boolean_t	(*xf_mcast_del)(xnb_t *, ether_addr_t *);
845084Sjohnlev } xnb_flavour_t;
855084Sjohnlev 
867615SMax.Zhen@Sun.COM typedef struct xnb_txbuf {
877615SMax.Zhen@Sun.COM 	frtn_t			xt_free_rtn;
887615SMax.Zhen@Sun.COM 	xnb_t			*xt_xnbp;
8910958Sdme@sun.com 	struct xnb_txbuf	*xt_next;
907615SMax.Zhen@Sun.COM 	RING_IDX		xt_id;
9110958Sdme@sun.com 	RING_IDX		xt_idx;
927615SMax.Zhen@Sun.COM 	uint16_t		xt_status;
9310958Sdme@sun.com 
9410958Sdme@sun.com 	ddi_dma_handle_t	xt_dma_handle;
9510958Sdme@sun.com 	ddi_acc_handle_t	xt_acc_handle;
9610958Sdme@sun.com 	caddr_t			xt_buf;
9710958Sdme@sun.com 	size_t			xt_buflen;
9810958Sdme@sun.com 	mfn_t			xt_mfn;
9910958Sdme@sun.com 
10010958Sdme@sun.com 	mblk_t			*xt_mblk;
10110958Sdme@sun.com 
1027615SMax.Zhen@Sun.COM 	unsigned int		xt_flags;
1035084Sjohnlev 
1047615SMax.Zhen@Sun.COM #define	XNB_TXBUF_INUSE	0x01
1055084Sjohnlev 
1067615SMax.Zhen@Sun.COM } xnb_txbuf_t;
1075084Sjohnlev 
1085084Sjohnlev /* Per network-interface-controller driver private structure */
1095084Sjohnlev struct xnb {
1105084Sjohnlev 	/* most interesting stuff first to assist debugging */
1115741Smrj 	dev_info_t		*xnb_devinfo;	/* System per-device info. */
1125084Sjohnlev 
1135741Smrj 	xnb_flavour_t		*xnb_flavour;
1145741Smrj 	void			*xnb_flavour_data;
1155084Sjohnlev 
1165741Smrj 	boolean_t		xnb_irq;
1175741Smrj 	unsigned char		xnb_mac_addr[ETHERADDRL];
1185084Sjohnlev 
1195741Smrj 	uint64_t		xnb_stat_ipackets;
1205741Smrj 	uint64_t		xnb_stat_opackets;
1215741Smrj 	uint64_t		xnb_stat_rbytes;
1225741Smrj 	uint64_t		xnb_stat_obytes;
1235084Sjohnlev 
1245741Smrj 	uint64_t		xnb_stat_intr;
1257615SMax.Zhen@Sun.COM 	uint64_t		xnb_stat_rx_defer;
1265741Smrj 
1277615SMax.Zhen@Sun.COM 	uint64_t		xnb_stat_rx_cksum_deferred;
1287615SMax.Zhen@Sun.COM 	uint64_t		xnb_stat_tx_cksum_no_need;
1295741Smrj 
1307615SMax.Zhen@Sun.COM 	uint64_t		xnb_stat_rx_rsp_notok;
1315990Sschuster 
1325741Smrj 	uint64_t		xnb_stat_tx_notify_sent;
1335741Smrj 	uint64_t		xnb_stat_tx_notify_deferred;
1345084Sjohnlev 
1355741Smrj 	uint64_t		xnb_stat_rx_notify_sent;
1365741Smrj 	uint64_t		xnb_stat_rx_notify_deferred;
1375084Sjohnlev 
1385741Smrj 	uint64_t		xnb_stat_tx_too_early;
1395741Smrj 	uint64_t		xnb_stat_rx_too_early;
1405741Smrj 	uint64_t		xnb_stat_rx_allocb_failed;
1415741Smrj 	uint64_t		xnb_stat_tx_allocb_failed;
1427615SMax.Zhen@Sun.COM 	uint64_t		xnb_stat_rx_foreign_page;
143*11588Sdavid.edmondson@sun.com 	uint64_t		xnb_stat_tx_overflow_page;
144*11588Sdavid.edmondson@sun.com 	uint64_t		xnb_stat_tx_unexpected_flags;
1455741Smrj 	uint64_t		xnb_stat_mac_full;
1465741Smrj 	uint64_t		xnb_stat_spurious_intr;
1475741Smrj 	uint64_t		xnb_stat_allocation_success;
1485741Smrj 	uint64_t		xnb_stat_allocation_failure;
1495741Smrj 	uint64_t		xnb_stat_small_allocation_success;
1505741Smrj 	uint64_t		xnb_stat_small_allocation_failure;
1515741Smrj 	uint64_t		xnb_stat_other_allocation_failure;
1525741Smrj 
1537615SMax.Zhen@Sun.COM 	uint64_t		xnb_stat_rx_pagebndry_crossed;
1547615SMax.Zhen@Sun.COM 	uint64_t		xnb_stat_rx_cpoparea_grown;
1555741Smrj 
1565741Smrj 	uint64_t		xnb_stat_csum_hardware;
1575741Smrj 	uint64_t		xnb_stat_csum_software;
1585084Sjohnlev 
1595741Smrj 	kstat_t			*xnb_kstat_aux;
1605741Smrj 
1615741Smrj 	ddi_iblock_cookie_t	xnb_icookie;
1625084Sjohnlev 
1635741Smrj 	kmutex_t		xnb_rx_lock;
1645741Smrj 	kmutex_t		xnb_tx_lock;
16510958Sdme@sun.com 	kmutex_t		xnb_state_lock;
1665084Sjohnlev 
16710958Sdme@sun.com 	int			xnb_be_status;
16810958Sdme@sun.com 	int			xnb_fe_status;
16910958Sdme@sun.com 
17010958Sdme@sun.com 	kmem_cache_t		*xnb_tx_buf_cache;
17110958Sdme@sun.com 	uint32_t		xnb_tx_buf_count;
17210958Sdme@sun.com 	int			xnb_tx_buf_outstanding;
1735084Sjohnlev 
1745741Smrj 	netif_rx_back_ring_t	xnb_rx_ring;	/* rx interface struct ptr */
1755741Smrj 	void			*xnb_rx_ring_addr;
1765741Smrj 	grant_ref_t		xnb_rx_ring_ref;
1775741Smrj 	grant_handle_t		xnb_rx_ring_handle;
1785084Sjohnlev 
1795741Smrj 	netif_tx_back_ring_t	xnb_tx_ring;	/* tx interface struct ptr */
1805741Smrj 	void			*xnb_tx_ring_addr;
1815741Smrj 	grant_ref_t		xnb_tx_ring_ref;
1825741Smrj 	grant_handle_t		xnb_tx_ring_handle;
1835084Sjohnlev 
1845741Smrj 	boolean_t		xnb_connected;
1855741Smrj 	boolean_t		xnb_hotplugged;
1865741Smrj 	boolean_t		xnb_detachable;
1875741Smrj 	int			xnb_evtchn;	/* channel to front end */
18810958Sdme@sun.com 	evtchn_port_t		xnb_fe_evtchn;
1895741Smrj 	domid_t			xnb_peer;
1905084Sjohnlev 
19110958Sdme@sun.com 	xnb_txbuf_t		*xnb_tx_bufp[NET_TX_RING_SIZE];
19210958Sdme@sun.com 	gnttab_copy_t		xnb_tx_cop[NET_TX_RING_SIZE];
1935084Sjohnlev 
1947615SMax.Zhen@Sun.COM 	caddr_t			xnb_rx_va;
1957615SMax.Zhen@Sun.COM 	gnttab_transfer_t	xnb_rx_top[NET_RX_RING_SIZE];
1965084Sjohnlev 
19710958Sdme@sun.com 	boolean_t		xnb_rx_hv_copy;
19810958Sdme@sun.com 	boolean_t		xnb_multicast_control;
19910958Sdme@sun.com 	boolean_t		xnb_no_csum_offload;
20010958Sdme@sun.com 
2017615SMax.Zhen@Sun.COM 	gnttab_copy_t		*xnb_rx_cpop;
2025741Smrj #define	CPOP_DEFCNT 	8
20310958Sdme@sun.com 	size_t			xnb_rx_cpop_count; 	/* in elements */
2045084Sjohnlev };
2055084Sjohnlev 
2065084Sjohnlev extern int xnb_attach(dev_info_t *, xnb_flavour_t *, void *);
2075084Sjohnlev extern void xnb_detach(dev_info_t *);
2085741Smrj extern mblk_t *xnb_copy_to_peer(xnb_t *, mblk_t *);
2095084Sjohnlev extern mblk_t *xnb_process_cksum_flags(xnb_t *, mblk_t *, uint32_t);
2105084Sjohnlev 
2115084Sjohnlev #ifdef __cplusplus
2125084Sjohnlev }
2135084Sjohnlev #endif
2145084Sjohnlev 
2155084Sjohnlev #endif	/* _SYS_XNB_H */
216