ia64/xen-unstable

changeset 2566:3f0a9708178b

bitkeeper revision 1.1159.1.190 (41584f78c2CzAxiAUPqSlbUeESqryA)

Merge freefall.cl.cam.ac.uk:/auto/groups/xeno/BK/xeno.bk
into freefall.cl.cam.ac.uk:/auto/groups/xeno/users/cl349/BK/xeno.bk-nbsd
author cl349@freefall.cl.cam.ac.uk
date Mon Sep 27 17:35:52 2004 +0000 (2004-09-27)
parents 0a062a592e97 4c917a17da84
children 82cab392896d 653fd1eddd8c e9d6f07d0e52
files .rootkeys netbsd-2.0-xen-sparse/sys/arch/xen/conf/XEN netbsd-2.0-xen-sparse/sys/arch/xen/include/hypervisor.h netbsd-2.0-xen-sparse/sys/arch/xen/include/xbdvar.h netbsd-2.0-xen-sparse/sys/arch/xen/xen/xbd.c
line diff
     1.1 --- a/.rootkeys	Mon Sep 27 16:27:49 2004 +0000
     1.2 +++ b/.rootkeys	Mon Sep 27 17:35:52 2004 +0000
     1.3 @@ -283,6 +283,7 @@ 413cb3b4k9OVRCxuSdhKt-2baTp_Yg netbsd-2.
     1.4  413cb3b4bRsqiHQLTKEZk4-zOksf8A netbsd-2.0-xen-sparse/sys/arch/xen/include/hypervisor.h
     1.5  413cb3b4OqY83qI8GztIZGADpvrpSw netbsd-2.0-xen-sparse/sys/arch/xen/include/if_xennetvar.h
     1.6  413cb3b42GG0LffraTnpZKlSUq57wg netbsd-2.0-xen-sparse/sys/arch/xen/include/pmap.h
     1.7 +41580792kPzxLiPb47k_GDEMSbAbzA netbsd-2.0-xen-sparse/sys/arch/xen/include/xbdvar.h
     1.8  413cb3b4F0ArkWVBRyspkw7ivfXihg netbsd-2.0-xen-sparse/sys/arch/xen/include/xen.h
     1.9  413cb3b4ullQud70n4JClwoEEUBh8Q netbsd-2.0-xen-sparse/sys/arch/xen/include/xenfunc.h
    1.10  413cb3b4y1Ffq8BOhbdSpn-fGmKuEg netbsd-2.0-xen-sparse/sys/arch/xen/include/xenpmap.h
     2.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/conf/XEN	Mon Sep 27 16:27:49 2004 +0000
     2.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/conf/XEN	Mon Sep 27 17:35:52 2004 +0000
     2.3 @@ -132,10 +132,10 @@ npx0		at hypervisor?		# x86 math coproce
     2.4  xencons*	at hypervisor?		# Xen virtual console
     2.5  xennet* 	at hypervisor?		# Xen virtual network interface
     2.6  
     2.7 -#xbd*		at hypervisor?		# Xen virtual block device
     2.8 -#wd*		at hypervisor?		# Xen vbd (wd identity)
     2.9 -#sd*		at hypervisor?		# Xen vbd (sd identity)
    2.10 -#cd*		at hypervisor?		# Xen vbd (cd identity)
    2.11 +xbd*		at hypervisor?		# Xen virtual block device
    2.12 +wd*		at hypervisor?		# Xen vbd (wd identity)
    2.13 +sd*		at hypervisor?		# Xen vbd (sd identity)
    2.14 +cd*		at hypervisor?		# Xen vbd (cd identity)
    2.15  
    2.16  #xenkbc* 	at hypervisor?		# Xen Keyboard/Mouse Interface
    2.17  #pckbd*		at xenkbc?		# Keyboard
     3.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/include/hypervisor.h	Mon Sep 27 16:27:49 2004 +0000
     3.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/include/hypervisor.h	Mon Sep 27 17:35:52 2004 +0000
     3.3 @@ -59,6 +59,7 @@ struct xen_npx_attach_args {
     3.4  #include <machine/hypervisor-ifs/event_channel.h>
     3.5  #include <machine/hypervisor-ifs/io/domain_controller.h>
     3.6  #include <machine/hypervisor-ifs/io/netif.h>
     3.7 +#include <machine/hypervisor-ifs/io/blkif.h>
     3.8  
     3.9  #undef u8
    3.10  #undef u16
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/include/xbdvar.h	Mon Sep 27 17:35:52 2004 +0000
     4.3 @@ -0,0 +1,56 @@
     4.4 +/* $NetBSD: xbdvar.h,v 1.5 2004/05/07 14:15:11 cl Exp $ */
     4.5 +
     4.6 +/*
     4.7 + *
     4.8 + * Copyright (c) 2004 Christian Limpach.
     4.9 + * All rights reserved.
    4.10 + *
    4.11 + * Redistribution and use in source and binary forms, with or without
    4.12 + * modification, are permitted provided that the following conditions
    4.13 + * are met:
    4.14 + * 1. Redistributions of source code must retain the above copyright
    4.15 + *    notice, this list of conditions and the following disclaimer.
    4.16 + * 2. Redistributions in binary form must reproduce the above copyright
    4.17 + *    notice, this list of conditions and the following disclaimer in the
    4.18 + *    documentation and/or other materials provided with the distribution.
    4.19 + * 3. All advertising materials mentioning features or use of this software
    4.20 + *    must display the following acknowledgement:
    4.21 + *      This product includes software developed by Christian Limpach.
    4.22 + * 4. The name of the author may not be used to endorse or promote products
    4.23 + *    derived from this software without specific prior written permission.
    4.24 + *
    4.25 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    4.26 + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    4.27 + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    4.28 + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
    4.29 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
    4.30 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    4.31 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    4.32 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    4.33 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    4.34 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    4.35 + */
    4.36 +
    4.37 +
    4.38 +#ifndef _XEN_XBDVAR_H_
    4.39 +#define _XEN_XBDVAR_H_
    4.40 +
    4.41 +struct xbd_softc {
    4.42 +	struct device		sc_dev;		/* base device glue */
    4.43 +	struct dk_softc		sc_dksc;	/* generic disk interface */
    4.44 +	unsigned long		sc_xd_device;	/* cookie identifying device */
    4.45 +	struct dk_intf		*sc_di;		/* pseudo-disk interface */
    4.46 +	struct simplelock	sc_slock;	/* our lock */
    4.47 +	int			sc_shutdown;	/* about to be removed */
    4.48 +};
    4.49 +
    4.50 +struct xbd_attach_args {
    4.51 +	const char 		*xa_device;
    4.52 +	vdisk_t			*xa_xd;
    4.53 +	struct dk_intf		*xa_dkintf;
    4.54 +	struct sysctlnode	*xa_diskcookies;
    4.55 +};
    4.56 +
    4.57 +int xbd_scan(struct device *, struct xbd_attach_args *, cfprint_t);
    4.58 +
    4.59 +#endif /* _XEN_XBDVAR_H_ */
     5.1 --- a/netbsd-2.0-xen-sparse/sys/arch/xen/xen/xbd.c	Mon Sep 27 16:27:49 2004 +0000
     5.2 +++ b/netbsd-2.0-xen-sparse/sys/arch/xen/xen/xbd.c	Mon Sep 27 17:35:52 2004 +0000
     5.3 @@ -63,13 +63,16 @@
     5.4  
     5.5  #include <dev/dkvar.h>
     5.6  #include <machine/xbdvar.h>
     5.7 +
     5.8  #include <machine/xen.h>
     5.9  #include <machine/hypervisor.h>
    5.10 -#include <machine/hypervisor-ifs/hypervisor-if.h>
    5.11 -#include <machine/hypervisor-ifs/vbd.h>
    5.12  #include <machine/evtchn.h>
    5.13 +#include <machine/ctrl_if.h>
    5.14  
    5.15  
    5.16 +static void	control_send(blkif_request_t *, blkif_response_t *);
    5.17 +static void	send_interface_connect(void);
    5.18 +
    5.19  static void xbd_attach(struct device *, struct device *, void *);
    5.20  static int xbd_detach(struct device *, int);
    5.21  
    5.22 @@ -178,11 +181,13 @@ static dev_t xbd_cd_cdev_major;
    5.23  
    5.24  static int	xbdstart(struct dk_softc *, struct buf *);
    5.25  static int	xbd_response_handler(void *);
    5.26 +#if 0
    5.27  static void	xbd_update_create_kthread(void *);
    5.28  static void	xbd_update_kthread(void *);
    5.29  static int	xbd_update_handler(void *);
    5.30 +#endif
    5.31  
    5.32 -static int	xbdinit(struct xbd_softc *, xen_disk_t *, struct dk_intf *);
    5.33 +static int	xbdinit(struct xbd_softc *, vdisk_t *, struct dk_intf *);
    5.34  
    5.35  /* Pseudo-disk Interface */
    5.36  static struct dk_intf dkintf_esdi = {
    5.37 @@ -346,18 +351,32 @@ static int bufq_users = 0;
    5.38  
    5.39  #define MAX_VBDS 64
    5.40  static int nr_vbds;
    5.41 -static xen_disk_t *vbd_info;
    5.42 +static vdisk_t *vbd_info;
    5.43 +
    5.44 +static blkif_ring_t *blk_ring = NULL;
    5.45 +static BLKIF_RING_IDX resp_cons; /* Response consumer for comms ring. */
    5.46 +static BLKIF_RING_IDX req_prod;  /* Private request producer.         */
    5.47 +static BLKIF_RING_IDX last_req_prod;  /* Request producer at last trap. */
    5.48  
    5.49 -static blk_ring_t *blk_ring = NULL;
    5.50 -static BLK_RING_IDX resp_cons; /* Response consumer for comms ring. */
    5.51 -static BLK_RING_IDX req_prod;  /* Private request producer.         */
    5.52 -static BLK_RING_IDX last_req_prod;  /* Request producer at last trap. */
    5.53 +#define STATE_CLOSED		0
    5.54 +#define STATE_DISCONNECTED	1
    5.55 +#define STATE_CONNECTED		2
    5.56 +static unsigned int state = STATE_CLOSED;
    5.57 +static unsigned int blkif_evtchn = 0;
    5.58 +static unsigned int blkif_irq = 0;
    5.59 +static unsigned int blkif_handle = 0;
    5.60  
    5.61 -#define STATE_ACTIVE    0
    5.62 -#define STATE_SUSPENDED 1
    5.63 -#define STATE_CLOSED    2
    5.64 -static unsigned int state = STATE_SUSPENDED;
    5.65 +static int blkif_control_rsp_valid = 0;
    5.66 +static blkif_response_t blkif_control_rsp;
    5.67 +
    5.68 +/** Network interface info. */
    5.69 +struct xbd_ctrl {
    5.70  
    5.71 +	cfprint_t xc_cfprint;
    5.72 +	struct device *xc_parent;
    5.73 +};
    5.74 +
    5.75 +static struct xbd_ctrl blkctrl;
    5.76  
    5.77  #define XBDUNIT(x)		DISKUNIT(x)
    5.78  #define GETXBD_SOFTC(_xs, x)	if (!((_xs) = getxbd_softc(x))) return ENXIO
    5.79 @@ -396,70 +415,317 @@ getxbd_softc(dev_t dev)
    5.80  }
    5.81  
    5.82  static int
    5.83 -get_vbd_info(xen_disk_t *disk_info)
    5.84 +get_vbd_info(vdisk_t *disk_info)
    5.85  {
    5.86 -	int err;
    5.87 -	block_io_op_t op; 
    5.88 +	vdisk_t *buf;
    5.89 +	int nr;
    5.90 +	blkif_request_t req;
    5.91 +	blkif_response_t rsp;
    5.92 +	paddr_t pa;
    5.93  
    5.94 +	buf = (vdisk_t *)uvm_km_kmemalloc1(kmem_map, NULL,
    5.95 +	    PAGE_SIZE, PAGE_SIZE, UVM_UNKNOWN_OFFSET, 0);
    5.96 +	pmap_extract(pmap_kernel(), (vaddr_t)buf, &pa);
    5.97  	/* Probe for disk information. */
    5.98 -	memset(&op, 0, sizeof(op)); 
    5.99 -	op.cmd = BLOCK_IO_OP_VBD_PROBE; 
   5.100 -	op.u.probe_params.domain = 0; 
   5.101 -	op.u.probe_params.xdi.max = MAX_VBDS;
   5.102 -	op.u.probe_params.xdi.disks = disk_info;
   5.103 -	op.u.probe_params.xdi.count = 0;
   5.104 +	memset(&req, 0, sizeof(req));
   5.105 +	req.operation = BLKIF_OP_PROBE;
   5.106 +	req.nr_segments = 1;
   5.107 +	req.frame_and_sects[0] = xpmap_ptom_masked(pa) | 7;
   5.108 +
   5.109 +	control_send(&req, &rsp);
   5.110 +	nr = rsp.status > MAX_VBDS ? MAX_VBDS : rsp.status;
   5.111 +
   5.112 +	if (rsp.status < 0)
   5.113 +		printf("WARNING: Could not probe disks (%d)\n", rsp.status);
   5.114 +
   5.115 +	memcpy(disk_info, buf, nr * sizeof(vdisk_t));
   5.116 +
   5.117 +	uvm_km_free(kmem_map, (vaddr_t)buf, PAGE_SIZE);
   5.118 +
   5.119 +	return nr;
   5.120 +}
   5.121 +
   5.122 +static struct xbd_attach_args *
   5.123 +get_xbda(vdisk_t *xd)
   5.124 +{
   5.125  
   5.126 -	err = HYPERVISOR_block_io_op(&op);
   5.127 -	if (err) {
   5.128 -		printf("WARNING: Could not probe disks (%d)\n", err);
   5.129 -		DIAGPANIC(("get_vbd_info: Could not probe disks (%d)", err));
   5.130 -		return -1;
   5.131 +	switch (XEN_MAJOR(xd->device)) {
   5.132 +#if NSD > 0
   5.133 +	case XEN_SCSI_DISK0_MAJOR:
   5.134 +	case XEN_SCSI_DISK1_MAJOR ... XEN_SCSI_DISK7_MAJOR:
   5.135 +	case XEN_SCSI_DISK8_MAJOR ... XEN_SCSI_DISK15_MAJOR:
   5.136 +		if (xd->capacity == 0)
   5.137 +			return NULL;
   5.138 +		return &sd_ata;
   5.139 +	case XEN_SCSI_CDROM_MAJOR:
   5.140 +		return &cd_ata;
   5.141 +#endif
   5.142 +#if NWD > 0
   5.143 +	case XEN_IDE0_MAJOR:
   5.144 +	case XEN_IDE1_MAJOR:
   5.145 +	case XEN_IDE2_MAJOR:
   5.146 +	case XEN_IDE3_MAJOR:
   5.147 +	case XEN_IDE4_MAJOR:
   5.148 +	case XEN_IDE5_MAJOR:
   5.149 +	case XEN_IDE6_MAJOR:
   5.150 +	case XEN_IDE7_MAJOR:
   5.151 +	case XEN_IDE8_MAJOR:
   5.152 +	case XEN_IDE9_MAJOR:
   5.153 +		switch (VDISK_TYPE(xd->info)) {
   5.154 +		case VDISK_TYPE_CDROM:
   5.155 +			return &cd_ata;
   5.156 +		case VDISK_TYPE_DISK:
   5.157 +			if (xd->capacity == 0)
   5.158 +				return NULL;
   5.159 +			return &wd_ata;
   5.160 +		default:
   5.161 +			return NULL;
   5.162 +		}
   5.163 +		break;
   5.164 +#endif
   5.165 +	default:
   5.166 +		if (xd->capacity == 0)
   5.167 +			return NULL;
   5.168 +		return &xbd_ata;
   5.169 +	}
   5.170 +	return NULL;
   5.171 +}
   5.172 +
   5.173 +static void
   5.174 +free_interface(void)
   5.175 +{
   5.176 +
   5.177 +	/* Prevent new requests being issued until we fix things up. */
   5.178 +	// simple_lock(&blkif_io_lock);
   5.179 +	// recovery = 1;
   5.180 +	state = STATE_DISCONNECTED;
   5.181 +	// simple_unlock(&blkif_io_lock);
   5.182 +
   5.183 +	/* Free resources associated with old device channel. */
   5.184 +	if (blk_ring) {
   5.185 +		uvm_km_free(kmem_map, (vaddr_t)blk_ring, PAGE_SIZE);
   5.186 +		blk_ring = NULL;
   5.187  	}
   5.188  
   5.189 -	return op.u.probe_params.xdi.count;
   5.190 +	if (blkif_irq) {
   5.191 +#if 0
   5.192 +		free_irq(blkif_irq, NULL);
   5.193 +#endif
   5.194 +		blkif_irq = 0;
   5.195 +	}
   5.196 +
   5.197 +	if (blkif_evtchn) {
   5.198 +#if 0
   5.199 +		unbind_evtchn_from_irq(blkif_evtchn);
   5.200 +#endif
   5.201 +		blkif_evtchn = 0;
   5.202 +	}
   5.203 +}
   5.204 +
   5.205 +static void
   5.206 +close_interface(void){
   5.207 +}
   5.208 +
   5.209 +static void
   5.210 +disconnect_interface(void)
   5.211 +{
   5.212 +
   5.213 +	if (blk_ring == NULL)
   5.214 +		blk_ring = (blkif_ring_t *)uvm_km_kmemalloc1(kmem_map, NULL,
   5.215 +		    PAGE_SIZE, PAGE_SIZE, UVM_UNKNOWN_OFFSET, 0);
   5.216 +	memset(blk_ring, 0, PAGE_SIZE);
   5.217 +	blk_ring->req_prod = blk_ring->resp_prod = resp_cons = req_prod =
   5.218 +		last_req_prod = 0;
   5.219 +	state = STATE_DISCONNECTED;
   5.220 +	send_interface_connect();
   5.221  }
   5.222  
   5.223  static void
   5.224  reset_interface(void)
   5.225  {
   5.226 -	block_io_op_t op; 
   5.227 +
   5.228 +	printf("Recovering virtual block device driver\n");
   5.229 +	free_interface();
   5.230 +	disconnect_interface();
   5.231 +}
   5.232 +
   5.233 +static void
   5.234 +connect_interface(blkif_fe_interface_status_t *status)
   5.235 +{
   5.236 +	// unsigned long flags;
   5.237 +	struct xbd_attach_args *xbda;
   5.238 +	vdisk_t *xd;
   5.239 +	int i;
   5.240 +
   5.241 +	blkif_evtchn = status->evtchn;
   5.242 +	blkif_irq = bind_evtchn_to_irq(blkif_evtchn);
   5.243 +
   5.244 +	event_set_handler(blkif_irq, &xbd_response_handler, NULL, IPL_BIO);
   5.245 +	hypervisor_enable_irq(blkif_irq);
   5.246 +
   5.247 +	/* Transition to connected in case we need to do 
   5.248 +	 *  a partition probe on a whole disk. */
   5.249 +	state = STATE_CONNECTED;
   5.250  
   5.251 -	op.cmd = BLOCK_IO_OP_RESET;
   5.252 -	if (HYPERVISOR_block_io_op(&op) != 0)
   5.253 -		printf("xbd: Possible blkdev trouble: couldn't reset ring\n");
   5.254 +	/* Probe for discs attached to the interface. */
   5.255 +	// xlvbd_init();
   5.256 +	MALLOC(vbd_info, vdisk_t *, MAX_VBDS * sizeof(vdisk_t),
   5.257 +	    M_DEVBUF, M_WAITOK);
   5.258 +	memset(vbd_info, 0, MAX_VBDS * sizeof(vdisk_t));
   5.259 +	nr_vbds  = get_vbd_info(vbd_info);
   5.260 +	if (nr_vbds <= 0)
   5.261 +		goto out;
   5.262 +
   5.263 +	for (i = 0; i < nr_vbds; i++) {
   5.264 +		xd = &vbd_info[i];
   5.265 +		xbda = get_xbda(xd);
   5.266 +		if (xbda) {
   5.267 +			xbda->xa_xd = xd;
   5.268 +			config_found(blkctrl.xc_parent, xbda,
   5.269 +			    blkctrl.xc_cfprint);
   5.270 +		}
   5.271 +	}
   5.272 +
   5.273 +#if 0
   5.274 +	/* Kick pending requests. */
   5.275 +	save_and_cli(flags);
   5.276 +	// simple_lock(&blkif_io_lock);
   5.277 +	kick_pending_request_queues();
   5.278 +	// simple_unlock(&blkif_io_lock);
   5.279 +	restore_flags(flags);
   5.280 +#endif
   5.281 +	return;
   5.282 +
   5.283 + out:
   5.284 +	FREE(vbd_info, M_DEVBUF);
   5.285 +	vbd_info = NULL;
   5.286 +	return;
   5.287  }
   5.288  
   5.289  static void
   5.290 -init_interface(void)
   5.291 +unexpected(blkif_fe_interface_status_t *status)
   5.292  {
   5.293 -	block_io_op_t op; 
   5.294 +
   5.295 +	printf("Unexpected blkif status %d in state %d\n", 
   5.296 +	    status->status, state);
   5.297 +}
   5.298  
   5.299 -	reset_interface();
   5.300 -
   5.301 -	if (blk_ring == NULL) {
   5.302 -		op.cmd = BLOCK_IO_OP_RING_ADDRESS;
   5.303 -		(void)HYPERVISOR_block_io_op(&op);
   5.304 +#if 0
   5.305 +static struct device *
   5.306 +find_device(vdisk_t *xd)
   5.307 +{
   5.308 +	struct device *dv;
   5.309 +	struct xbd_softc *xs = NULL;
   5.310  
   5.311 -		blk_ring = (blk_ring_t *)uvm_km_valloc_align(kernel_map,
   5.312 -		    PAGE_SIZE, PAGE_SIZE);
   5.313 -		pmap_kenter_ma((vaddr_t)blk_ring, op.u.ring_mfn << PAGE_SHIFT,
   5.314 -		    VM_PROT_READ|VM_PROT_WRITE);
   5.315 -		DPRINTF(XBDB_SETUP, ("init_interface: "
   5.316 -		    "ring va %p and wired to %p\n",
   5.317 -		    blk_ring, (void *)(op.u.ring_mfn << PAGE_SHIFT)));
   5.318 +	for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
   5.319 +		if (dv->dv_cfattach == NULL ||
   5.320 +		    dv->dv_cfattach->ca_attach != xbd_attach)
   5.321 +			continue;
   5.322 +		xs = (struct xbd_softc *)dv;
   5.323 +		if (xd == NULL || xs->sc_xd_device == xd->device)
   5.324 +			break;
   5.325 +	}
   5.326 +	return dv;
   5.327 +}
   5.328 +#endif
   5.329  
   5.330 -		blk_ring->req_prod = blk_ring->resp_prod =
   5.331 -			resp_cons = req_prod = last_req_prod = 0;
   5.332 +static void
   5.333 +blkif_status(blkif_fe_interface_status_t *status)
   5.334 +{
   5.335  
   5.336 -		event_set_handler(_EVENT_BLKDEV, &xbd_response_handler,
   5.337 -		    NULL, IPL_BIO);
   5.338 -		hypervisor_enable_event(_EVENT_BLKDEV);
   5.339 +	if (status->handle != blkif_handle) {
   5.340 +		printf("Invalid blkif: handle=%u", status->handle);
   5.341 +		return;
   5.342  	}
   5.343  
   5.344 -	__insn_barrier();
   5.345 -	state = STATE_ACTIVE;
   5.346 +	switch (status->status) {
   5.347 +	case BLKIF_INTERFACE_STATUS_CLOSED:
   5.348 +		switch (state) {
   5.349 +		case STATE_CLOSED:
   5.350 +			unexpected(status);
   5.351 +			break;
   5.352 +		case STATE_DISCONNECTED:
   5.353 +		case STATE_CONNECTED:
   5.354 +			unexpected(status);
   5.355 +			close_interface();
   5.356 +			break;
   5.357 +		}
   5.358 +		break;
   5.359 +
   5.360 +	case BLKIF_INTERFACE_STATUS_DISCONNECTED:
   5.361 +		switch (state) {
   5.362 +		case STATE_CLOSED:
   5.363 +			disconnect_interface();
   5.364 +			break;
   5.365 +		case STATE_DISCONNECTED:
   5.366 +		case STATE_CONNECTED:
   5.367 +			unexpected(status);
   5.368 +			reset_interface();
   5.369 +			break;
   5.370 +		}
   5.371 +		break;
   5.372 +
   5.373 +	case BLKIF_INTERFACE_STATUS_CONNECTED:
   5.374 +		switch (state) {
   5.375 +		case STATE_CLOSED:
   5.376 +			unexpected(status);
   5.377 +			disconnect_interface();
   5.378 +			connect_interface(status);
   5.379 +			break;
   5.380 +		case STATE_DISCONNECTED:
   5.381 +			connect_interface(status);
   5.382 +			break;
   5.383 +		case STATE_CONNECTED:
   5.384 +			unexpected(status);
   5.385 +			connect_interface(status);
   5.386 +			break;
   5.387 +		}
   5.388 +		break;
   5.389 +
   5.390 +	case BLKIF_INTERFACE_STATUS_CHANGED:
   5.391 +		switch (state) {
   5.392 +		case STATE_CLOSED:
   5.393 +		case STATE_DISCONNECTED:
   5.394 +			unexpected(status);
   5.395 +			break;
   5.396 +		case STATE_CONNECTED:
   5.397 +#if 0
   5.398 +			vbd_update();
   5.399 +#endif
   5.400 +			break;
   5.401 +		}
   5.402 +		break;
   5.403 +
   5.404 +	default:
   5.405 +		printf(" Invalid blkif status: %d\n", status->status);
   5.406 +		break;
   5.407 +	}
   5.408  }
   5.409  
   5.410 +
   5.411 +static void
   5.412 +xbd_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
   5.413 +{
   5.414 +	switch (msg->subtype) {
   5.415 +	case CMSG_BLKIF_FE_INTERFACE_STATUS:
   5.416 +		if (msg->length != sizeof(blkif_fe_interface_status_t))
   5.417 +			goto parse_error;
   5.418 +		blkif_status((blkif_fe_interface_status_t *)
   5.419 +		    &msg->msg[0]);
   5.420 +		break;        
   5.421 +	default:
   5.422 +		goto parse_error;
   5.423 +	}
   5.424 +
   5.425 +	ctrl_if_send_response(msg);
   5.426 +	return;
   5.427 +
   5.428 + parse_error:
   5.429 +	msg->length = 0;
   5.430 +	ctrl_if_send_response(msg);
   5.431 +}
   5.432 +
   5.433 +#if 0
   5.434  static void
   5.435  enable_update_events(struct device *self)
   5.436  {
   5.437 @@ -468,23 +734,109 @@ enable_update_events(struct device *self
   5.438  	event_set_handler(_EVENT_VBD_UPD, &xbd_update_handler, self, IPL_BIO);
   5.439  	hypervisor_enable_event(_EVENT_VBD_UPD);
   5.440  }
   5.441 +#endif
   5.442  
   5.443  static void
   5.444  signal_requests_to_xen(void)
   5.445  {
   5.446 -	block_io_op_t op; 
   5.447  
   5.448 -	DPRINTF(XBDB_IO, ("signal_requests_to_xen: %d -> %d\n",
   5.449 -	    blk_ring->req_prod, MASK_BLK_IDX(req_prod)));
   5.450 -	blk_ring->req_prod = MASK_BLK_IDX(req_prod);
   5.451 +	DPRINTF(XBDB_IO, ("signal_requests_to_xen: %x -> %x\n",
   5.452 +		    blk_ring->req_prod, req_prod));
   5.453 +	blk_ring->req_prod = req_prod;
   5.454  	last_req_prod = req_prod;
   5.455  
   5.456 -	op.cmd = BLOCK_IO_OP_SIGNAL; 
   5.457 -	HYPERVISOR_block_io_op(&op);
   5.458 +	hypervisor_notify_via_evtchn(blkif_evtchn);
   5.459  	return;
   5.460  }
   5.461  
   5.462  static void
   5.463 +control_send(blkif_request_t *req, blkif_response_t *rsp)
   5.464 +{
   5.465 +	unsigned long flags;
   5.466 +	struct xbdreq *xr;
   5.467 +
   5.468 + retry:
   5.469 +	while ((req_prod - resp_cons) == BLKIF_RING_SIZE) {
   5.470 +		tsleep((caddr_t) &req_prod, PUSER | PCATCH,
   5.471 +		    "blkfront", 0);
   5.472 +	}
   5.473 +
   5.474 +	save_and_cli(flags);
   5.475 +	// simple_lock(&blkif_io_lock);
   5.476 +	if ((req_prod - resp_cons) == BLKIF_RING_SIZE) {
   5.477 +		// simple_unlock(&blkif_io_lock);
   5.478 +		restore_flags(flags);
   5.479 +		goto retry;
   5.480 +	}
   5.481 +
   5.482 +	blk_ring->ring[MASK_BLKIF_IDX(req_prod)].req = *req;    
   5.483 +
   5.484 +	GET_XBDREQ(xr);
   5.485 +	blk_ring->ring[MASK_BLKIF_IDX(req_prod)].req.id = (unsigned long)xr;
   5.486 +	// rec_ring[id].id = (unsigned long) req;
   5.487 +
   5.488 +	// translate_req_to_pfn( &rec_ring[id], req );
   5.489 +
   5.490 +	req_prod++;
   5.491 +	signal_requests_to_xen();
   5.492 +
   5.493 +	// simple_unlock(&blkif_io_lock);
   5.494 +	restore_flags(flags);
   5.495 +
   5.496 +	while (!blkif_control_rsp_valid) {
   5.497 +		/* XXXcl: sleep/wakeup not ready yet - busy wait for now.
   5.498 +		 * interrupts are still of, so we pick up the control
   5.499 +		 * channel response on return from HYPERVISOR_yield().
   5.500 +		 */
   5.501 +#if 0
   5.502 +		tsleep((caddr_t)&blkif_control_rsp_valid, PUSER | PCATCH,
   5.503 +		    "blkfront", 0);
   5.504 +#else
   5.505 +		HYPERVISOR_yield();
   5.506 +#endif
   5.507 +	}
   5.508 +
   5.509 +	memcpy(rsp, &blkif_control_rsp, sizeof(*rsp));
   5.510 +	blkif_control_rsp_valid = 0;
   5.511 +}
   5.512 +
   5.513 +/* Send a driver status notification to the domain controller. */
   5.514 +static void
   5.515 +send_driver_status(int ok)
   5.516 +{
   5.517 +	ctrl_msg_t cmsg = {
   5.518 +		.type    = CMSG_BLKIF_FE,
   5.519 +		.subtype = CMSG_BLKIF_FE_DRIVER_STATUS,
   5.520 +		.length  = sizeof(blkif_fe_driver_status_t),
   5.521 +	};
   5.522 +	blkif_fe_driver_status_t *msg = (void*)cmsg.msg;
   5.523 +    
   5.524 +	msg->status = ok ? BLKIF_DRIVER_STATUS_UP : BLKIF_DRIVER_STATUS_DOWN;
   5.525 +
   5.526 +	ctrl_if_send_message_block(&cmsg, NULL, 0, 0);
   5.527 +}
   5.528 +
   5.529 +/* Tell the controller to bring up the interface. */
   5.530 +static void
   5.531 +send_interface_connect(void)
   5.532 +{
   5.533 +	ctrl_msg_t cmsg = {
   5.534 +		.type    = CMSG_BLKIF_FE,
   5.535 +		.subtype = CMSG_BLKIF_FE_INTERFACE_CONNECT,
   5.536 +		.length  = sizeof(blkif_fe_interface_connect_t),
   5.537 +	};
   5.538 +	blkif_fe_interface_connect_t *msg = (void*)cmsg.msg;
   5.539 +    	paddr_t pa;
   5.540 +
   5.541 +	pmap_extract(pmap_kernel(), (vaddr_t)blk_ring, &pa);
   5.542 +
   5.543 +	msg->handle = 0;
   5.544 +	msg->shmem_frame = xpmap_ptom_masked(pa) >> PAGE_SHIFT;
   5.545 +
   5.546 +	ctrl_if_send_message_block(&cmsg, NULL, 0, 0);
   5.547 +}
   5.548 +
   5.549 +static void
   5.550  setup_sysctl(void)
   5.551  {
   5.552  	struct sysctlnode *pnode;
   5.553 @@ -514,62 +866,16 @@ setup_sysctl(void)
   5.554  		diskcookies = pnode;
   5.555  }
   5.556  
   5.557 -static struct xbd_attach_args *
   5.558 -get_xbda(xen_disk_t *xd)
   5.559 -{
   5.560 -
   5.561 -	switch (XEN_MAJOR(xd->device)) {
   5.562 -#if NSD > 0
   5.563 -	case XEN_SCSI_DISK0_MAJOR:
   5.564 -	case XEN_SCSI_DISK1_MAJOR ... XEN_SCSI_DISK7_MAJOR:
   5.565 -	case XEN_SCSI_DISK8_MAJOR ... XEN_SCSI_DISK15_MAJOR:
   5.566 -		if (xd->capacity == 0)
   5.567 -			return NULL;
   5.568 -		return &sd_ata;
   5.569 -	case XEN_SCSI_CDROM_MAJOR:
   5.570 -		return &cd_ata;
   5.571 -#endif
   5.572 -#if NWD > 0
   5.573 -	case XEN_IDE0_MAJOR:
   5.574 -	case XEN_IDE1_MAJOR:
   5.575 -	case XEN_IDE2_MAJOR:
   5.576 -	case XEN_IDE3_MAJOR:
   5.577 -	case XEN_IDE4_MAJOR:
   5.578 -	case XEN_IDE5_MAJOR:
   5.579 -	case XEN_IDE6_MAJOR:
   5.580 -	case XEN_IDE7_MAJOR:
   5.581 -	case XEN_IDE8_MAJOR:
   5.582 -	case XEN_IDE9_MAJOR:
   5.583 -		switch (XD_TYPE(xd->info)) {
   5.584 -		case XD_TYPE_CDROM:
   5.585 -			return &cd_ata;
   5.586 -		case XD_TYPE_DISK:
   5.587 -			if (xd->capacity == 0)
   5.588 -				return NULL;
   5.589 -			return &wd_ata;
   5.590 -		default:
   5.591 -			return NULL;
   5.592 -		}
   5.593 -		break;
   5.594 -#endif
   5.595 -	default:
   5.596 -		if (xd->capacity == 0)
   5.597 -			return NULL;
   5.598 -		return &xbd_ata;
   5.599 -	}
   5.600 -	return NULL;
   5.601 -}
   5.602 -
   5.603  int
   5.604  xbd_scan(struct device *self, struct xbd_attach_args *mainbus_xbda,
   5.605      cfprint_t print)
   5.606  {
   5.607  	struct xbdreq *xr;
   5.608 -	struct xbd_attach_args *xbda;
   5.609 -	xen_disk_t *xd;
   5.610  	int i;
   5.611  
   5.612 -	init_interface();
   5.613 +	blkctrl.xc_parent = self;
   5.614 +	blkctrl.xc_cfprint = print;
   5.615 +
   5.616  	if (xen_start_info.flags & SIF_PRIVILEGED)
   5.617  		setup_sysctl();
   5.618  
   5.619 @@ -593,48 +899,24 @@ xbd_scan(struct device *self, struct xbd
   5.620  	xbd_cd_cdev_major = major(devsw_blk2chr(makedev(xbd_cd_major, 0)));
   5.621  #endif
   5.622  
   5.623 -	MALLOC(xr, struct xbdreq *, BLK_RING_SIZE * sizeof(struct xbdreq),
   5.624 +	MALLOC(xr, struct xbdreq *, BLKIF_RING_SIZE * sizeof(struct xbdreq),
   5.625  	    M_DEVBUF, M_WAITOK | M_ZERO);
   5.626  #ifdef DEBUG
   5.627  	xbd_allxr = xr;
   5.628  #endif
   5.629 -
   5.630 -	/* XXX Xen1.2: We cannot use BLK_RING_SIZE many slots, since
   5.631 -	 * Xen 1.2 keeps indexes masked in the ring and the case where
   5.632 -	 * we queue all slots at once is handled wrong. 
   5.633 -	 */
   5.634 -	for (i = 0; i < BLK_RING_SIZE - 1; i++)
   5.635 +	for (i = 0; i < BLKIF_RING_SIZE - 1; i++)
   5.636  		PUT_XBDREQ(&xr[i]);
   5.637  
   5.638 -	MALLOC(vbd_info, xen_disk_t *, MAX_VBDS * sizeof(xen_disk_t),
   5.639 -	    M_DEVBUF, M_WAITOK);
   5.640 -	memset(vbd_info, 0, MAX_VBDS * sizeof(xen_disk_t));
   5.641 -	nr_vbds  = get_vbd_info(vbd_info);
   5.642 -	if (nr_vbds <= 0)
   5.643 -		goto out;
   5.644 +	(void)ctrl_if_register_receiver(CMSG_BLKIF_FE, xbd_ctrlif_rx,
   5.645 +	    CALLBACK_IN_BLOCKING_CONTEXT);
   5.646 +
   5.647 +	send_driver_status(1);
   5.648  
   5.649 -	for (i = 0; i < nr_vbds; i++) {
   5.650 -		xd = &vbd_info[i];
   5.651 -		xbda = get_xbda(xd);
   5.652 -		if (xbda) {
   5.653 -			xbda->xa_xd = xd;
   5.654 -			config_found(self, xbda, print);
   5.655 -		}
   5.656 -	}
   5.657 -
   5.658 +#if 0
   5.659  	enable_update_events(self);
   5.660 +#endif
   5.661  
   5.662  	return 0;
   5.663 -
   5.664 - out:
   5.665 -	FREE(vbd_info, M_DEVBUF);
   5.666 -	vbd_info = NULL;
   5.667 -	FREE(xr, M_DEVBUF);
   5.668 -#ifdef DEBUG
   5.669 -	xbd_allxr = NULL;
   5.670 -#endif
   5.671 -	SLIST_INIT(&xbdreqs);
   5.672 -	return 0;
   5.673  }
   5.674  
   5.675  #if NXBD > 0
   5.676 @@ -844,20 +1126,21 @@ fill_ring(struct xbdreq *xr)
   5.677  	paddr_t pa;
   5.678  	unsigned long ma;
   5.679  	vaddr_t addr, off;
   5.680 -	blk_ring_req_entry_t *ring_req;
   5.681 -	int breq, nr_sectors;
   5.682 +	blkif_request_t *ring_req;
   5.683 +	int breq, nr_sectors, fsect, lsect;
   5.684  
   5.685  	/* Fill out a communications ring structure. */
   5.686 -	ring_req = &blk_ring->ring[MASK_BLK_IDX(req_prod)].req;
   5.687 +	ring_req = &blk_ring->ring[MASK_BLKIF_IDX(req_prod)].req;
   5.688  	ring_req->id = (unsigned long)xr;
   5.689 -	ring_req->operation = pxr->xr_bp->b_flags & B_READ ? XEN_BLOCK_READ :
   5.690 -		XEN_BLOCK_WRITE;
   5.691 -	ring_req->sector_number = (xen_sector_t)pxr->xr_bn;
   5.692 +	ring_req->operation = pxr->xr_bp->b_flags & B_READ ? BLKIF_OP_READ :
   5.693 +		BLKIF_OP_WRITE;
   5.694 +	ring_req->sector_number = pxr->xr_bn;
   5.695  	ring_req->device = pxr->xr_sc->sc_xd_device;
   5.696  
   5.697  	DPRINTF(XBDB_IO, ("fill_ring(%d): bp %p sector %llu pxr %p xr %p\n",
   5.698 -	    MASK_BLK_IDX(req_prod), pxr->xr_bp, (unsigned long long)pxr->xr_bn,
   5.699 -	    pxr, xr));
   5.700 +		    MASK_BLKIF_IDX(req_prod), pxr->xr_bp,
   5.701 +		    (unsigned long long)pxr->xr_bn,
   5.702 +		    pxr, xr));
   5.703  
   5.704  	xr->xr_breq = 0;
   5.705  	ring_req->nr_segments = 0;
   5.706 @@ -870,7 +1153,7 @@ fill_ring(struct xbdreq *xr)
   5.707  #else
   5.708  		pmap_extract(pmap_kernel(), addr, &pa);
   5.709  #endif
   5.710 -		ma = xpmap_ptom_masked(pa) + off;
   5.711 +		ma = xpmap_ptom_masked(pa);
   5.712  		DIAGCONDPANIC((ma & (XEN_BSIZE - 1)) != 0,
   5.713  		    ("xbd request ma not sector aligned"));
   5.714  
   5.715 @@ -878,23 +1161,29 @@ fill_ring(struct xbdreq *xr)
   5.716  			breq = PAGE_SIZE - off;
   5.717  		else
   5.718  			breq = pxr->xr_bqueue;
   5.719 +
   5.720  		nr_sectors = breq >> XEN_BSHIFT;
   5.721  		DIAGCONDPANIC(nr_sectors >= XEN_BSIZE,
   5.722  		    ("xbd request nr_sectors >= XEN_BSIZE"));
   5.723  
   5.724 +		fsect = off >> XEN_BSHIFT;
   5.725 +		lsect = fsect + nr_sectors - 1;
   5.726 +		DIAGCONDPANIC(fsect > 7, ("xbd request fsect > 7"));
   5.727 +		DIAGCONDPANIC(lsect > 7, ("xbd request lsect > 7"));
   5.728 +
   5.729  		DPRINTF(XBDB_IO, ("fill_ring(%d): va 0x%08lx pa 0x%08lx "
   5.730  		    "ma 0x%08lx, sectors %d, left %ld/%ld\n",
   5.731 -		    MASK_BLK_IDX(req_prod), addr, pa, ma, nr_sectors,
   5.732 +		    MASK_BLKIF_IDX(req_prod), addr, pa, ma, nr_sectors,
   5.733  		    pxr->xr_bqueue >> XEN_BSHIFT, pxr->xr_bqueue));
   5.734  
   5.735 -		ring_req->buffer_and_sects[ring_req->nr_segments++] =
   5.736 -			ma | nr_sectors;
   5.737 +		ring_req->frame_and_sects[ring_req->nr_segments++] =
   5.738 +			ma | (fsect<<3) | lsect;
   5.739  		addr += PAGE_SIZE;
   5.740  		pxr->xr_bqueue -= breq;
   5.741  		pxr->xr_bn += nr_sectors;
   5.742  		xr->xr_breq += breq;
   5.743  		off = 0;
   5.744 -		if (ring_req->nr_segments == MAX_BLK_SEGS)
   5.745 +		if (ring_req->nr_segments == BLKIF_MAX_SEGMENTS_PER_REQUEST)
   5.746  			break;
   5.747  	}
   5.748  	pxr->xr_data = addr;
   5.749 @@ -1048,64 +1337,81 @@ xbd_response_handler(void *arg)
   5.750  {
   5.751  	struct buf *bp;
   5.752  	struct xbd_softc *xs;
   5.753 -	blk_ring_resp_entry_t *ring_resp;
   5.754 +	blkif_response_t *ring_resp;
   5.755  	struct xbdreq *pxr, *xr;
   5.756 -	int i;
   5.757 +	BLKIF_RING_IDX i, rp;
   5.758 +
   5.759 +	rp = blk_ring->resp_prod;
   5.760 +	__insn_barrier(); /* Ensure we see queued responses up to 'rp'. */
   5.761  
   5.762 -	for (i = resp_cons; i != blk_ring->resp_prod; i = BLK_RING_INC(i)) {
   5.763 -		ring_resp = &blk_ring->ring[MASK_BLK_IDX(i)].resp;
   5.764 +	for (i = resp_cons; i != rp; i++) {
   5.765 +		ring_resp = &blk_ring->ring[MASK_BLKIF_IDX(i)].resp;
   5.766  		xr = (struct xbdreq *)ring_resp->id;
   5.767 -		pxr = xr->xr_parent;
   5.768 +
   5.769 +		switch (ring_resp->operation) {
   5.770 +		case BLKIF_OP_READ:
   5.771 +		case BLKIF_OP_WRITE:
   5.772 +			pxr = xr->xr_parent;
   5.773  
   5.774 -		DPRINTF(XBDB_IO, ("xbd_response_handler(%d): pxr %p xr %p "
   5.775 -		    "bdone %04lx breq %04lx\n", i, pxr, xr, pxr->xr_bdone,
   5.776 -		    xr->xr_breq));
   5.777 -		pxr->xr_bdone -= xr->xr_breq;
   5.778 -		DIAGCONDPANIC(pxr->xr_bdone < 0,
   5.779 -		    ("xbd_response_handler: pxr->xr_bdone < 0"));
   5.780 +			DPRINTF(XBDB_IO, ("xbd_response_handler(%d): pxr %p "
   5.781 +				    "xr %p bdone %04lx breq %04lx\n", i, pxr,
   5.782 +				    xr, pxr->xr_bdone, xr->xr_breq));
   5.783 +			pxr->xr_bdone -= xr->xr_breq;
   5.784 +			DIAGCONDPANIC(pxr->xr_bdone < 0,
   5.785 +			    ("xbd_response_handler: pxr->xr_bdone < 0"));
   5.786  
   5.787 -		if (__predict_false(ring_resp->status)) {
   5.788 -			pxr->xr_bp->b_flags |= B_ERROR;
   5.789 -			pxr->xr_bp->b_error = EIO;
   5.790 -		}
   5.791 +			if (__predict_false(ring_resp->status)) {
   5.792 +				pxr->xr_bp->b_flags |= B_ERROR;
   5.793 +				pxr->xr_bp->b_error = EIO;
   5.794 +			}
   5.795  
   5.796 -		if (xr != pxr) {
   5.797 -			PUT_XBDREQ(xr);
   5.798 -			if (!SIMPLEQ_EMPTY(&xbdr_suspended))
   5.799 -				xbdresume();
   5.800 -		}
   5.801 +			if (xr != pxr) {
   5.802 +				PUT_XBDREQ(xr);
   5.803 +				if (!SIMPLEQ_EMPTY(&xbdr_suspended))
   5.804 +					xbdresume();
   5.805 +			}
   5.806  
   5.807 -		if (pxr->xr_bdone == 0) {
   5.808 -			bp = pxr->xr_bp;
   5.809 -			xs = getxbd_softc(bp->b_dev);
   5.810 -			if (xs == NULL) { /* don't fail bp if we're shutdown */
   5.811 -				bp->b_flags |= B_ERROR;
   5.812 -				bp->b_error = EIO;
   5.813 -			}
   5.814 -			DPRINTF(XBDB_IO, ("xbd_response_handler(%d): "
   5.815 -			    "completed bp %p\n", i, bp));
   5.816 -			if (bp->b_flags & B_ERROR)
   5.817 -				bp->b_resid = bp->b_bcount;
   5.818 -			else
   5.819 -				bp->b_resid = 0;
   5.820 +			if (pxr->xr_bdone == 0) {
   5.821 +				bp = pxr->xr_bp;
   5.822 +				xs = getxbd_softc(bp->b_dev);
   5.823 +				if (xs == NULL) { /* don't fail bp if we're shutdown */
   5.824 +					bp->b_flags |= B_ERROR;
   5.825 +					bp->b_error = EIO;
   5.826 +				}
   5.827 +				DPRINTF(XBDB_IO, ("xbd_response_handler(%d): "
   5.828 +					    "completed bp %p\n", i, bp));
   5.829 +				if (bp->b_flags & B_ERROR)
   5.830 +					bp->b_resid = bp->b_bcount;
   5.831 +				else
   5.832 +					bp->b_resid = 0;
   5.833 +
   5.834 +				if (pxr->xr_aligned)
   5.835 +					unmap_align(pxr);
   5.836  
   5.837 -			if (pxr->xr_aligned)
   5.838 -				unmap_align(pxr);
   5.839 -
   5.840 -			PUT_XBDREQ(pxr);
   5.841 -			if (xs)
   5.842 -				disk_unbusy(&xs->sc_dksc.sc_dkdev,
   5.843 -				    (bp->b_bcount - bp->b_resid),
   5.844 -				    (bp->b_flags & B_READ));
   5.845 -			biodone(bp);
   5.846 -			if (!SIMPLEQ_EMPTY(&xbdr_suspended))
   5.847 -				xbdresume();
   5.848 -			/* XXX possible lockup if this was the only
   5.849 -			 * active device and requests were held back in
   5.850 -			 * the queue.
   5.851 -			 */
   5.852 -			if (xs)
   5.853 -				dk_iodone(xs->sc_di, &xs->sc_dksc);
   5.854 +				PUT_XBDREQ(pxr);
   5.855 +				if (xs)
   5.856 +					disk_unbusy(&xs->sc_dksc.sc_dkdev,
   5.857 +					    (bp->b_bcount - bp->b_resid),
   5.858 +					    (bp->b_flags & B_READ));
   5.859 +				biodone(bp);
   5.860 +				if (!SIMPLEQ_EMPTY(&xbdr_suspended))
   5.861 +					xbdresume();
   5.862 +				/* XXX possible lockup if this was the only
   5.863 +				 * active device and requests were held back in
   5.864 +				 * the queue.
   5.865 +				 */
   5.866 +				if (xs)
   5.867 +					dk_iodone(xs->sc_di, &xs->sc_dksc);
   5.868 +			}
   5.869 +			break;
   5.870 +		case BLKIF_OP_PROBE:
   5.871 +			memcpy(&blkif_control_rsp, ring_resp,
   5.872 +			    sizeof(*ring_resp));
   5.873 +			blkif_control_rsp_valid = 1;
   5.874 +			wakeup((caddr_t)&blkif_control_rsp_valid);
   5.875 +			break;
   5.876 +		default:
   5.877 +			panic("unknown response");
   5.878  		}
   5.879  	}
   5.880  	resp_cons = i;
   5.881 @@ -1115,23 +1421,7 @@ xbd_response_handler(void *arg)
   5.882  	return 0;
   5.883  }
   5.884  
   5.885 -static struct device *
   5.886 -find_device(xen_disk_t *xd)
   5.887 -{
   5.888 -	struct device *dv;
   5.889 -	struct xbd_softc *xs;
   5.890 -
   5.891 -	for (dv = alldevs.tqh_first; dv != NULL; dv = dv->dv_list.tqe_next) {
   5.892 -		if (dv->dv_cfattach == NULL ||
   5.893 -		    dv->dv_cfattach->ca_attach != xbd_attach)
   5.894 -			continue;
   5.895 -		xs = (struct xbd_softc *)dv;
   5.896 -		if (xs->sc_xd_device == xd->device)
   5.897 -			break;
   5.898 -	}
   5.899 -	return dv;
   5.900 -}
   5.901 -
   5.902 +#if 0
   5.903  static void
   5.904  xbd_update_create_kthread(void *arg)
   5.905  {
   5.906 @@ -1145,24 +1435,24 @@ xbd_update_kthread(void *arg)
   5.907  	struct device *parent = arg;
   5.908  	struct xbd_attach_args *xbda;
   5.909  	struct device *dev;
   5.910 -	xen_disk_t *xd;
   5.911 -	xen_disk_t *vbd_info_update, *vbd_info_old;
   5.912 +	vdisk_t *xd;
   5.913 +	vdisk_t *vbd_info_update, *vbd_info_old;
   5.914  	int i, j, new_nr_vbds;
   5.915  	extern int hypervisor_print(void *, const char *);
   5.916  
   5.917 -	MALLOC(vbd_info_update, xen_disk_t *, MAX_VBDS *
   5.918 -	    sizeof(xen_disk_t), M_DEVBUF, M_WAITOK);
   5.919 +	MALLOC(vbd_info_update, vdisk_t *, MAX_VBDS *
   5.920 +	    sizeof(vdisk_t), M_DEVBUF, M_WAITOK);
   5.921  
   5.922  	for (;;) {
   5.923 -		memset(vbd_info_update, 0, MAX_VBDS * sizeof(xen_disk_t));
   5.924 +		memset(vbd_info_update, 0, MAX_VBDS * sizeof(vdisk_t));
   5.925  		new_nr_vbds  = get_vbd_info(vbd_info_update);
   5.926  
   5.927  		if (memcmp(vbd_info, vbd_info_update, MAX_VBDS *
   5.928 -		    sizeof(xen_disk_t)) == 0) {
   5.929 +		    sizeof(vdisk_t)) == 0) {
   5.930  			FREE(vbd_info_update, M_DEVBUF);
   5.931  			tsleep(parent, PWAIT, "xbdupd", 0);
   5.932 -			MALLOC(vbd_info_update, xen_disk_t *, MAX_VBDS *
   5.933 -			    sizeof(xen_disk_t), M_DEVBUF, M_WAITOK);
   5.934 +			MALLOC(vbd_info_update, vdisk_t *, MAX_VBDS *
   5.935 +			    sizeof(vdisk_t), M_DEVBUF, M_WAITOK);
   5.936  			continue;
   5.937  		}
   5.938  
   5.939 @@ -1228,6 +1518,7 @@ xbd_update_handler(void *arg)
   5.940  
   5.941  	return 0;
   5.942  }
   5.943 +#endif
   5.944  
   5.945  /* XXX: we should probably put these into dksubr.c, mostly */
   5.946  int
   5.947 @@ -1309,7 +1600,7 @@ xbddump(dev_t dev, daddr_t blkno, caddr_
   5.948  }
   5.949  
   5.950  static int
   5.951 -xbdinit(struct xbd_softc *xs, xen_disk_t *xd, struct dk_intf *dkintf)
   5.952 +xbdinit(struct xbd_softc *xs, vdisk_t *xd, struct dk_intf *dkintf)
   5.953  {
   5.954  	struct dk_geom *pdg;
   5.955  	char buf[9];