From owner-svn-src-projects@FreeBSD.ORG Thu Dec 4 20:04:25 2008 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id BD9501065673; Thu, 4 Dec 2008 20:04:25 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id AA7798FC13; Thu, 4 Dec 2008 20:04:25 +0000 (UTC) (envelope-from kmacy@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mB4K4Pg3033163; Thu, 4 Dec 2008 20:04:25 GMT (envelope-from kmacy@svn.freebsd.org) Received: (from kmacy@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mB4K4PZG033158; Thu, 4 Dec 2008 20:04:25 GMT (envelope-from kmacy@svn.freebsd.org) Message-Id: <200812042004.mB4K4PZG033158@svn.freebsd.org> From: Kip Macy Date: Thu, 4 Dec 2008 20:04:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r185619 - in projects/release_6_3_xen/sys: conf dev/xen/blkfront dev/xen/netfront i386/conf i386/include/xen i386/xen vm xen xen/xenbus X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Dec 2008 20:04:25 -0000 Author: kmacy Date: Thu Dec 4 20:04:25 2008 New Revision: 185619 URL: http://svn.freebsd.org/changeset/base/185619 Log: Convert virtual devices over to using newbus Added: projects/release_6_3_xen/sys/xen/xenbus/xenbus_if.m projects/release_6_3_xen/sys/xen/xenbus/xenbusvar.h Deleted: projects/release_6_3_xen/sys/i386/include/xen/xenbus.h Modified: projects/release_6_3_xen/sys/conf/files projects/release_6_3_xen/sys/dev/xen/blkfront/blkfront.c projects/release_6_3_xen/sys/dev/xen/blkfront/block.h projects/release_6_3_xen/sys/dev/xen/netfront/netfront.c projects/release_6_3_xen/sys/i386/conf/XEN projects/release_6_3_xen/sys/i386/xen/mp_machdep.c projects/release_6_3_xen/sys/i386/xen/xen_machdep.c projects/release_6_3_xen/sys/vm/vm_page.c projects/release_6_3_xen/sys/xen/gnttab.c projects/release_6_3_xen/sys/xen/gnttab.h projects/release_6_3_xen/sys/xen/xenbus/xenbus_client.c projects/release_6_3_xen/sys/xen/xenbus/xenbus_comms.c projects/release_6_3_xen/sys/xen/xenbus/xenbus_comms.h projects/release_6_3_xen/sys/xen/xenbus/xenbus_dev.c projects/release_6_3_xen/sys/xen/xenbus/xenbus_probe.c projects/release_6_3_xen/sys/xen/xenbus/xenbus_probe_backend.c projects/release_6_3_xen/sys/xen/xenbus/xenbus_xs.c Modified: projects/release_6_3_xen/sys/conf/files ============================================================================== --- projects/release_6_3_xen/sys/conf/files Thu Dec 4 20:03:15 2008 (r185618) +++ projects/release_6_3_xen/sys/conf/files Thu Dec 4 20:04:25 2008 (r185619) @@ -2007,10 +2007,14 @@ xen/evtchn/evtchn_dev.c o xen/xenbus/xenbus_client.c optional xen xen/xenbus/xenbus_comms.c optional xen xen/xenbus/xenbus_dev.c optional xen +xen/xenbus/xenbus_if.m optional xen xen/xenbus/xenbus_probe.c optional xen -xen/xenbus/xenbus_probe_backend.c optional xen +#xen/xenbus/xenbus_probe_backend.c optional xen xen/xenbus/xenbus_xs.c optional xen dev/xen/console/console.c optional xen dev/xen/console/xencons_ring.c optional xen dev/xen/blkfront/blkfront.c optional xen dev/xen/netfront/netfront.c optional xen +#dev/xen/xenpci/xenpci.c optional xen +#xen/xenbus/xenbus_newbus.c optional xenhvm + Modified: projects/release_6_3_xen/sys/dev/xen/blkfront/blkfront.c ============================================================================== --- projects/release_6_3_xen/sys/dev/xen/blkfront/blkfront.c Thu Dec 4 20:03:15 2008 (r185618) +++ projects/release_6_3_xen/sys/dev/xen/blkfront/blkfront.c Thu Dec 4 20:04:25 2008 (r185619) @@ -43,9 +43,10 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include +#include +#include #include #include @@ -53,15 +54,17 @@ __FBSDID("$FreeBSD$"); #include +#include "xenbus_if.h" + #define ASSERT(S) KASSERT(S, (#S)) /* prototypes */ struct xb_softc; static void xb_startio(struct xb_softc *sc); -static void connect(struct blkfront_info *); -static void blkfront_closing(struct xenbus_device *); -static int blkfront_remove(struct xenbus_device *); -static int talk_to_backend(struct xenbus_device *, struct blkfront_info *); -static int setup_blkring(struct xenbus_device *, struct blkfront_info *); +static void connect(device_t, struct blkfront_info *); +static void blkfront_closing(device_t); +static int blkfront_detach(device_t); +static int talk_to_backend(device_t, struct blkfront_info *); +static int setup_blkring(device_t, struct blkfront_info *); static void blkif_int(void *); #if 0 static void blkif_restart_queue(void *arg); @@ -136,22 +139,95 @@ pfn_to_mfn(vm_paddr_t pfn) } +/* + * Translate Linux major/minor to an appropriate name and unit + * number. For HVM guests, this allows us to use the same drive names + * with blkfront as the emulated drives, easing transition slightly. + */ +static void +blkfront_vdevice_to_unit(int vdevice, int *unit, const char **name) +{ + static struct vdev_info { + int major; + int shift; + int base; + const char *name; + } info[] = { + {3, 6, 0, "ad"}, /* ide0 */ + {22, 6, 2, "ad"}, /* ide1 */ + {33, 6, 4, "ad"}, /* ide2 */ + {34, 6, 6, "ad"}, /* ide3 */ + {56, 6, 8, "ad"}, /* ide4 */ + {57, 6, 10, "ad"}, /* ide5 */ + {88, 6, 12, "ad"}, /* ide6 */ + {89, 6, 14, "ad"}, /* ide7 */ + {90, 6, 16, "ad"}, /* ide8 */ + {91, 6, 18, "ad"}, /* ide9 */ + + {8, 4, 0, "da"}, /* scsi disk0 */ + {65, 4, 16, "da"}, /* scsi disk1 */ + {66, 4, 32, "da"}, /* scsi disk2 */ + {67, 4, 48, "da"}, /* scsi disk3 */ + {68, 4, 64, "da"}, /* scsi disk4 */ + {69, 4, 80, "da"}, /* scsi disk5 */ + {70, 4, 96, "da"}, /* scsi disk6 */ + {71, 4, 112, "da"}, /* scsi disk7 */ + {128, 4, 128, "da"}, /* scsi disk8 */ + {129, 4, 144, "da"}, /* scsi disk9 */ + {130, 4, 160, "da"}, /* scsi disk10 */ + {131, 4, 176, "da"}, /* scsi disk11 */ + {132, 4, 192, "da"}, /* scsi disk12 */ + {133, 4, 208, "da"}, /* scsi disk13 */ + {134, 4, 224, "da"}, /* scsi disk14 */ + {135, 4, 240, "da"}, /* scsi disk15 */ + + {202, 4, 0, "xbd"}, /* xbd */ + + {0, 0, 0, NULL}, + }; + int major = vdevice >> 8; + int minor = vdevice & 0xff; + int i; + + if (vdevice & (1 << 28)) { + *unit = (vdevice & ((1 << 28) - 1)) >> 8; + *name = "xbd"; + } + + for (i = 0; info[i].major; i++) { + if (info[i].major == major) { + *unit = info[i].base + (minor >> info[i].shift); + *name = info[i].name; + return; + } + } + + *unit = minor >> 4; + *name = "xbd"; +} + int -xlvbd_add(blkif_sector_t capacity, int unit, uint16_t vdisk_info, uint16_t sector_size, - struct blkfront_info *info) +xlvbd_add(device_t dev, blkif_sector_t capacity, + int vdevice, uint16_t vdisk_info, uint16_t sector_size, + struct blkfront_info *info) { struct xb_softc *sc; - int error = 0; - int unitno = unit - 767; + int unit, error = 0; + const char *name; + + blkfront_vdevice_to_unit(vdevice, &unit, &name); sc = (struct xb_softc *)malloc(sizeof(*sc), M_DEVBUF, M_WAITOK|M_ZERO); - sc->xb_unit = unitno; + sc->xb_unit = unit; sc->xb_info = info; info->sc = sc; + if (strcmp(name, "xbd")) + device_printf(dev, "attaching as %s%d\n", name, unit); + memset(&sc->xb_disk, 0, sizeof(sc->xb_disk)); sc->xb_disk = disk_alloc(); - sc->xb_disk->d_unit = unitno; + sc->xb_disk->d_unit = unit; sc->xb_disk->d_open = blkif_open; sc->xb_disk->d_close = blkif_close; sc->xb_disk->d_ioctl = blkif_ioctl; @@ -226,19 +302,33 @@ xb_strategy(struct bio *bp) return; } +static int +blkfront_probe(device_t dev) +{ + + if (!strcmp(xenbus_get_type(dev), "vbd")) { + device_set_desc(dev, "Virtual Block Device"); + device_quiet(dev); + return (0); + } -/* Setup supplies the backend dir, virtual device. + return (ENXIO); +} -We place an event channel and shared frame entries. -We watch backend to wait if it's ok. */ -static int blkfront_probe(struct xenbus_device *dev, - const struct xenbus_device_id *id) +/* + * Setup supplies the backend dir, virtual device. We place an event + * channel and shared frame entries. We watch backend to wait if it's + * ok. + */ +static int +blkfront_attach(device_t dev) { - int err, vdevice, i; + int err, vdevice, i, unit; struct blkfront_info *info; + const char *name; /* FIXME: Use dynamic device id if this is not set. */ - err = xenbus_scanf(XBT_NIL, dev->nodename, + err = xenbus_scanf(XBT_NIL, xenbus_get_node(dev), "virtual-device", "%i", &vdevice); if (err != 1) { xenbus_dev_fatal(dev, err, "reading virtual-device"); @@ -246,11 +336,11 @@ static int blkfront_probe(struct xenbus_ return (err); } - info = malloc(sizeof(*info), M_DEVBUF, M_NOWAIT|M_ZERO); - if (info == NULL) { - xenbus_dev_fatal(dev, ENOMEM, "allocating info structure"); - return ENOMEM; - } + blkfront_vdevice_to_unit(vdevice, &unit, &name); + if (!strcmp(name, "xbd")) + device_set_unit(dev, unit); + + info = device_get_softc(dev); /* * XXX debug only @@ -270,23 +360,20 @@ static int blkfront_probe(struct xenbus_ info->shadow[BLK_RING_SIZE-1].req.id = 0x0fffffff; /* Front end dir is a number, which is used as the id. */ - info->handle = strtoul(strrchr(dev->nodename,'/')+1, NULL, 0); - dev->dev_driver_data = info; + info->handle = strtoul(strrchr(xenbus_get_node(dev),'/')+1, NULL, 0); err = talk_to_backend(dev, info); if (err) { - free(info, M_DEVBUF); - dev->dev_driver_data = NULL; return err; } - return 0; + return (0); } - -static int blkfront_resume(struct xenbus_device *dev) +static int +blkfront_resume(device_t dev) { - struct blkfront_info *info = dev->dev_driver_data; + struct blkfront_info *info = device_get_softc(dev); int err; DPRINTK("blkfront_resume: %s\n", dev->nodename); @@ -301,8 +388,8 @@ static int blkfront_resume(struct xenbus } /* Common code used when first setting up, and when resuming. */ -static int talk_to_backend(struct xenbus_device *dev, - struct blkfront_info *info) +static int +talk_to_backend(device_t dev, struct blkfront_info *info) { const char *message = NULL; struct xenbus_transaction xbt; @@ -320,19 +407,24 @@ static int talk_to_backend(struct xenbus goto destroy_blkring; } - err = xenbus_printf(xbt, dev->nodename, + err = xenbus_printf(xbt, xenbus_get_node(dev), "ring-ref","%u", info->ring_ref); if (err) { message = "writing ring-ref"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, + err = xenbus_printf(xbt, xenbus_get_node(dev), "event-channel", "%u", irq_to_evtchn_port(info->irq)); if (err) { message = "writing event-channel"; goto abort_transaction; } - + err = xenbus_printf(xbt, xenbus_get_node(dev), + "protocol", "%s", XEN_IO_PROTO_ABI_NATIVE); + if (err) { + message = "writing protocol"; + goto abort_transaction; + } err = xenbus_transaction_end(xbt, 0); if (err) { if (err == -EAGAIN) @@ -340,7 +432,7 @@ static int talk_to_backend(struct xenbus xenbus_dev_fatal(dev, err, "completing transaction"); goto destroy_blkring; } - xenbus_switch_state(dev, XenbusStateInitialised); + xenbus_set_state(dev, XenbusStateInitialised); return 0; @@ -355,7 +447,7 @@ static int talk_to_backend(struct xenbus } static int -setup_blkring(struct xenbus_device *dev, struct blkfront_info *info) +setup_blkring(device_t dev, struct blkfront_info *info) { blkif_sring_t *sring; int err; @@ -378,7 +470,7 @@ setup_blkring(struct xenbus_device *dev, } info->ring_ref = err; - err = bind_listening_port_to_irqhandler(dev->otherend_id, + err = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), "xbd", (driver_intr_t *)blkif_int, info, INTR_TYPE_BIO | INTR_MPSAFE, NULL); if (err <= 0) { @@ -398,10 +490,10 @@ setup_blkring(struct xenbus_device *dev, /** * Callback received when the backend's state changes. */ -static void backend_changed(struct xenbus_device *dev, - XenbusState backend_state) +static void +blkfront_backend_changed(device_t dev, XenbusState backend_state) { - struct blkfront_info *info = dev->dev_driver_data; + struct blkfront_info *info = device_get_softc(dev); DPRINTK("blkfront:backend_changed.\n"); @@ -416,7 +508,7 @@ static void backend_changed(struct xenbu break; case XenbusStateConnected: - connect(info); + connect(dev, info); break; case XenbusStateClosing: @@ -447,7 +539,7 @@ static void backend_changed(struct xenbu ** the details about the physical device - #sectors, size, etc). */ static void -connect(struct blkfront_info *info) +connect(device_t dev, struct blkfront_info *info) { unsigned long sectors, sector_size; unsigned int binfo; @@ -457,28 +549,34 @@ connect(struct blkfront_info *info) (info->connected == BLKIF_STATE_SUSPENDED) ) return; - DPRINTK("blkfront.c:connect:%s.\n", info->xbdev->otherend); + DPRINTK("blkfront.c:connect:%s.\n", xenbus_get_otherend_path(dev)); - err = xenbus_gather(XBT_NIL, info->xbdev->otherend, + err = xenbus_gather(XBT_NIL, xenbus_get_otherend_path(dev), "sectors", "%lu", §ors, "info", "%u", &binfo, "sector-size", "%lu", §or_size, NULL); if (err) { - xenbus_dev_fatal(info->xbdev, err, - "reading backend fields at %s", - info->xbdev->otherend); + xenbus_dev_fatal(dev, err, + "reading backend fields at %s", + xenbus_get_otherend_path(dev)); return; } - err = xenbus_gather(XBT_NIL, info->xbdev->otherend, + err = xenbus_gather(XBT_NIL, xenbus_get_otherend_path(dev), "feature-barrier", "%lu", &info->feature_barrier, NULL); if (err) info->feature_barrier = 0; - xlvbd_add(sectors, info->vdevice, binfo, sector_size, info); + device_printf(dev, "%juMB <%s> at %s", + (uintmax_t) sectors / (1048576 / sector_size), + device_get_desc(dev), + xenbus_get_node(dev)); + bus_print_child_footer(device_get_parent(dev), dev); - (void)xenbus_switch_state(info->xbdev, XenbusStateConnected); + xlvbd_add(dev, sectors, info->vdevice, binfo, sector_size, info); + + (void)xenbus_set_state(dev, XenbusStateConnected); /* Kick pending requests. */ mtx_lock(&blkif_io_lock); @@ -498,11 +596,12 @@ connect(struct blkfront_info *info) * the backend. Once is this done, we can switch to Closed in * acknowledgement. */ -static void blkfront_closing(struct xenbus_device *dev) +static void +blkfront_closing(device_t dev) { - struct blkfront_info *info = dev->dev_driver_data; + struct blkfront_info *info = device_get_softc(dev); - DPRINTK("blkfront_closing: %s removed\n", dev->nodename); + DPRINTK("blkfront_closing: %s removed\n", xenbus_get_node(dev)); if (info->mi) { DPRINTK("Calling xlvbd_del\n"); @@ -510,20 +609,19 @@ static void blkfront_closing(struct xenb info->mi = NULL; } - xenbus_switch_state(dev, XenbusStateClosed); + xenbus_set_state(dev, XenbusStateClosed); } -static int blkfront_remove(struct xenbus_device *dev) +static int +blkfront_detach(device_t dev) { - struct blkfront_info *info = dev->dev_driver_data; + struct blkfront_info *info = device_get_softc(dev); - DPRINTK("blkfront_remove: %s removed\n", dev->nodename); + DPRINTK("blkfront_remove: %s removed\n", xenbus_get_node(dev)); blkif_free(info, 0); - free(info, M_DEVBUF); - return 0; } @@ -631,8 +729,9 @@ blkif_close(struct disk *dp) /* Check whether we have been instructed to close. We will have ignored this request initially, as the device was still mounted. */ - struct xenbus_device * dev = sc->xb_info->xbdev; - XenbusState state = xenbus_read_driver_state(dev->otherend); + device_t dev = sc->xb_info->xbdev; + XenbusState state = + xenbus_read_driver_state(xenbus_get_otherend_path(dev)); if (state == XenbusStateClosing) blkfront_closing(dev); @@ -731,7 +830,7 @@ static int blkif_queue_request(struct bi gnttab_grant_foreign_access_ref( ref, - info->xbdev->otherend_id, + xenbus_get_otherend_id(info->xbdev), buffer_ma >> PAGE_SHIFT, ring_req->operation & 1 ); /* ??? */ info->shadow[id].frame[ring_req->nr_segments] = @@ -952,7 +1051,7 @@ blkif_recover(struct blkfront_info *info for (j = 0; j < req->nr_segments; j++) gnttab_grant_foreign_access_ref( req->seg[j].gref, - info->xbdev->otherend_id, + xenbus_get_otherend_id(info->xbdev), pfn_to_mfn(info->shadow[req->id].frame[j]), 0 /* assume not readonly */); @@ -963,7 +1062,7 @@ blkif_recover(struct blkfront_info *info free(copy, M_DEVBUF); - xenbus_switch_state(info->xbdev, XenbusStateConnected); + xenbus_set_state(info->xbdev, XenbusStateConnected); /* Now safe for us to use the shared ring */ mtx_lock(&blkif_io_lock); @@ -979,48 +1078,30 @@ blkif_recover(struct blkfront_info *info mtx_unlock(&blkif_io_lock); } -static int -blkfront_is_ready(struct xenbus_device *dev) -{ - struct blkfront_info *info = dev->dev_driver_data; - - return info->is_ready; -} - -static struct xenbus_device_id blkfront_ids[] = { - { "vbd" }, - { "" } -}; - - -static struct xenbus_driver blkfront = { - .name = "vbd", - .ids = blkfront_ids, - .probe = blkfront_probe, - .remove = blkfront_remove, - .resume = blkfront_resume, - .otherend_changed = backend_changed, - .is_ready = blkfront_is_ready, -}; - - - -static void -xenbus_init(void) -{ - xenbus_register_frontend(&blkfront); -} +/* ** Driver registration ** */ +static device_method_t blkfront_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, blkfront_probe), + DEVMETHOD(device_attach, blkfront_attach), + DEVMETHOD(device_detach, blkfront_detach), + DEVMETHOD(device_shutdown, bus_generic_shutdown), + DEVMETHOD(device_suspend, bus_generic_suspend), + DEVMETHOD(device_resume, blkfront_resume), + + /* Xenbus interface */ + DEVMETHOD(xenbus_backend_changed, blkfront_backend_changed), + + { 0, 0 } +}; + +static driver_t blkfront_driver = { + "xbd", + blkfront_methods, + sizeof(struct blkfront_info), +}; +devclass_t blkfront_devclass; + +DRIVER_MODULE(xbd, xenbus, blkfront_driver, blkfront_devclass, 0, 0); MTX_SYSINIT(ioreq, &blkif_io_lock, "BIO LOCK", MTX_NOWITNESS); /* XXX how does one enroll a lock? */ -SYSINIT(xbdev, SI_SUB_PSEUDO, SI_ORDER_SECOND, xenbus_init, NULL); - -/* - * Local variables: - * mode: C - * c-set-style: "BSD" - * c-basic-offset: 8 - * tab-width: 4 - * indent-tabs-mode: t - * End: - */ Modified: projects/release_6_3_xen/sys/dev/xen/blkfront/block.h ============================================================================== --- projects/release_6_3_xen/sys/dev/xen/blkfront/block.h Thu Dec 4 20:03:15 2008 (r185618) +++ projects/release_6_3_xen/sys/dev/xen/blkfront/block.h Thu Dec 4 20:04:25 2008 (r185619) @@ -60,7 +60,7 @@ struct xb_softc { */ struct blkfront_info { - struct xenbus_device *xbdev; + device_t xbdev; dev_t dev; struct gendisk *gd; int vdevice; @@ -89,7 +89,7 @@ struct blkfront_info /* Note that xlvbd_add doesn't call add_disk for you: you're expected to call add_disk on info->gd once the disk is properly connected up. */ -int xlvbd_add(blkif_sector_t capacity, int device, +int xlvbd_add(device_t, blkif_sector_t capacity, int device, uint16_t vdisk_info, uint16_t sector_size, struct blkfront_info *info); void xlvbd_del(struct blkfront_info *info); Modified: projects/release_6_3_xen/sys/dev/xen/netfront/netfront.c ============================================================================== --- projects/release_6_3_xen/sys/dev/xen/netfront/netfront.c Thu Dec 4 20:03:15 2008 (r185618) +++ projects/release_6_3_xen/sys/dev/xen/netfront/netfront.c Thu Dec 4 20:04:25 2008 (r185619) @@ -25,6 +25,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -65,13 +66,14 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include #include #include +#include +#include "xenbus_if.h" #define GRANT_INVALID_REF 0 @@ -117,19 +119,19 @@ static void xn_watchdog(struct ifnet *); static void show_device(struct netfront_info *sc); #ifdef notyet -static void netfront_closing(struct xenbus_device *dev); +static void netfront_closing(device_t dev); #endif static void netif_free(struct netfront_info *info); -static int netfront_remove(struct xenbus_device *dev); +static int netfront_detach(device_t dev); -static int talk_to_backend(struct xenbus_device *dev, struct netfront_info *info); -static int create_netdev(struct xenbus_device *dev, struct ifnet **ifp); +static int talk_to_backend(device_t dev, struct netfront_info *info); +static int create_netdev(device_t dev); static void netif_disconnect_backend(struct netfront_info *info); -static int setup_device(struct xenbus_device *dev, struct netfront_info *info); +static int setup_device(device_t dev, struct netfront_info *info); static void end_access(int ref, void *page); /* Xenolinux helper functions */ -static int network_connect(struct ifnet *ifp); +int network_connect(struct netfront_info *); static void xn_free_rx_ring(struct netfront_info *); @@ -222,7 +224,7 @@ struct netfront_info { grant_ref_t grant_rx_ref[NET_TX_RING_SIZE + 1]; #define TX_MAX_TARGET min(NET_RX_RING_SIZE, 256) - struct xenbus_device *xbdev; + device_t xbdev; int tx_ring_ref; int rx_ring_ref; uint8_t mac[ETHER_ADDR_LEN]; @@ -328,7 +330,7 @@ xennet_get_rx_ref(struct netfront_info * #define WPRINTK(fmt, args...) \ printf("[XEN] " fmt, ##args) #define DPRINTK(fmt, args...) \ - printf("[XEN] " fmt, ##args) + printf("[XEN] %s: " fmt, __func__, ##args) static __inline struct mbuf* @@ -341,15 +343,15 @@ makembuf (struct mbuf *buf) if (! m) return 0; - M_MOVE_PKTHDR(m, buf); + M_MOVE_PKTHDR(m, buf); - m_cljget(m, M_DONTWAIT, MJUMPAGESIZE); + m_cljget(m, M_DONTWAIT, MJUMPAGESIZE); m->m_pkthdr.len = buf->m_pkthdr.len; m->m_len = buf->m_len; - m_copydata(buf, 0, buf->m_pkthdr.len, mtod(m,caddr_t) ); + m_copydata(buf, 0, buf->m_pkthdr.len, mtod(m,caddr_t) ); m->m_ext.ext_args = (caddr_t *)(uintptr_t)(vtophys(mtod(m,caddr_t)) >> PAGE_SHIFT); - + return m; } @@ -360,12 +362,12 @@ makembuf (struct mbuf *buf) * Return 0 on success, or errno on error. */ static int -xen_net_read_mac(struct xenbus_device *dev, uint8_t mac[]) +xen_net_read_mac(device_t dev, uint8_t mac[]) { char *s; int i; char *e; - char *macstr = xenbus_read(XBT_NIL, dev->nodename, "mac", NULL); + char *macstr = xenbus_read(XBT_NIL, xenbus_get_node(dev), "mac", NULL); if (IS_ERR(macstr)) { return PTR_ERR(macstr); } @@ -389,23 +391,28 @@ xen_net_read_mac(struct xenbus_device *d * Connected state. */ static int -netfront_probe(struct xenbus_device *dev, const struct xenbus_device_id *id) +netfront_probe(device_t dev) { + + if (!strcmp(xenbus_get_type(dev), "vif")) { + device_set_desc(dev, "Virtual Network Interface"); + return (0); + } + + return (ENXIO); +} + +static int +netfront_attach(device_t dev) +{ int err; - struct ifnet *ifp; - struct netfront_info *info; - printf("netfront_probe() \n"); - - err = create_netdev(dev, &ifp); + err = create_netdev(dev); if (err) { xenbus_dev_fatal(dev, err, "creating netdev"); return err; } - info = ifp->if_softc; - dev->dev_driver_data = info; - return 0; } @@ -417,11 +424,11 @@ netfront_probe(struct xenbus_device *dev * rest of the kernel. */ static int -netfront_resume(struct xenbus_device *dev) +netfront_resume(device_t dev) { - struct netfront_info *info = dev->dev_driver_data; + struct netfront_info *info = device_get_softc(dev); - DPRINTK("%s\n", dev->nodename); + DPRINTK("%s\n", xenbus_get_node(dev)); netif_disconnect_backend(info); return (0); @@ -430,15 +437,16 @@ netfront_resume(struct xenbus_device *de /* Common code used when first setting up, and when resuming. */ static int -talk_to_backend(struct xenbus_device *dev, struct netfront_info *info) +talk_to_backend(device_t dev, struct netfront_info *info) { const char *message; struct xenbus_transaction xbt; + const char *node = xenbus_get_node(dev); int err; err = xen_net_read_mac(dev, info->mac); if (err) { - xenbus_dev_fatal(dev, err, "parsing %s/mac", dev->nodename); + xenbus_dev_fatal(dev, err, "parsing %s/mac", node); goto out; } @@ -453,47 +461,47 @@ talk_to_backend(struct xenbus_device *de xenbus_dev_fatal(dev, err, "starting transaction"); goto destroy_ring; } - err = xenbus_printf(xbt, dev->nodename, "tx-ring-ref","%u", + err = xenbus_printf(xbt, node, "tx-ring-ref","%u", info->tx_ring_ref); if (err) { message = "writing tx ring-ref"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, "rx-ring-ref","%u", + err = xenbus_printf(xbt, node, "rx-ring-ref","%u", info->rx_ring_ref); if (err) { message = "writing rx ring-ref"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, + err = xenbus_printf(xbt, node, "event-channel", "%u", irq_to_evtchn_port(info->irq)); if (err) { message = "writing event-channel"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, "request-rx-copy", "%u", + err = xenbus_printf(xbt, node, "request-rx-copy", "%u", info->copying_receiver); if (err) { message = "writing request-rx-copy"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, "feature-rx-notify", "%d", 1); + err = xenbus_printf(xbt, node, "feature-rx-notify", "%d", 1); if (err) { message = "writing feature-rx-notify"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, "feature-no-csum-offload", "%d", 1); + err = xenbus_printf(xbt, node, "feature-no-csum-offload", "%d", 1); if (err) { message = "writing feature-no-csum-offload"; goto abort_transaction; } - err = xenbus_printf(xbt, dev->nodename, "feature-sg", "%d", 1); + err = xenbus_printf(xbt, node, "feature-sg", "%d", 1); if (err) { message = "writing feature-sg"; goto abort_transaction; } #ifdef HAVE_TSO - err = xenbus_printf(xbt, dev->nodename, "feature-gso-tcpv4", "%d", 1); + err = xenbus_printf(xbt, node, "feature-gso-tcpv4", "%d", 1); if (err) { message = "writing feature-gso-tcpv4"; goto abort_transaction; @@ -521,7 +529,7 @@ talk_to_backend(struct xenbus_device *de static int -setup_device(struct xenbus_device *dev, struct netfront_info *info) +setup_device(device_t dev, struct netfront_info *info) { netif_tx_sring_t *txs; netif_rx_sring_t *rxs; @@ -564,9 +572,9 @@ setup_device(struct xenbus_device *dev, info->rx_ring_ref = err; #if 0 - network_connect(ifp); + network_connect(info); #endif - err = bind_listening_port_to_irqhandler(dev->otherend_id, + err = bind_listening_port_to_irqhandler(xenbus_get_otherend_id(dev), "xn", xn_intr, info, INTR_TYPE_NET | INTR_MPSAFE, NULL); if (err <= 0) { @@ -589,14 +597,13 @@ setup_device(struct xenbus_device *dev, * Callback received when the backend's state changes. */ static void -backend_changed(struct xenbus_device *dev, - XenbusState backend_state) +netfront_backend_changed(device_t dev, XenbusState newstate) { - struct netfront_info *sc = dev->dev_driver_data; + struct netfront_info *sc = device_get_softc(dev); - DPRINTK("\n"); - - switch (backend_state) { + DPRINTK("newstate=%d\n", newstate); + + switch (newstate) { case XenbusStateInitialising: case XenbusStateInitialised: case XenbusStateConnected: @@ -604,19 +611,19 @@ backend_changed(struct xenbus_device *de case XenbusStateClosed: case XenbusStateReconfigured: case XenbusStateReconfiguring: - break; + break; case XenbusStateInitWait: - if (dev->state != XenbusStateInitialising) + if (xenbus_get_state(dev) != XenbusStateInitialising) break; - if (network_connect(sc->xn_ifp) != 0) + if (network_connect(sc) != 0) break; - xenbus_switch_state(dev, XenbusStateConnected); + xenbus_set_state(dev, XenbusStateConnected); #ifdef notyet (void)send_fake_arp(netdev); #endif - break; break; + break; case XenbusStateClosing: - xenbus_frontend_closed(dev); + xenbus_set_state(dev, XenbusStateClosed); break; } } @@ -675,7 +682,8 @@ netif_release_tx_bufs(struct netfront_in if (((u_long)m) < KERNBASE) continue; gnttab_grant_foreign_access_ref(np->grant_tx_ref[i], - np->xbdev->otherend_id, virt_to_mfn(mtod(m, vm_offset_t)), + xenbus_get_otherend_id(np->xbdev), + virt_to_mfn(mtod(m, vm_offset_t)), GNTMAP_readonly); gnttab_release_grant_reference(&np->gref_tx_head, np->grant_tx_ref[i]); @@ -688,6 +696,7 @@ netif_release_tx_bufs(struct netfront_in static void network_alloc_rx_buffers(struct netfront_info *sc) { + int otherend_id = xenbus_get_otherend_id(sc->xbdev); unsigned short id; struct mbuf *m_new; int i, batch_target, notify; @@ -769,7 +778,7 @@ refill: if (sc->copying_receiver == 0) { gnttab_grant_foreign_transfer_ref(ref, - sc->xbdev->otherend_id, pfn); + otherend_id, pfn); sc->rx_pfn_array[nr_flips] = PFNTOMFN(pfn); if (!xen_feature(XENFEAT_auto_translated_physmap)) { /* Remove this page before passing @@ -782,7 +791,7 @@ refill: nr_flips++; } else { gnttab_grant_foreign_access_ref(ref, - sc->xbdev->otherend_id, + otherend_id, PFNTOMFN(pfn), 0); } req->id = id; @@ -1297,6 +1306,7 @@ xn_tick(void *xsc) static void xn_start_locked(struct ifnet *ifp) { + int otherend_id; unsigned short id; struct mbuf *m_head, *new_m; struct netfront_info *sc; @@ -1307,6 +1317,7 @@ xn_start_locked(struct ifnet *ifp) int notify; sc = ifp->if_softc; + otherend_id = xenbus_get_otherend_id(sc->xbdev); tx_bytes = 0; if (!netfront_carrier_ok(sc)) @@ -1336,7 +1347,7 @@ xn_start_locked(struct ifnet *ifp) ref = gnttab_claim_grant_reference(&sc->gref_tx_head); KASSERT((short)ref >= 0, ("Negative ref")); mfn = virt_to_mfn(mtod(new_m, vm_offset_t)); - gnttab_grant_foreign_access_ref(ref, sc->xbdev->otherend_id, + gnttab_grant_foreign_access_ref(ref, otherend_id, mfn, GNTMAP_readonly); tx->gref = sc->grant_tx_ref[id] = ref; tx->size = new_m->m_pkthdr.len; @@ -1540,23 +1551,19 @@ xn_stop(struct netfront_info *sc) } /* START of Xenolinux helper functions adapted to FreeBSD */ -static int -network_connect(struct ifnet *ifp) +int +network_connect(struct netfront_info *np) { - struct netfront_info *np; int i, requeue_idx, err; grant_ref_t ref; netif_rx_request_t *req; u_int feature_rx_copy, feature_rx_flip; - printf("network_connect\n"); - - np = ifp->if_softc; - err = xenbus_scanf(XBT_NIL, np->xbdev->otherend, + err = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), "feature-rx-copy", "%u", &feature_rx_copy); if (err != 1) feature_rx_copy = 0; - err = xenbus_scanf(XBT_NIL, np->xbdev->otherend, + err = xenbus_scanf(XBT_NIL, xenbus_get_otherend_path(np->xbdev), "feature-rx-flip", "%u", &feature_rx_flip); if (err != 1) feature_rx_flip = 1; @@ -1573,7 +1580,7 @@ network_connect(struct ifnet *ifp) /* Recovery procedure: */ err = talk_to_backend(np->xbdev, np); if (err) - return (err); + return (err); /* Step 1: Reinitialise variables. */ netif_release_tx_bufs(np); @@ -1591,11 +1598,11 @@ network_connect(struct ifnet *ifp) if (!np->copying_receiver) { gnttab_grant_foreign_transfer_ref(ref, - np->xbdev->otherend_id, + xenbus_get_otherend_id(np->xbdev), vtophys(mtod(m, vm_offset_t))); } else { gnttab_grant_foreign_access_ref(ref, - np->xbdev->otherend_id, + xenbus_get_otherend_id(np->xbdev), vtophys(mtod(m, vm_offset_t)), 0); } req->gref = ref; @@ -1622,7 +1629,6 @@ network_connect(struct ifnet *ifp) return (0); } - static void show_device(struct netfront_info *sc) { @@ -1642,25 +1648,18 @@ show_device(struct netfront_info *sc) #endif } -static int ifno = 0; - /** Create a network device. * @param handle device handle */ -static int -create_netdev(struct xenbus_device *dev, struct ifnet **ifpp) +int +create_netdev(device_t dev) { int i; struct netfront_info *np; int err; struct ifnet *ifp; - np = (struct netfront_info *)malloc(sizeof(struct netfront_info), - M_DEVBUF, M_NOWAIT); *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***